Skip to content

Commit

Permalink
Fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
Negashev committed Mar 25, 2024
1 parent f36129f commit f3882f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rancher-vcloud-director-node-driver-ui-plugin",
"version": "0.2.7",
"version": "0.2.8",
"private": false,
"engines": {
"node": ">=12"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vcd-node-driver/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vcd-node-driver",
"description": "vCloud Director node-driver plugin for rancher",
"version": "0.2.7",
"version": "0.2.8",
"private": false,
"rancher": {
"annotations": {
Expand Down
37 changes: 20 additions & 17 deletions pkg/vcd-node-driver/vcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,23 @@ export class Vcd {

public protocolHostname(href: string) {
const u = parseUrl(href);

return u?.host || '';
}

public getDeepKey(from: any, selectors: string) {
return selectors.replace(/\[([^\[\]]*)\]/g, '.$1.')
.split('.')
.filter(t => t !== '')
.reduce((prev, cur) => prev && prev[cur], from)
.reduce((prev, cur) => prev && prev[cur], from);
}

public async getToken() {
const url = `/meta/proxy/${ this.protocolHostname(this.href) }/cloudapi/1.0.0/sessions`;

const headers = {
Accept: 'application/*;version=' + this.version,
'X-API-Auth-Header': 'Basic ' + btoa(this.username + '@' + this.org + ':' + this.password)
const headers = {
Accept: `application/*;version=${ this.version }`,
'X-API-Auth-Header': `Basic ${ btoa(`${ this.username }@${ this.org }:${ this.password }`) }`
};

try {
Expand Down Expand Up @@ -105,7 +106,7 @@ export class Vcd {

public async getVAppVms(value: any, api: string, initial?: string) {
return await this.getOptions(value, parseUrl(api).path.replace(/^\/api/, ''), 'children.vm', (vm: any) => {
const vmx = vm.section.find((section: any)=> section._type === 'VmSpecSectionType');
const vmx = vm.section.find((section: any) => section._type === 'VmSpecSectionType');

return {
...vm,
Expand Down Expand Up @@ -163,14 +164,14 @@ export class Vcd {
let loopPages = true;

let res = await this.makeComputeRequest(api, domain);
let totalResults = res;
const totalResults = res;
let page = 1;

if (res?.pageCount) {
while (loopPages) {
if (res?.pageCount > res?.page) {
page = res.page + 1;
res = await this.makeComputeRequest(api + '&page=' + page, domain);
res = await this.makeComputeRequest(`${ api }&page=${ page }`, domain);
totalResults[field] = totalResults[field].concat(res[field]);
} else {
loopPages = false;
Expand All @@ -188,11 +189,11 @@ export class Vcd {
const url = `${ baseUrl }${ api }`;

const headers = domain ? {
Accept: 'application/json;multisite=global;version=' + this.version,
'X-API-Auth-Header': 'Bearer ' + this.token
Accept: `application/json;multisite=global;version=${ this.version }`,
'X-API-Auth-Header': `Bearer ${ this.token }`
} : {
Accept: 'application/*+json;version=' + this.version,
'X-API-Auth-Header': 'Bearer ' + this.token
Accept: `application/*+json;version=${ this.version }`,
'X-API-Auth-Header': `Bearer ${ this.token }`
};

try {
Expand All @@ -214,8 +215,8 @@ export class Vcd {
const baseUrl = `/meta/proxy/${ href }`;

const headers = {
Accept: 'application/*+json;version=' + this.version,
'X-API-Auth-Header': 'Bearer ' + this.token
Accept: `application/*+json;version=${ this.version }`,
'X-API-Auth-Header': `Bearer ${ this.token }`
};

try {
Expand All @@ -225,7 +226,7 @@ export class Vcd {
method: 'GET',
redirectUnauthorized: false,
}, { root: true });

return res?.orgVdcReference;
} catch (e) {
console.error(e); // eslint-disable-line no-console
Expand All @@ -235,13 +236,15 @@ export class Vcd {
}

private convertToOptions(list: any) {
const sorted = (list || []).sort((a: any, b: any) => a.name.localeCompare(b.name));
let sorted = (list || []).sort((a: any, b: any) => a.name.localeCompare(b.name));

sorted = sorted.filter((item: undefined) => item !== undefined);

return sorted.filter(item => item !== undefined).map((p: any) => {
return sorted.map((p: any) => {
return {
label: p.name,
value: p
};
});
}
}
}

0 comments on commit f3882f4

Please sign in to comment.