Skip to content

Commit

Permalink
fix eslint issues in CLI project (#7492)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Feb 8, 2022
1 parent 3205a3d commit f9be037
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 235 deletions.
8 changes: 4 additions & 4 deletions lib/cli/.eslintrc.json
Expand Up @@ -19,14 +19,14 @@
"eslint-plugin-rxjs"
],
"rules": {
"prefer-arrow/prefer-arrow-functions": "warn",
"@typescript-eslint/no-var-requires": "warn",
"prefer-arrow/prefer-arrow-functions": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/naming-convention": "warn",
"quote-props": "warn",
"no-shadow": "warn",
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"no-underscore-dangle": "warn",
"@typescript-eslint/prefer-for-of": "off",
"no-underscore-dangle": ["error", { "allowAfterThis": true }],

"@angular-eslint/component-selector": [
"error",
Expand Down
2 changes: 2 additions & 0 deletions lib/cli/scripts/changelog.ts
Expand Up @@ -17,6 +17,8 @@
* limitations under the License.
*/

/* eslint-disable @typescript-eslint/naming-convention */

import * as shell from 'shelljs';
import * as path from 'path';
import * as program from 'commander';
Expand Down
20 changes: 10 additions & 10 deletions lib/cli/scripts/check-cs-env.ts
Expand Up @@ -70,19 +70,19 @@ async function checkDiskSpaceFullEnv() {

try {
folder = await alfrescoJsApi.nodes.addNode('-my-', {
'name': `try-env`,
'relativePath': `Builds`,
'nodeType': 'cm:folder'
name: `try-env`,
relativePath: `Builds`,
nodeType: 'cm:folder'
}, {}, {
'overwrite': true
overwrite: true
});

} catch (error) {
folder = await alfrescoJsApi.nodes.getNode('-my-', {
'relativePath': `Builds/try-env`,
'nodeType': 'cm:folder'
relativePath: `Builds/try-env`,
nodeType: 'cm:folder'
}, {}, {
'overwrite': true
overwrite: true
});
}
const pathFile = path.join(__dirname, '../', 'README.md');
Expand All @@ -95,9 +95,9 @@ async function checkDiskSpaceFullEnv() {
folder.entry.id,
null,
{
'name': 'README.md',
'nodeType': 'cm:content',
'autoRename': true
name: 'README.md',
nodeType: 'cm:content',
autoRename: true
}
);

Expand Down
17 changes: 9 additions & 8 deletions lib/cli/scripts/docker.ts
Expand Up @@ -22,9 +22,10 @@ import * as program from 'commander';
import { logger } from './logger';
import { resolve } from 'path';

// eslint-disable-next-line no-shadow
enum TARGETS {
Publish = 'publish',
Link = 'link'
publish = 'publish',
link = 'link'
}

const DOCKER_FILENAME = 'Dockerfile';
Expand Down Expand Up @@ -105,7 +106,7 @@ function main(args) {
.option('--sourceTag [type]', 'sourceTag')
.option('--buildArgs [type...]', 'buildArgs')
.option('--fileName [type...]', 'Docker file name', DOCKER_FILENAME)
.option('--target [type]', 'target: publish or link', TARGETS.Publish)
.option('--target [type]', 'target: publish or link', TARGETS.publish)
.requiredOption('--dockerRepo [type]', 'docker repo')
.requiredOption('--dockerTags [type]', ' tags')
.parse(process.argv);
Expand All @@ -120,13 +121,13 @@ function main(args) {
process.exit(1);
}

if (program.opts().target === TARGETS.Publish && args.buildArgs === undefined) {
logger.error(`error: required option --buildArgs [type] in case the target is ${TARGETS.Publish}`);
if (program.opts().target === TARGETS.publish && args.buildArgs === undefined) {
logger.error(`error: required option --buildArgs [type] in case the target is ${TARGETS.publish}`);
process.exit(1);
}

if (program.opts().target === TARGETS.Link && args.sourceTag === undefined) {
logger.error(`error: required option --sourceTag [type] in case the target is ${TARGETS.Link}`);
if (program.opts().target === TARGETS.link && args.sourceTag === undefined) {
logger.error(`error: required option --sourceTag [type] in case the target is ${TARGETS.link}`);
process.exit(1);
}

Expand All @@ -147,7 +148,7 @@ function main(args) {
args.dockerTags.split(',').forEach((tag, index) => {
if (tag) {
logger.info(`Analyzing tag:${tag} ... for target ${program.opts().target}`);
if (program.opts().target === TARGETS.Publish) {
if (program.opts().target === TARGETS.publish) {
if (index === 0) {
logger.info(`Build only once`);
mainTag = tag;
Expand Down
13 changes: 5 additions & 8 deletions lib/cli/scripts/init-aae-env.ts
Expand Up @@ -18,14 +18,11 @@
*/

import * as program from 'commander';

/* eslint-disable */
import request = require('request');
import * as fs from 'fs';
import { logger } from './logger';
import { AlfrescoApi } from '@alfresco/js-api';
const ACTIVITI_CLOUD_APPS = require('./resources').ACTIVITI_CLOUD_APPS;
/* eslint-enable */

let alfrescoJsApiModeler: any;
let alfrescoJsApiDevops: any;
Expand Down Expand Up @@ -369,11 +366,11 @@ async function checkIfAppIsReleased(missingApps: any [], tag?: string) {
await checkDescriptorExist(currentAbsentApp.name);
await sleep(TIME);
const deployPayload = {
'name': currentAbsentApp.name,
'releaseId': projectRelease.entry.id,
'security': currentAbsentApp.security,
'infrastructure': currentAbsentApp.infrastructure,
'variables': currentAbsentApp.variables
name: currentAbsentApp.name,
releaseId: projectRelease.entry.id,
security: currentAbsentApp.security,
infrastructure: currentAbsentApp.infrastructure,
variables: currentAbsentApp.variables
};
await deploy(deployPayload);
}
Expand Down
13 changes: 6 additions & 7 deletions lib/cli/scripts/init-acs-env.ts
@@ -1,15 +1,14 @@
/* eslint-disable */
let alfrescoApi = require('@alfresco/js-api');
let program = require('commander');
let fs = require ('fs');
const alfrescoApi = require('@alfresco/js-api');
const program = require('commander');
const fs = require ('fs');
const path = require('path');
import { logger } from './logger';
// eslint-disable-next-line @typescript-eslint/naming-convention
const { SharedlinksApi, FavoritesApi, NodesApi } = require('@alfresco/js-api');
let MAX_RETRY = 10;
const MAX_RETRY = 10;
let counter = 0;
let TIMEOUT = 6000;
const TIMEOUT = 6000;
const ACS_DEFAULT = require('./resources').ACS_DEFAULT;
/* eslint-enable */

let alfrescoJsApi;

Expand Down
33 changes: 16 additions & 17 deletions lib/cli/scripts/init-aps-env.ts
@@ -1,19 +1,18 @@
/* eslint-disable */
let alfrescoApi = require('@alfresco/js-api');
let program = require('commander');
let fs = require ('fs');
const alfrescoApi = require('@alfresco/js-api');
const program = require('commander');
const fs = require ('fs');
const path = require('path');
import { logger } from './logger';
const { throwError } = require('rxjs');
// eslint-disable-next-line @typescript-eslint/naming-convention
const { AppDefinitionsApi, RuntimeAppDefinitionsApi } = require('@alfresco/js-api');
let MAX_RETRY = 10;
const MAX_RETRY = 10;
let counter = 0;
let TIMEOUT = 6000;
const TIMEOUT = 6000;
const TENANT_DEFAULT_ID = 1;
const TENANT_DEFAULT_NAME = 'default';
const CONTENT_DEFAULT_NAME = 'adw-content';
const ACTIVITI_APPS = require('./resources').ACTIVITI_APPS;
/* eslint-enable */

let alfrescoJsApi;
let alfrescoJsApiRepo;
Expand Down Expand Up @@ -162,9 +161,9 @@ async function hasDefaultTenant(tenantId, tenantName) {

async function createDefaultTenant(tenantName) {
const tenantPost = {
'active': true,
'maxUsers': 10000,
'name' : tenantName
active: true,
maxUsers: 10000,
name : tenantName
};

try {
Expand All @@ -180,13 +179,13 @@ async function createUsers(tenandId, user) {
logger.info(`Create user ${user.email} on tenant: ${tenandId}`);
const passwordCamelCase = 'Password';
const userJson = {
'email': user.email,
'firstName': user.firstName,
'lastName': user.lastName,
'status': 'active',
'type': 'enterprise',
'password': passwordCamelCase,
'tenantId': tenandId
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
status: 'active',
type: 'enterprise',
password: passwordCamelCase,
tenantId: tenandId
};

try {
Expand Down
65 changes: 65 additions & 0 deletions lib/cli/scripts/kube-utils.ts
@@ -0,0 +1,65 @@
import { logger } from './logger';
import { exec } from './exec';

export interface KubeArgs {
tag?: string;
installCheck?: boolean;
username?: string;
token?: string;
clusterEnv?: string;
clusterUrl?: string;
dockerRepo?: string;
label?: string;
namespaces?: string;
}

export const setCluster = (clusterEnv: string, clusterUrl: string) => {
logger.info('Perform set-cluster...');
const response = exec('kubectl', [`config`, `set-cluster`, `${clusterEnv}`, `--server=${clusterUrl}`], {});
logger.info(response);
};

export const setCredentials = (username: string, token: string) => {
logger.info('Perform set-credentials...');
const response = exec('kubectl', [`config`, `set-credentials`, `${username}`, `--token=${token}`], {});
logger.info(response);
};

export const setContext = (clusterEnv: string, username: string) => {
logger.info('Perform set-context...');
const response = exec('kubectl', [`config`, `set-context`, `${clusterEnv}`, `--cluster=${clusterEnv}`, `--user=${username}`], {});
logger.info(response);
};

export const useContext = (clusterEnv: string) => {
logger.info('Perform use-context...');
const response = exec('kubectl', [`config`, `use-context`, `${clusterEnv}`], {});
logger.info(response);
};

export const deletePod = (args: KubeArgs) => {
logger.info('Perform delete pods...');
const response = exec('kubectl', [`delete`, `pods`, `--all-namespaces`, `-l`, `app=${args.label}`], {});
logger.info(response);
};

export const getNamespaces = (): string[] => {
logger.info('Perform get namespaces name...');
const result = exec('kubectl', [`get`, `namespaces`, `-l`, `type=application`, `-o`, `name`], {});
const namespaces = result.replace(/namespace[\/]+/g, '').split(/\r?\n/);
logger.info(`namespaces found: ${namespaces}`);
return namespaces;
};

export const getDeploymentName = (args: KubeArgs, namespace: string): string => {
logger.info('Perform get deployment name...');
const result = exec('kubectl', [`get`, `deployments`, `--namespace=${namespace}`, `-l`, `app=${args.label}`, `-o`, `name`], {});
logger.info(`deployment name: ${result}`);
return result;
};

export const setImage = (args: KubeArgs, deploymentName: string, serviceName: string, namespace: string) => {
logger.info('Perform set image...');
const response = exec('kubectl', [`set`, `image`, `--namespace=${namespace}`, `${deploymentName}`, `${serviceName}=${args.dockerRepo}:${args.tag}`], {});
logger.info(response);
};
51 changes: 12 additions & 39 deletions lib/cli/scripts/kubectl-clean-app.ts
Expand Up @@ -19,13 +19,9 @@

import * as program from 'commander';
import moment from 'moment-es6';
import { exec } from './exec';
/* eslint-disable */
import { AlfrescoApi } from '@alfresco/js-api';
/* eslint-enable */

import { logger } from './logger';

import * as kube from './kube-utils';
export interface ConfigArgs {
rancherUsername?: string;
rancherToken?: string;
Expand All @@ -42,7 +38,6 @@ export interface ConfigArgs {
identityHost: boolean;
enableLike: boolean;
intervalTime: string;

}

function getAlfrescoJsApiInstance(args: ConfigArgs) {
Expand Down Expand Up @@ -185,36 +180,12 @@ async function undeployApplication(args: ConfigArgs, apiService: any, name: stri
}
}

function setCluster(args: ConfigArgs) {
logger.info('Perform set-cluster...');
const response = exec('kubectl', [`config`, `set-cluster`, `${args.clusterEnv}`, `--server=${args.clusterUrl}`], {});
logger.info(response);
}

function setCredentials(args: ConfigArgs) {
logger.info('Perform set-credentials...');
const response = exec('kubectl', [`config`, `set-credentials`, `${args.rancherUsername}`, `--token=${args.rancherToken}`], {});
logger.info(response);
}

function setContext(args: ConfigArgs) {
logger.info('Perform set-context...');
const response = exec('kubectl', [`config`, `set-context`, `${args.clusterEnv}`, `--cluster=${args.clusterEnv}`, `--user=${args.rancherUsername}`], {});
logger.info(response);
}

function useContext(args: ConfigArgs) {
logger.info('Perform use-context...');
const response = exec('kubectl', [`config`, `use-context`, `${args.clusterEnv}`], {});
logger.info(response);
}

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export default async function(args: ConfigArgs) {
await main(args);
}

async function main(args) {

const main = async (args: ConfigArgs) => {
program
.version('0.1.0')
.description('The following command is in charge of cleaning the releases/application/descriptor related to an app passed as input' +
Expand Down Expand Up @@ -254,24 +225,27 @@ async function main(args) {
});

if (args.apps !== undefined) {
setCluster(args);
setCredentials(args);
setContext(args);
useContext(args);
kube.setCluster(args.clusterEnv, args.clusterUrl);
kube.setCredentials(args.rancherUsername, args.rancherToken);
kube.setContext(args.clusterEnv, args.rancherUsername);
kube.useContext(args.clusterEnv);

const applications = args.apps.includes(',') ? args.apps.split(',') : [args.apps];
const interval = args.intervalTime ? args.intervalTime : '30 min';
const extractTimeRange = interval.split(' ')[0];
const extractTimeRange = parseInt(interval.split(' ')[0], 10);
logger.info(`Extract time ${extractTimeRange} from interval: ${interval}`);

for (let i = 0; i < applications.length; i++ ) {
logger.info(`Perform action on app: ${applications[i]}`);
if (args.enableLike) {
const applicationsByName = await getApplicationsByName(args, alfrescoJsApiDevops, applications[i]);
logger.info(`Found ${applicationsByName.length} apps`);

for (let y = 0; y < applicationsByName.length; y++ ) {
const application = applicationsByName[y].entry;
logger.info(`Analyze app: ${application.name} `);
const diffAsMinutes = moment.duration(moment().diff(moment(application.createdAt))).asMinutes();

if (diffAsMinutes > extractTimeRange) {
logger.info(`The app: ${application} is older than ${interval}. Can delete it`);
await undeployApplication(args, alfrescoJsApiDevops, application.name);
Expand All @@ -288,5 +262,4 @@ async function main(args) {
}
}
}

}
};

0 comments on commit f9be037

Please sign in to comment.