From fec1b813e674408860683b771ff0d01739c061f4 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Fri, 12 Jun 2020 13:57:44 +0100 Subject: [PATCH] fix cli --- lib/cli/scripts/init-aae-env.ts | 85 +++++++----- lib/cli/scripts/kubectl-clean-app.ts | 22 ++- lib/cli/scripts/resources.ts | 200 +++++++++++++++++++++++++++ 3 files changed, 267 insertions(+), 40 deletions(-) create mode 100644 lib/cli/scripts/resources.ts diff --git a/lib/cli/scripts/init-aae-env.ts b/lib/cli/scripts/init-aae-env.ts index ac0320f829..d71323ccf0 100644 --- a/lib/cli/scripts/init-aae-env.ts +++ b/lib/cli/scripts/init-aae-env.ts @@ -20,13 +20,15 @@ import * as program from 'commander'; /* tslint:disable */ -const alfrescoApi = require('@alfresco/js-api'); -/* tslint:enable */ 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; +/* tslint:enable */ -let alfrescoJsApi: any; +let alfrescoJsApiModeler: any; +let alfrescoJsApiDevops: any; let args: ConfigArgs; let isValid = true; @@ -54,7 +56,7 @@ async function healthCheck(nameService: string) { headerParams = {}, formParams = {}, bodyParam = {}, contentTypes = ['application/json'], accepts = ['application/json']; try { - const health = await alfrescoJsApi.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, + const health = await alfrescoJsApiModeler.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); if (health.status !== 'UP') { logger.error(`${nameService} is DOWN `); @@ -75,11 +77,11 @@ function getApplicationByStatus(status: string) { headerParams = {}, formParams = {}, bodyParam = {}, contentTypes = ['application/json'], accepts = ['application/json']; try { - return alfrescoJsApi.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, + return alfrescoJsApiDevops.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); } catch (error) { - logger.error(error.status); + logger.error(`Get application by status ${error.status} `); isValid = false; } } @@ -91,59 +93,59 @@ function getDescriptors() { headerParams = {}, formParams = {}, bodyParam = {}, contentTypes = ['application/json'], accepts = ['application/json']; try { - return alfrescoJsApi.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, + return alfrescoJsApiDevops.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); } catch (error) { - logger.error(error.status); + logger.error(`Get Descriptors ${error.status} `); isValid = false; } } function getProjects() { - const url = `${args.host}/deployment-service/v1/projects/'`; + const url = `${args.host}/modeling-service/v1/projects`; const pathParams = {}, queryParams = { maxItems: 1000 }, headerParams = {}, formParams = {}, bodyParam = {}, contentTypes = ['application/json'], accepts = ['application/json']; try { - return alfrescoJsApi.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, + return alfrescoJsApiModeler.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); } catch (error) { - logger.error(error.status); + logger.error('Get Projects' + error.status); isValid = false; } } function getProjectRelease(projectId: string) { - const url = `${args.host}/deployment-service/v1/projects/${projectId}/releases`; + const url = `${args.host}/modeling-service/v1/projects/${projectId}/releases`; const pathParams = {}, queryParams = {}, headerParams = {}, formParams = {}, bodyParam = {}, contentTypes = ['application/json'], accepts = ['application/json']; try { - return alfrescoJsApi.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, + return alfrescoJsApiModeler.oauth2Auth.callCustomApi(url, 'GET', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); } catch (error) { - logger.error(error.status); + logger.error('Get Projects Release' + error.status); isValid = false; } } function releaseProject(projectId: string) { - const url = `${args.host}/deployment-service/v1/projects/${projectId}/releases`; + const url = `${args.host}/modeling-service/v1/projects/${projectId}/releases`; const pathParams = {}, queryParams = {}, headerParams = {}, formParams = {}, bodyParam = {}, contentTypes = ['application/json'], accepts = ['application/json']; try { - return alfrescoJsApi.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam, + return alfrescoJsApiModeler.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); } catch (error) { - logger.error(error.status); + logger.error('Post Projects Release' + error.status); isValid = false; } } @@ -152,45 +154,45 @@ async function importAndReleaseProject(absoluteFilePath: string) { const fileContent = await fs.createReadStream(absoluteFilePath); try { - const project = await alfrescoJsApi.oauth2Auth.callCustomApi(`${args.host}/v1/projects/import`, 'POST', {}, {}, {}, { file: fileContent }, {}, ['multipart/form-data'], ['application/json']); + const project = await alfrescoJsApiModeler.oauth2Auth.callCustomApi(`${args.host}/modeling-service/v1/projects/import`, 'POST', {}, {}, {}, { file: fileContent }, {}, ['multipart/form-data'], ['application/json']); - await alfrescoJsApi.oauth2Auth.callCustomApi(`${args.host}/v1/projects/${project.entry.id}/releases`, 'POST', {}, {}, {}, {}, {}, + await alfrescoJsApiModeler.oauth2Auth.callCustomApi(`${args.host}/modeling-service/v1/projects/${project.entry.id}/releases`, 'POST', {}, {}, {}, {}, {}, ['application/json'], ['application/json']); } catch (error) { - logger.error(error.status); + logger.error('Import Projects' + error.status); isValid = false; } } function deleteDescriptor(name: string) { - const url = `${args.host}/v1/descriptors/${name}`; + const url = `${args.host}/deployment-service/v1/descriptors/${name}`; const pathParams = {}, queryParams = {}, headerParams = {}, formParams = {}, bodyParam = {}, contentTypes = ['application/json'], accepts = ['application/json']; try { - return alfrescoJsApi.oauth2Auth.callCustomApi(url, 'DELETE', pathParams, queryParams, headerParams, formParams, bodyParam, + return alfrescoJsApiDevops.oauth2Auth.callCustomApi(url, 'DELETE', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); } catch (error) { - logger.error(error.status); + logger.error('Delete descriptor' + error.status); isValid = false; } } function deploy(model: any) { - const url = `${args.host}/v1/applications/`; + const url = `${args.host}/deployment-service/v1/applications/`; const pathParams = {}, queryParams = {}, headerParams = {}, formParams = {}, bodyParam = model, contentTypes = ['application/json'], accepts = ['application/json']; try { - return alfrescoJsApi.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam, + return alfrescoJsApiDevops.oauth2Auth.callCustomApi(url, 'POST', pathParams, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts); } catch (error) { - logger.error(error.status); + logger.error('Deploy post' + error.status); isValid = false; } } @@ -210,7 +212,7 @@ function getAlfrescoJsApiInstance(configArgs: ConfigArgs) { redirectUri: '/' } }; - return new alfrescoApi.AlfrescoApiCompatibility(config); + return new AlfrescoApi(config); } async function deployMissingApps() { @@ -243,7 +245,7 @@ async function checkIfAppIsReleased(absentApps: any []) { logger.warn('Missing project: Create the project for ' + currentAbsentApp.name); try { - projectRelease = await importProjectAndRelease(currentAbsentApp); + projectRelease = await importProjectAndRelease(currentAbsentApp.name); } catch (error) { logger.info(`error status ${error.status}`); @@ -320,13 +322,13 @@ async function importProjectAndRelease(app: any) { function findMissingApps(deployedApps: any []) { const absentApps: any [] = []; - ['candidatebaseapp', 'simpleapp', 'subprocessapp'].forEach((app) => { + Object.keys(ACTIVITI_CLOUD_APPS).forEach((key) => { const isPresent = deployedApps.find((currentApp: any) => { - return app === currentApp.entry.name; + return ACTIVITI_CLOUD_APPS[key].name === currentApp.entry.name; }); if (!isPresent) { - absentApps.push(app); + absentApps.push(ACTIVITI_CLOUD_APPS[key]); } }); return absentApps; @@ -341,6 +343,7 @@ async function getFileFromRemote(url: string, name: string) { resolve(); }) .on('error', (error: any) => { + logger.error(`Not possible to download the project form remote`); reject(error); }); }); @@ -369,7 +372,7 @@ async function main(configArgs: ConfigArgs) { program .version('0.1.0') .description('The following command is in charge of Initializing the activiti cloud env with the default apps' + - 'adf-cli init-aae-env --host "gateway_env" --oauth "identity_env" --identityHost "identity_env" --modelerUsername "modelerusername" --modelerPassword "modelerpassword" --devopsUsername "devevopsusername" --devopsPassword "devopspassword"') + 'adf-cli init-aae-env --host "gateway_env" --oauth "identity_env" --modelerUsername "modelerusername" --modelerPassword "modelerpassword" --devopsUsername "devevopsusername" --devopsPassword "devopspassword"') .option('-h, --host [type]', 'Host gateway') .option('-o, --oauth [type]', 'Host sso server') .option('-jsonAppsPath, --oauth [type]', 'Host sso server') @@ -385,8 +388,14 @@ async function main(configArgs: ConfigArgs) { return; } - alfrescoJsApi = getAlfrescoJsApiInstance(args); - await alfrescoJsApi.login(args.modelerUsername, args.modelerPassword); + alfrescoJsApiModeler = getAlfrescoJsApiInstance(args); + alfrescoJsApiDevops = getAlfrescoJsApiInstance(args); + await alfrescoJsApiModeler.login(args.modelerUsername, args.modelerPassword).then(() => { + logger.info('login SSO ok'); + }, (error) => { + logger.info(`login SSO error ${JSON.stringify(error)} ${args.modelerUsername}`); + process.exit(1); + }); AAE_MICROSERVICES.map(async (serviceName) => { await healthCheck(serviceName); @@ -394,7 +403,13 @@ async function main(configArgs: ConfigArgs) { if (isValid) { logger.error('The environment is up and running'); - await alfrescoJsApi.login(args.devopsUsername, args.devopsPassword); + await alfrescoJsApiDevops.login(args.devopsUsername, args.devopsPassword).then(() => { + logger.info('login SSO ok devopsUsername'); + }, (error) => { + logger.info(`login SSO error ${JSON.stringify(error)} ${args.devopsUsername}`); + process.exit(1); + }); + await deployMissingApps(); } else { logger.info('The environment is not up'); diff --git a/lib/cli/scripts/kubectl-clean-app.ts b/lib/cli/scripts/kubectl-clean-app.ts index 5148afa072..94448b6e44 100644 --- a/lib/cli/scripts/kubectl-clean-app.ts +++ b/lib/cli/scripts/kubectl-clean-app.ts @@ -20,7 +20,7 @@ import * as program from 'commander'; import { exec } from './exec'; /* tslint:disable */ -const alfrescoApi = require('@alfresco/js-api'); +import { AlfrescoApi } from '@alfresco/js-api'; /* tslint:enable */ import { logger } from './logger'; @@ -60,7 +60,7 @@ function getAlfrescoJsApiInstance(args: ConfigArgs) { redirectUri: '/' } }; - return new alfrescoApi.AlfrescoApiCompatibility(config); + return new AlfrescoApi(config); } async function login(username: string, password: string, alfrescoJsApi: any) { @@ -264,12 +264,14 @@ async function main(args) { 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' + - 'adf-cli kubectl-clean-app --host "gateway_env" --oauth "identity_env" --identityHost "identity_env" --username "username" --password "password"') + 'adf-cli kubectl-clean-app --host "gateway_env" --modelerUsername "modelerusername" --modelerPassword "modelerpassword" --oauth "identity_env" --username "username" --password "password"') .option('-h, --host [type]', 'Host gateway') .option('-o, --oauth [type]', 'Host sso server') .option('--clientId[type]', 'sso client') .option('--devopsUsername [type]', 'username of user with ACTIVITI_DEVOPS role') .option('--devopsPassword [type]', 'password of user with ACTIVITI_DEVOPS role') + .option('--modelerUsername [type]', 'username of a user with role ACTIVIT_MODELER') + .option('--modelerPassword [type]', 'modeler password') .option('--rancherUsername [type]', 'rancher username') .option('--rancherPassword [type]', 'rancher password') .option('--enableLike [boolean]', 'Enable the like for app name') @@ -282,10 +284,20 @@ async function main(args) { } const configModeler = getAlfrescoJsApiInstance(args); - const alfrescoJsApiModeler = await login(args.modelerUsername, args.modelerPassword, configModeler); + const alfrescoJsApiModeler = await login(args.modelerUsername, args.modelerPassword, configModeler).then(() => { + logger.info('login SSO ok'); + }, (error) => { + logger.info(`login SSO error ${JSON.stringify(error)}`); + process.exit(1); + }); const configDevops = getAlfrescoJsApiInstance(args); - const alfrescoJsApiDevops = await login(args.devopsUsername, args.devopsPassword, configDevops); + const alfrescoJsApiDevops = await login(args.devopsUsername, args.devopsPassword, configDevops).then(() => { + logger.info('login SSO ok'); + }, (error) => { + logger.info(`login SSO error ${JSON.stringify(error)}`); + process.exit(1); + }); if (args.label !== undefined || args.apps !== undefined) { setCluster(args); diff --git a/lib/cli/scripts/resources.ts b/lib/cli/scripts/resources.ts new file mode 100644 index 0000000000..f4dc0fe731 --- /dev/null +++ b/lib/cli/scripts/resources.ts @@ -0,0 +1,200 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* cSpell:disable */ +export const ACTIVITI_CLOUD_APPS: any = { + CANDIDATE_BASE_APP: { + name: 'candidatebaseapp', + file_location: 'https://github.com/Alfresco/alfresco-ng2-components/blob/develop/e2e/resources/activiti7/candidatebaseapp.zip?raw=true', + processes: { + candidateUserProcess: 'candidateuserprocess', + candidateGroupProcess: 'candidategroupprocess', + anotherCandidateGroupProcess: 'anothercandidategroup', + uploadFileProcess: 'uploadfileprocess', + processwithstarteventform: 'processwithstarteventform', + processwithjsonfilemapping: 'processwithjsonfilemapping', + assigneeProcess: 'assigneeprocess', + errorStartEventProcess: { + process_name: 'errorstartevent', + error_id: 'Error_END_EVENT', + error_code: '123' + }, + errorBoundaryEventProcess: { + process_name: 'errorboundaryevent', + error_id: 'Error_END_EVENT', + error_code: '567' + }, + errorExclusiveGateProcess: { + process_name: 'errorexclusivegate', + error_id: 'Error_OK', + error_code: '200' + } + }, + forms: { + starteventform: 'starteventform', + formtotestvalidations: 'formtotestvalidations', + uploadfileform: 'uploadfileform', + inputform: 'inputform', + outputform: 'outputform' + }, + security: [ + { 'role': 'ACTIVITI_ADMIN', 'groups': [], 'users': ['superadminuser', 'processadminuser'] }, + { 'role': 'ACTIVITI_USER', 'groups': ['hr', 'testgroup'], 'users': ['hruser', 'salesuser'] } + ], + tasks: { + uploadFileTask: 'UploadFileTask', + candidateUserTask: 'candidateUserTask' + } + }, + SIMPLE_APP: { + name: 'simpleapp', + file_location: 'https://github.com/Alfresco/alfresco-ng2-components/blob/develop/e2e/resources/activiti7/simpleapp.zip?raw=true', + processes: { + processwithvariables: 'processwithvariables', + simpleProcess: 'simpleprocess', + dropdownrestprocess: 'dropdownrestprocess', + multilingualprocess: 'multilingualprocess', + processWithTabVisibility: 'processwithtabvisibility', + startmessageevent: 'start-message-event', + intermediatemessageevent: 'intermediate-message-event', + intboundaryevent: 'int-boundary-event', + nonintboundaryevent: 'nonint-boundary-event', + intboundarysubprocess: 'int-boundary-subprocess', + intstartmessageevent: 'int-start-message-event', + nonintstartmessageevent: 'nonint-start-message-event', + siblingtaskprocess: 'siblingtaskprocess', + startTaskVisibilityForm: 'start-task-visibility-form', + startVisibilityForm: 'start-visibility-form', + processstring: 'processstring', + processinteger: 'processinteger', + processboolean: 'processboolean', + processdate: 'processdate', + multiprocess: 'multiprocess', + terminateexclusive: 'terminate-exclusive', + terminatesubprocess: 'terminate-subprocess', + multiinstancedmnparallel: 'multiinstance-dmnparallel', + multiinstancecallactivity: 'multiinstance-callactivity', + multiinstancecollection: 'multiinstance-collection', + multiinstancecompletion: 'multiinstance-completion', + multiinstancesequential: 'multiinstance-sequential', + multiinstanceservicetask: 'multiinstance-servicetask', + multiinstanceusertask: 'multiinstance-usertask', + multiinstancedmnsequence: 'multiinstance-dmnsequence', + multiinstancemanualtask: 'multiinstance-manualtask', + multiinstancesubprocess: 'multiinstance-subprocess', + calledprocess: 'calledprocess', + booleanvisibilityprocess: 'booleanvisibilityprocess', + numbervisibilityprocess: 'numbervisibilityprocess', + processformoutcome: 'outcomebuttons', + uploadSingleMultipleFiles: 'upload-single-multiple-pro', + processDisplayRestJson: 'process-display-rest-json', + poolStartEndMessageThrow: 'pool-start-end-mess-throw', + poolStartEndMessageCatch: 'pool-start-end-mess-catch', + poolProcessCalled: 'pool-process-called', + poolProcessCalling: 'pool-process-calling', + poolNonIntBoundaryThrown: 'pool-nonint-boundary-throw', + poolNonIntBoundaryCatch: 'pool-nonint-boundary-catch', + poolIntermediateMessageThrow: 'pool-interm-message-throw', + poolIntermediateMessageCatch: 'pool-interm-message-catch', + poolInterruptingBoundarySubprocessThrow: 'pool-int-bound-subpr-throw', + poolInterruptingBoundarySubprocessCatch: 'pool-int-bound-subpr-catch', + poolInterruptingBoundaryThrow: 'pool-int-boundary-throw', + poolInterruptingBoundaryCatch: 'pool-int-boundary-catch' + }, + forms: { + tabVisibilityFields: { + name: 'tabvisibilitywithfields' + }, + tabVisibilityVars: { + name: 'tabvisibilitywithvars' + }, + usertaskform: { + name: 'usertaskform' + }, + dropdownform: { + name: 'dropdownform' + }, + formVisibility: { + name: 'form-visibility' + }, + multilingualform: { + name: 'multilingualform' + }, + inputform: { + name: 'inputform' + }, + outputform: { + name: 'outputform' + }, + exclusiveconditionform: { + name: 'exclusive-condition-form' + }, + uploadlocalfileform: { + name: 'upload-localfile-form' + }, + booleanvisibility: { + name: 'booleanvisibility' + }, + requirednumbervisibility: { + name: 'requirednumbervisibility' + }, + mealform: { + name: 'mealform' + }, + resultcollectionform: { + name: 'resultcollectionform' + }, + uploadSingleMultiple: { + name: 'upload-single-multiple', + widgets: { + contentMultipleAttachFileId: 'UploadMultipleFileFromContentId' + } + }, + formWithJsonWidget: { + name: 'form-with-json-widget' + }, + formWithAllWidgets: { + name: 'form-with-all-widgets' + }, + poolForm: { + name: 'pool-usertaskform' + } + + }, + tasks: { + processstring: 'inputtask', + uploadSingleMultipleFiles: 'UploadSingleMultipleFiles' + }, + security: [ + { 'role': 'ACTIVITI_ADMIN', 'groups': [], 'users': ['superadminuser', 'processadminuser'] }, + { 'role': 'ACTIVITI_USER', 'groups': ['hr', 'sales', 'testgroup'], 'users': ['hruser'] } + ], + infrastructure: {connectors: {restconnector: {}}, bridges: {}} + }, + SUB_PROCESS_APP: { + name: 'subprocessapp', + file_location: 'https://github.com/Alfresco/alfresco-ng2-components/blob/develop/e2e/resources/activiti7/subprocessapp.zip?raw=true', + processes: { + processchild: 'processchild', + processparent: 'processparent' + }, + security: [ + { 'role': 'ACTIVITI_ADMIN', 'groups': [], 'users': ['superadminuser'] }, + { 'role': 'ACTIVITI_USER', 'groups': ['hr', 'testgroup'], 'users': ['hruser'] } + ] + } +};