mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Upgrade ADF CLI to latest Commander library (#9473)
* build(deps-dev): bump commander from 6.2.1 to 12.0.0 Bumps [commander](https://github.com/tj/commander.js) from 6.2.1 to 12.0.0. - [Release notes](https://github.com/tj/commander.js/releases) - [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/tj/commander.js/compare/v6.2.1...v12.0.0) --- updated-dependencies: - dependency-name: commander dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore: migrate CLI to latest commander library * chore: migrate CLI to latest commander library [ci:force] --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
7cca017c12
commit
9d7608817d
@ -22,7 +22,14 @@ import * as ejs from 'ejs';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { argv, exit } from 'node:process';
|
||||
import program from 'commander';
|
||||
import { Command } from 'commander';
|
||||
|
||||
const program = new Command();
|
||||
|
||||
interface AuditCommandArgs {
|
||||
package?: string;
|
||||
outDir?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Audit report command
|
||||
@ -44,10 +51,12 @@ export default function main(_args: string[], workingDir: string) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const options = program.opts<AuditCommandArgs>();
|
||||
|
||||
let packagePath = path.resolve(workingDir, 'package.json');
|
||||
|
||||
if (program.package) {
|
||||
packagePath = path.resolve(program.package);
|
||||
if (options.package) {
|
||||
packagePath = path.resolve(options.package);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(packagePath)) {
|
||||
@ -82,7 +91,7 @@ export default function main(_args: string[], workingDir: string) {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
} else {
|
||||
const outputPath = path.resolve(program.outDir || workingDir);
|
||||
const outputPath = path.resolve(options.outDir || workingDir);
|
||||
const outputFile = path.join(outputPath, `audit-info-${packageJson.version}.md`);
|
||||
|
||||
fs.writeFileSync(outputFile, mdText);
|
||||
|
@ -22,11 +22,13 @@
|
||||
import { argv, exit } from 'node:process';
|
||||
import * as shell from 'shelljs';
|
||||
import * as path from 'path';
|
||||
import program from 'commander';
|
||||
import { Command } from 'commander';
|
||||
import { logger } from './logger';
|
||||
import * as fs from 'fs';
|
||||
import * as ejs from 'ejs';
|
||||
|
||||
const program = new Command();
|
||||
|
||||
interface Commit {
|
||||
hash: string;
|
||||
author: string;
|
||||
@ -167,8 +169,10 @@ export default function main(_args: string[], workingDir: string) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const dir = path.resolve(program.dir || workingDir);
|
||||
const { range, skip, max, format, output, exclude } = program;
|
||||
const options = program.opts();
|
||||
|
||||
const dir = path.resolve(options.dir || workingDir);
|
||||
const { range, skip, max, format, output, exclude } = options;
|
||||
|
||||
const remote = getRemote(dir);
|
||||
|
||||
|
@ -17,11 +17,21 @@
|
||||
|
||||
import { AlfrescoApi /*, NodesApi, UploadApi*/ } from '@alfresco/js-api';
|
||||
import { argv, exit } from 'node:process';
|
||||
// import { Buffer } from 'node:buffer';
|
||||
const program = require('commander');
|
||||
import { Command } from 'commander';
|
||||
import { logger } from './logger';
|
||||
|
||||
interface CheckCsEnvArgs {
|
||||
host?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
time?: number;
|
||||
retry?: number;
|
||||
}
|
||||
|
||||
const program = new Command();
|
||||
const MAX_RETRY = 3;
|
||||
const TIMEOUT = 20000;
|
||||
|
||||
let counter = 0;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
|
||||
@ -40,23 +50,26 @@ export default async function main() {
|
||||
.option('-r, --retry [type]', 'retry ')
|
||||
.parse(argv);
|
||||
|
||||
await checkEnv();
|
||||
const opts = program.opts<CheckCsEnvArgs>();
|
||||
await checkEnv(opts);
|
||||
// TODO: https://alfresco.atlassian.net/browse/ACS-5873
|
||||
// await checkDiskSpaceFullEnv();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check environment
|
||||
*
|
||||
* @param opts command options
|
||||
*/
|
||||
async function checkEnv() {
|
||||
async function checkEnv(opts?: CheckCsEnvArgs) {
|
||||
try {
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ECM',
|
||||
hostEcm: program.host,
|
||||
hostEcm: opts.host,
|
||||
contextRoot: 'alfresco'
|
||||
});
|
||||
|
||||
await alfrescoJsApi.login(program.username, program.password);
|
||||
await alfrescoJsApi.login(opts.username, opts.password);
|
||||
} catch (error) {
|
||||
if (error?.error?.code === 'ETIMEDOUT') {
|
||||
logger.error('The env is not reachable. Terminating');
|
||||
@ -64,8 +77,8 @@ async function checkEnv() {
|
||||
}
|
||||
logger.error('Login error environment down or inaccessible');
|
||||
counter++;
|
||||
const retry = program.retry || MAX_RETRY;
|
||||
const time = program.time || TIMEOUT;
|
||||
const retry = opts.retry || MAX_RETRY;
|
||||
const time = opts.time || TIMEOUT;
|
||||
if (retry === counter) {
|
||||
logger.error('Give up');
|
||||
exit(1);
|
||||
|
@ -16,15 +16,25 @@
|
||||
*/
|
||||
|
||||
import { argv } from 'node:process';
|
||||
import { PluginTarget } from './plugins/plugin-model';
|
||||
import { CheckEnv } from './plugins/check-env';
|
||||
import program = require('commander');
|
||||
import { Command } from 'commander';
|
||||
import { ProcessServiceCheckPlugin } from './plugins/process-service-check-plugin';
|
||||
import { ProcessAutomationCheckPlugin } from './plugins/process-automation-check-plugin';
|
||||
import { GovernanceCheckPlugin } from './plugins/governance-check-plugin';
|
||||
|
||||
const program = new Command();
|
||||
let pluginEnv: CheckEnv;
|
||||
|
||||
interface CheckPluginArgs {
|
||||
host?: string;
|
||||
pluginName?: 'processService' | 'processAutomation' | 'governance';
|
||||
clientId?: string;
|
||||
appName?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
uiName?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check environment plugin
|
||||
*/
|
||||
@ -40,30 +50,34 @@ export default async function main() {
|
||||
.option('--ui, --uiName [type]', 'uiName', 'Deployed app UI type on activiti-cloud')
|
||||
.parse(argv);
|
||||
|
||||
pluginEnv = new CheckEnv(program.host, program.username, program.password, program.clientId);
|
||||
const options = program.opts<CheckPluginArgs>();
|
||||
|
||||
pluginEnv = new CheckEnv(options.host, options.username, options.password, options.clientId);
|
||||
await pluginEnv.checkEnv();
|
||||
|
||||
if (program.pluginName === PluginTarget.processService) {
|
||||
await checkProcessServicesPlugin();
|
||||
if (options.pluginName === 'processService') {
|
||||
await checkProcessServicesPlugin(options);
|
||||
}
|
||||
|
||||
if (program.pluginName === PluginTarget.processAutomation) {
|
||||
await checkProcessAutomationPlugin();
|
||||
if (options.pluginName === 'processAutomation') {
|
||||
await checkProcessAutomationPlugin(options);
|
||||
}
|
||||
|
||||
if (program.pluginName === PluginTarget.governance) {
|
||||
await checkGovernancePlugin();
|
||||
if (options.pluginName === 'governance') {
|
||||
await checkGovernancePlugin(options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check PS plugin
|
||||
*
|
||||
* @param options program arguments
|
||||
*/
|
||||
async function checkProcessServicesPlugin() {
|
||||
async function checkProcessServicesPlugin(options: CheckPluginArgs) {
|
||||
const processServiceCheckPlugin = new ProcessServiceCheckPlugin(
|
||||
{
|
||||
host: program.host,
|
||||
name: PluginTarget.processService
|
||||
host: options.host,
|
||||
name: 'processService'
|
||||
},
|
||||
pluginEnv.alfrescoJsApi
|
||||
);
|
||||
@ -72,14 +86,16 @@ async function checkProcessServicesPlugin() {
|
||||
|
||||
/**
|
||||
* Check APA plugin
|
||||
*
|
||||
* @param options program arguments
|
||||
*/
|
||||
async function checkProcessAutomationPlugin() {
|
||||
async function checkProcessAutomationPlugin(options: CheckPluginArgs) {
|
||||
const processAutomationCheckPlugin = new ProcessAutomationCheckPlugin(
|
||||
{
|
||||
host: program.host,
|
||||
name: PluginTarget.processAutomation,
|
||||
appName: program.appName,
|
||||
uiName: program.uiName
|
||||
host: options.host,
|
||||
name: 'processAutomation',
|
||||
appName: options.appName,
|
||||
uiName: options.uiName
|
||||
},
|
||||
pluginEnv.alfrescoJsApi
|
||||
);
|
||||
@ -88,12 +104,14 @@ async function checkProcessAutomationPlugin() {
|
||||
|
||||
/**
|
||||
* Check AGS plugin
|
||||
*
|
||||
* @param options program arguments
|
||||
*/
|
||||
async function checkGovernancePlugin() {
|
||||
async function checkGovernancePlugin(options: CheckPluginArgs) {
|
||||
const governancePluginCheck = new GovernanceCheckPlugin(
|
||||
{
|
||||
host: program.host,
|
||||
name: PluginTarget.governance
|
||||
host: options.host,
|
||||
name: 'governance'
|
||||
},
|
||||
pluginEnv.alfrescoJsApi
|
||||
);
|
||||
|
@ -19,10 +19,12 @@
|
||||
|
||||
import { argv, exit } from 'node:process';
|
||||
import { exec } from './exec';
|
||||
import program from 'commander';
|
||||
import { Command } from 'commander';
|
||||
import { logger } from './logger';
|
||||
import { resolve } from 'path';
|
||||
|
||||
const program = new Command();
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
enum TARGETS {
|
||||
publish = 'publish',
|
||||
|
@ -17,18 +17,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import program from 'commander';
|
||||
import { Command } from 'commander';
|
||||
import fetch from 'node-fetch';
|
||||
import * as fs from 'fs';
|
||||
import { logger } from './logger';
|
||||
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
|
||||
import { argv, exit } from 'node:process';
|
||||
|
||||
const program = new Command();
|
||||
const ACTIVITI_CLOUD_APPS = require('./resources').ACTIVITI_CLOUD_APPS;
|
||||
|
||||
let alfrescoJsApiModeler: AlfrescoApi;
|
||||
let alfrescoJsApiDevops: AlfrescoApi;
|
||||
let args: ConfigArgs;
|
||||
let isValid = true;
|
||||
|
||||
export interface ConfigArgs {
|
||||
modelerUsername: string;
|
||||
modelerPassword: string;
|
||||
@ -424,7 +427,7 @@ function deploy(model: any) {
|
||||
* @param options token options
|
||||
* @returns options
|
||||
*/
|
||||
function initializeDefaultToken(options: any): any {
|
||||
function initializeDefaultToken(options: ConfigArgs): any {
|
||||
options.tokenEndpoint = options.tokenEndpoint.replace('${clientId}', options.clientId);
|
||||
return options;
|
||||
}
|
||||
@ -680,18 +683,21 @@ async function getFileFromRemote(url: string, name: string): Promise<void> {
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.then((response) => new Promise<void>((resolve, reject) => {
|
||||
const outputFile = fs.createWriteStream(`${name}.zip`);
|
||||
response.body.pipe(outputFile);
|
||||
outputFile.on('finish', () => {
|
||||
logger.info(`The file is finished downloading.`);
|
||||
resolve();
|
||||
});
|
||||
outputFile.on('error', (error) => {
|
||||
logger.error(`Not possible to download the project form remote`);
|
||||
reject(error);
|
||||
});
|
||||
}))
|
||||
.then(
|
||||
(response) =>
|
||||
new Promise<void>((resolve, reject) => {
|
||||
const outputFile = fs.createWriteStream(`${name}.zip`);
|
||||
response.body.pipe(outputFile);
|
||||
outputFile.on('finish', () => {
|
||||
logger.info(`The file is finished downloading.`);
|
||||
resolve();
|
||||
});
|
||||
outputFile.on('error', (error) => {
|
||||
logger.error(`Not possible to download the project form remote`);
|
||||
reject(error);
|
||||
});
|
||||
})
|
||||
)
|
||||
.catch((error) => {
|
||||
logger.error(`Failed to fetch file from remote: ${error.message}`);
|
||||
throw error;
|
||||
|
@ -17,10 +17,19 @@
|
||||
|
||||
import { AlfrescoApi, SharedlinksApi, FavoritesApi, NodesApi, UploadApi, NodeEntry } from '@alfresco/js-api';
|
||||
import { exit, argv } from 'node:process';
|
||||
const program = require('commander');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
import { Command } from 'commander';
|
||||
import { createReadStream } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { logger } from './logger';
|
||||
|
||||
interface InitAcsEnvArgs {
|
||||
host?: string;
|
||||
clientId?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
const program = new Command();
|
||||
const MAX_RETRY = 10;
|
||||
let counter = 0;
|
||||
const TIMEOUT = 6000;
|
||||
@ -40,7 +49,8 @@ export default async function main() {
|
||||
.option('-u, --username [type]', 'username ')
|
||||
.parse(argv);
|
||||
|
||||
await checkEnv();
|
||||
const opts = program.opts<InitAcsEnvArgs>();
|
||||
await checkEnv(opts);
|
||||
|
||||
logger.info(`***** Step initialize ACS *****`);
|
||||
await initializeDefaultFiles();
|
||||
@ -117,7 +127,7 @@ async function createFolder(folderName: string, parentId: string) {
|
||||
*/
|
||||
async function uploadFile(fileName: string, fileDestination: string): Promise<NodeEntry> {
|
||||
const filePath = `../resources/content/${fileName}`;
|
||||
const file = fs.createReadStream(path.join(__dirname, filePath));
|
||||
const file = createReadStream(path.join(__dirname, filePath));
|
||||
let uploadedFile: NodeEntry;
|
||||
try {
|
||||
uploadedFile = await new UploadApi(alfrescoJsApi).uploadFile(file, '', fileDestination, null, {
|
||||
@ -192,23 +202,25 @@ async function favoriteFile(nodeId: string) {
|
||||
|
||||
/**
|
||||
* Check environment state
|
||||
*
|
||||
* @param opts command options
|
||||
*/
|
||||
async function checkEnv() {
|
||||
async function checkEnv(opts: InitAcsEnvArgs) {
|
||||
try {
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ALL',
|
||||
hostBpm: program.host,
|
||||
hostEcm: program.host,
|
||||
hostBpm: opts.host,
|
||||
hostEcm: opts.host,
|
||||
authType: 'OAUTH',
|
||||
oauth2: {
|
||||
host: `${program.host}/auth/realms/alfresco`,
|
||||
clientId: `${program.clientId}`,
|
||||
host: `${opts.host}/auth/realms/alfresco`,
|
||||
clientId: `${opts.clientId}`,
|
||||
scope: 'openid',
|
||||
redirectUri: '/'
|
||||
},
|
||||
contextRoot: 'alfresco'
|
||||
});
|
||||
await alfrescoJsApi.login(program.username, program.password);
|
||||
await alfrescoJsApi.login(opts.username, opts.password);
|
||||
} catch (e) {
|
||||
if (e.error.code === 'ETIMEDOUT') {
|
||||
logger.error('The env is not reachable. Terminating');
|
||||
@ -222,12 +234,11 @@ async function checkEnv() {
|
||||
} else {
|
||||
logger.error(`Retry in 1 minute attempt N ${counter}`);
|
||||
sleep(TIMEOUT);
|
||||
await checkEnv();
|
||||
await checkEnv(opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform a delay
|
||||
*
|
||||
|
@ -15,14 +15,33 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AdminTenantsApi, AdminUsersApi, AlfrescoApi, TenantRepresentation, AppDefinitionsApi, RuntimeAppDefinitionsApi, UserRepresentation, AppDefinitionUpdateResultRepresentation } from '@alfresco/js-api';
|
||||
import {
|
||||
AdminTenantsApi,
|
||||
AdminUsersApi,
|
||||
AlfrescoApi,
|
||||
TenantRepresentation,
|
||||
AppDefinitionsApi,
|
||||
RuntimeAppDefinitionsApi,
|
||||
UserRepresentation,
|
||||
AppDefinitionUpdateResultRepresentation
|
||||
} from '@alfresco/js-api';
|
||||
import { argv, exit } from 'node:process';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { createReadStream } from 'node:fs';
|
||||
const program = require('commander');
|
||||
const path = require('path');
|
||||
import { Command } from 'commander';
|
||||
import * as path from 'path';
|
||||
import { logger } from './logger';
|
||||
const { throwError } = require('rxjs');
|
||||
import { throwError } from 'rxjs';
|
||||
|
||||
interface InitApsEnvArgs {
|
||||
host?: string;
|
||||
clientId?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
license?: string;
|
||||
}
|
||||
|
||||
const program = new Command();
|
||||
const MAX_RETRY = 10;
|
||||
let counter = 0;
|
||||
const TIMEOUT = 6000;
|
||||
@ -37,7 +56,6 @@ let alfrescoJsApi: AlfrescoApi;
|
||||
* Init APS command
|
||||
*/
|
||||
export default async function main() {
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.option('--host [type]', 'Remote environment host')
|
||||
@ -47,23 +65,25 @@ export default async function main() {
|
||||
.option('--license [type]', 'APS license S3 path ')
|
||||
.parse(argv);
|
||||
|
||||
await checkEnv();
|
||||
const opts = program.opts<InitApsEnvArgs>();
|
||||
await checkEnv(opts);
|
||||
|
||||
logger.info(`***** Step 1 - Check License *****`);
|
||||
|
||||
let licenceUploaded = false;
|
||||
const hasValidLicense = await hasLicense() ;
|
||||
const hasValidLicense = await hasLicense(opts);
|
||||
if (!hasValidLicense) {
|
||||
logger.info(`Aps License missing`);
|
||||
const isLicenseFileDownloaded = await downloadLicenseFile(program.license);
|
||||
const isLicenseFileDownloaded = await downloadLicenseFile(opts.license);
|
||||
if (isLicenseFileDownloaded) {
|
||||
licenceUploaded = await updateLicense();
|
||||
licenceUploaded = await updateLicense(opts);
|
||||
}
|
||||
} else {
|
||||
licenceUploaded = true;
|
||||
logger.info(`Aps License present`);
|
||||
}
|
||||
let tenantId;
|
||||
|
||||
let tenantId: number;
|
||||
if (licenceUploaded) {
|
||||
logger.info(`***** Step 2 - Check Tenant *****`);
|
||||
logger.info(`is tenantId:${TENANT_DEFAULT_ID} with name:${TENANT_DEFAULT_NAME} present?`);
|
||||
@ -75,13 +95,13 @@ export default async function main() {
|
||||
tenantId = await createDefaultTenant(TENANT_DEFAULT_NAME);
|
||||
}
|
||||
logger.info(`***** Step 3 - Add Content Repo *****`);
|
||||
const isContentPresent = await isContentRepoPresent(TENANT_DEFAULT_ID, CONTENT_DEFAULT_NAME);
|
||||
const isContentPresent = await isContentRepoPresent(opts, TENANT_DEFAULT_ID, CONTENT_DEFAULT_NAME);
|
||||
if (!isContentPresent) {
|
||||
logger.info(`No content repo with name ${CONTENT_DEFAULT_NAME} found`);
|
||||
await addContentRepoWithBasic(TENANT_DEFAULT_ID, CONTENT_DEFAULT_NAME);
|
||||
await addContentRepoWithBasic(opts, TENANT_DEFAULT_ID, CONTENT_DEFAULT_NAME);
|
||||
}
|
||||
logger.info(`***** Step 4 - Create users *****`);
|
||||
const users = await getDefaultApsUsersFromRealm();
|
||||
const users = await getDefaultApsUsersFromRealm(opts);
|
||||
if (tenantId && users && users.length > 0) {
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
await createUsers(tenantId, users[i]);
|
||||
@ -89,19 +109,17 @@ export default async function main() {
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
logger.info('Impersonate user: ' + users[i].username);
|
||||
await alfrescoJsApi.login(users[i].username, 'password');
|
||||
await authorizeUserToContentRepo(users[i]);
|
||||
await authorizeUserToContentRepo(opts, users[i]);
|
||||
|
||||
const defaultUser = 'hruser';
|
||||
if (users[i].username.includes(defaultUser)) {
|
||||
logger.info(`***** Step initialize APS apps for user ${defaultUser} *****`);
|
||||
await initializeDefaultApps();
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
logger.info('Something went wrong. Was not able to create the users');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
logger.info(`Aps something went wrong. Tenant id ${tenantId}`);
|
||||
exit(1);
|
||||
@ -110,7 +128,6 @@ export default async function main() {
|
||||
logger.info('APS license error: check the configuration');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,23 +148,25 @@ async function initializeDefaultApps() {
|
||||
|
||||
/**
|
||||
* Check environment
|
||||
*
|
||||
* @param opts command options
|
||||
*/
|
||||
async function checkEnv() {
|
||||
async function checkEnv(opts: InitApsEnvArgs) {
|
||||
try {
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ALL',
|
||||
hostBpm: program.host,
|
||||
hostEcm: program.host,
|
||||
hostBpm: opts.host,
|
||||
hostEcm: opts.host,
|
||||
authType: 'OAUTH',
|
||||
contextRoot: 'alfresco',
|
||||
oauth2: {
|
||||
host: `${program.host}/auth/realms/alfresco`,
|
||||
clientId: `${program.clientId}`,
|
||||
host: `${opts.host}/auth/realms/alfresco`,
|
||||
clientId: `${opts.clientId}`,
|
||||
scope: 'openid',
|
||||
redirectUri: '/'
|
||||
}
|
||||
});
|
||||
await alfrescoJsApi.login(program.username, program.password);
|
||||
await alfrescoJsApi.login(opts.username, opts.password);
|
||||
} catch (e) {
|
||||
if (e.error.code === 'ETIMEDOUT') {
|
||||
logger.error('The env is not reachable. Terminating');
|
||||
@ -161,7 +180,7 @@ async function checkEnv() {
|
||||
} else {
|
||||
logger.error(`Retry in 1 minute attempt N ${counter}`);
|
||||
sleep(TIMEOUT);
|
||||
await checkEnv();
|
||||
await checkEnv(opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,7 +222,7 @@ async function createDefaultTenant(tenantName: string) {
|
||||
const tenantPost = {
|
||||
active: true,
|
||||
maxUsers: 10000,
|
||||
name : tenantName
|
||||
name: tenantName
|
||||
};
|
||||
|
||||
try {
|
||||
@ -212,7 +231,7 @@ async function createDefaultTenant(tenantName: string) {
|
||||
logger.info(`APS: Tenant ${tenantName} created with id: ${tenant.id}`);
|
||||
return tenant.id;
|
||||
} catch (error) {
|
||||
logger.info(`APS: not able to create the default tenant: ${JSON.parse(error.message)}` );
|
||||
logger.info(`APS: not able to create the default tenant: ${JSON.parse(error.message)}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -242,19 +261,21 @@ async function createUsers(tenantId: number, user: any) {
|
||||
logger.info(`APS: User ${userInfo.email} created with id: ${userInfo.id}`);
|
||||
return user;
|
||||
} catch (error) {
|
||||
logger.info(`APS: not able to create the default user: ${error.message}` );
|
||||
logger.info(`APS: not able to create the default user: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Activiti license
|
||||
*
|
||||
* @param opts command options
|
||||
*/
|
||||
async function updateLicense() {
|
||||
async function updateLicense(opts: InitApsEnvArgs) {
|
||||
const fileContent = createReadStream(path.join(__dirname, '/activiti.lic'));
|
||||
|
||||
try {
|
||||
await alfrescoJsApi.oauth2Auth.callCustomApi(
|
||||
`${program.host}/activiti-app/app/rest/license`,
|
||||
`${opts.host}/activiti-app/app/rest/license`,
|
||||
'POST',
|
||||
{},
|
||||
{},
|
||||
@ -283,7 +304,7 @@ async function isDefaultAppDeployed(appName: string): Promise<boolean> {
|
||||
try {
|
||||
const runtimeAppDefinitionsApi = new RuntimeAppDefinitionsApi(alfrescoJsApi);
|
||||
const availableApps = await runtimeAppDefinitionsApi.getAppDefinitions();
|
||||
const defaultApp = availableApps.data?.filter(app => app.name?.includes(appName));
|
||||
const defaultApp = availableApps.data?.filter((app) => app.name?.includes(appName));
|
||||
return defaultApp && defaultApp.length > 0;
|
||||
} catch (error) {
|
||||
logger.error(`Aps app failed to import/Publish!`);
|
||||
@ -304,7 +325,7 @@ async function importPublishApp(appName: string): Promise<AppDefinitionUpdateRes
|
||||
|
||||
try {
|
||||
const appDefinitionsApi = new AppDefinitionsApi(alfrescoJsApi);
|
||||
const result = await appDefinitionsApi.importAndPublishApp(fileContent, {renewIdmEntries: true});
|
||||
const result = await appDefinitionsApi.importAndPublishApp(fileContent, { renewIdmEntries: true });
|
||||
logger.info(`Aps app imported and published!`);
|
||||
return result;
|
||||
} catch (error) {
|
||||
@ -321,7 +342,7 @@ async function importPublishApp(appName: string): Promise<AppDefinitionUpdateRes
|
||||
async function deployApp(appDefinitionId: number) {
|
||||
logger.info(`Deploy app with id ${appDefinitionId}`);
|
||||
const body = {
|
||||
appDefinitions: [{id: appDefinitionId}]
|
||||
appDefinitions: [{ id: appDefinitionId }]
|
||||
};
|
||||
|
||||
try {
|
||||
@ -335,11 +356,13 @@ async function deployApp(appDefinitionId: number) {
|
||||
|
||||
/**
|
||||
* Checks if Activiti app has license
|
||||
*
|
||||
* @param opts command options
|
||||
*/
|
||||
async function hasLicense(): Promise<boolean> {
|
||||
async function hasLicense(opts: InitApsEnvArgs): Promise<boolean> {
|
||||
try {
|
||||
const license = await alfrescoJsApi.oauth2Auth.callCustomApi(
|
||||
`${program.host}/activiti-app/app/rest/license`,
|
||||
`${opts.host}/activiti-app/app/rest/license`,
|
||||
'GET',
|
||||
{},
|
||||
{},
|
||||
@ -356,18 +379,20 @@ async function hasLicense(): Promise<boolean> {
|
||||
logger.info(`Aps does NOT have a valid License!`);
|
||||
return false;
|
||||
} catch (error) {
|
||||
logger.error(`Aps not able to check the license` );
|
||||
logger.error(`Aps not able to check the license`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default users from the realm
|
||||
*
|
||||
* @param opts command options
|
||||
*/
|
||||
async function getDefaultApsUsersFromRealm() {
|
||||
async function getDefaultApsUsersFromRealm(opts: InitApsEnvArgs) {
|
||||
try {
|
||||
const users: any[] = await alfrescoJsApi.oauth2Auth.callCustomApi(
|
||||
`${program.host}/auth/admin/realms/alfresco/users`,
|
||||
`${opts.host}/auth/admin/realms/alfresco/users`,
|
||||
'GET',
|
||||
{},
|
||||
{ max: 1000 },
|
||||
@ -378,11 +403,11 @@ async function getDefaultApsUsersFromRealm() {
|
||||
['application/json']
|
||||
);
|
||||
const usernamesOfApsDefaultUsers = ['hruser', 'salesuser', 'superadminuser'];
|
||||
const apsDefaultUsers = users.filter(user => usernamesOfApsDefaultUsers.includes(user.username));
|
||||
const apsDefaultUsers = users.filter((user) => usernamesOfApsDefaultUsers.includes(user.username));
|
||||
logger.info(`Keycloak found ${apsDefaultUsers.length} users`);
|
||||
return apsDefaultUsers;
|
||||
} catch (error) {
|
||||
logger.error(`APS: not able to fetch user: ${error.message}` );
|
||||
logger.error(`APS: not able to fetch user: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -390,13 +415,14 @@ async function getDefaultApsUsersFromRealm() {
|
||||
/**
|
||||
* Validate that ACS repo for Activiti is present
|
||||
*
|
||||
* @param opts command options
|
||||
* @param tenantId tenant id
|
||||
* @param contentName content service name
|
||||
*/
|
||||
async function isContentRepoPresent(tenantId: number, contentName: string): Promise<boolean> {
|
||||
async function isContentRepoPresent(opts: InitApsEnvArgs, tenantId: number, contentName: string): Promise<boolean> {
|
||||
try {
|
||||
const contentRepos = await alfrescoJsApi.oauth2Auth.callCustomApi(
|
||||
`${program.host}/activiti-app/app/rest/integration/alfresco?tenantId=${tenantId}`,
|
||||
`${opts.host}/activiti-app/app/rest/integration/alfresco?tenantId=${tenantId}`,
|
||||
'GET',
|
||||
{},
|
||||
{},
|
||||
@ -406,9 +432,9 @@ async function isContentRepoPresent(tenantId: number, contentName: string): Prom
|
||||
['application/json'],
|
||||
['application/json']
|
||||
);
|
||||
return !!contentRepos.data.find(repo => repo.name === contentName);
|
||||
return !!contentRepos.data.find((repo) => repo.name === contentName);
|
||||
} catch (error) {
|
||||
logger.error(`APS: not able to create content: ${error.message}` );
|
||||
logger.error(`APS: not able to create content: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -416,18 +442,19 @@ async function isContentRepoPresent(tenantId: number, contentName: string): Prom
|
||||
/**
|
||||
* Add content service with basic auth
|
||||
*
|
||||
* @param opts command options
|
||||
* @param tenantId tenant id
|
||||
* @param name content name
|
||||
*/
|
||||
async function addContentRepoWithBasic(tenantId: number, name: string) {
|
||||
async function addContentRepoWithBasic(opts: InitApsEnvArgs, tenantId: number, name: string) {
|
||||
logger.info(`Create Content with name ${name} and basic auth`);
|
||||
|
||||
const body = {
|
||||
alfrescoTenantId: '',
|
||||
authenticationType: 'basic',
|
||||
name,
|
||||
repositoryUrl: `${program.host}/alfresco`,
|
||||
shareUrl: `${program.host}/share`,
|
||||
repositoryUrl: `${opts.host}/alfresco`,
|
||||
shareUrl: `${opts.host}/share`,
|
||||
// sitesFolder: '', not working on activiti 1.11.1.1
|
||||
tenantId,
|
||||
version: '6.1.1'
|
||||
@ -435,7 +462,7 @@ async function addContentRepoWithBasic(tenantId: number, name: string) {
|
||||
|
||||
try {
|
||||
const content = await alfrescoJsApi.oauth2Auth.callCustomApi(
|
||||
`${program.host}/activiti-app/app/rest/integration/alfresco`,
|
||||
`${opts.host}/activiti-app/app/rest/integration/alfresco`,
|
||||
'POST',
|
||||
{},
|
||||
{},
|
||||
@ -448,20 +475,21 @@ async function addContentRepoWithBasic(tenantId: number, name: string) {
|
||||
logger.info(`Content created!`);
|
||||
return content;
|
||||
} catch (error) {
|
||||
logger.error(`APS: not able to create content: ${error.message}` );
|
||||
logger.error(`APS: not able to create content: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize activiti user to ACS repo
|
||||
*
|
||||
* @param opts command options
|
||||
* @param user user object
|
||||
*/
|
||||
async function authorizeUserToContentRepo(user: any) {
|
||||
async function authorizeUserToContentRepo(opts: InitApsEnvArgs, user: any) {
|
||||
logger.info(`Authorize user ${user.email}`);
|
||||
try {
|
||||
const content = await alfrescoJsApi.oauth2Auth.callCustomApi(
|
||||
`${program.host}/activiti-app/app/rest/integration/alfresco`,
|
||||
`${opts.host}/activiti-app/app/rest/integration/alfresco`,
|
||||
'GET',
|
||||
{},
|
||||
{},
|
||||
@ -475,28 +503,29 @@ async function authorizeUserToContentRepo(user: any) {
|
||||
if (content.data) {
|
||||
for (let i = 0; i < content.data.length; i++) {
|
||||
if (content.data[i].authenticationType === 'basic') {
|
||||
await authorizeUserToContentWithBasic(user.username, content.data[i].id);
|
||||
await authorizeUserToContentWithBasic(opts, user.username, content.data[i].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
} catch (error) {
|
||||
logger.error(`APS: not able to authorize content: ${error.message}` );
|
||||
logger.error(`APS: not able to authorize content: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize user with content using basic auth
|
||||
*
|
||||
* @param opts command options
|
||||
* @param username username
|
||||
* @param contentId content id
|
||||
*/
|
||||
async function authorizeUserToContentWithBasic(username: string, contentId: string) {
|
||||
async function authorizeUserToContentWithBasic(opts: InitApsEnvArgs, username: string, contentId: string) {
|
||||
logger.info(`Authorize ${username} on contentId: ${contentId} in basic auth`);
|
||||
try {
|
||||
const body = {username, password: 'password'};
|
||||
const body = { username, password: 'password' };
|
||||
const content = await alfrescoJsApi.oauth2Auth.callCustomApi(
|
||||
`${program.host}/activiti-app/app/rest/integration/alfresco/${contentId}/account`,
|
||||
`${opts.host}/activiti-app/app/rest/integration/alfresco/${contentId}/account`,
|
||||
'POST',
|
||||
{},
|
||||
{},
|
||||
@ -509,7 +538,7 @@ async function authorizeUserToContentWithBasic(username: string, contentId: stri
|
||||
logger.info(`User authorized!`);
|
||||
return content;
|
||||
} catch (error) {
|
||||
logger.error(`APS: not able to authorize content: ${error.message}` );
|
||||
logger.error(`APS: not able to authorize content: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -519,12 +548,7 @@ async function authorizeUserToContentWithBasic(username: string, contentId: stri
|
||||
* @param apsLicensePath path to license file
|
||||
*/
|
||||
async function downloadLicenseFile(apsLicensePath: string) {
|
||||
const args = [
|
||||
`s3`,
|
||||
`cp`,
|
||||
apsLicensePath,
|
||||
`./`
|
||||
];
|
||||
const args = [`s3`, `cp`, apsLicensePath, `./`];
|
||||
const result = spawnSync(`aws`, args, {
|
||||
cwd: path.resolve(__dirname, `./`),
|
||||
shell: false
|
||||
@ -545,5 +569,5 @@ async function downloadLicenseFile(apsLicensePath: string) {
|
||||
*/
|
||||
function sleep(delay: number) {
|
||||
const start = new Date().getTime();
|
||||
while (new Date().getTime() < start + delay) { }
|
||||
while (new Date().getTime() < start + delay) {}
|
||||
}
|
||||
|
@ -23,7 +23,14 @@ import * as fs from 'fs';
|
||||
import * as checker from 'license-checker';
|
||||
import * as licenseList from 'spdx-license-list';
|
||||
import * as ejs from 'ejs';
|
||||
import program from 'commander';
|
||||
import { Command } from 'commander';
|
||||
|
||||
const program = new Command();
|
||||
|
||||
interface LicensesCommandArgs {
|
||||
package?: string;
|
||||
outDir?: string;
|
||||
}
|
||||
|
||||
interface PackageInfo {
|
||||
name: string;
|
||||
@ -110,10 +117,11 @@ export default function main(_args: string[], workingDir: string) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const options = program.opts<LicensesCommandArgs>();
|
||||
let packagePath = path.resolve(workingDir, 'package.json');
|
||||
|
||||
if (program.package) {
|
||||
packagePath = path.resolve(program.package);
|
||||
if (options.package) {
|
||||
packagePath = path.resolve(options.package);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(packagePath)) {
|
||||
@ -183,7 +191,7 @@ export default function main(_args: string[], workingDir: string) {
|
||||
console.error(ejsError);
|
||||
reject(ejsError);
|
||||
} else {
|
||||
const outputPath = path.resolve(program.outDir || workingDir);
|
||||
const outputPath = path.resolve(options.outDir || workingDir);
|
||||
const outputFile = path.join(outputPath, `license-info-${packageJson.version}.md`);
|
||||
|
||||
fs.writeFileSync(outputFile, mdText);
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
import { exit } from 'node:process';
|
||||
import { logger } from './../logger';
|
||||
import { logger } from '../logger';
|
||||
|
||||
const TIMEOUT = 6000;
|
||||
const MAX_RETRY = 10;
|
||||
|
@ -15,13 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
export enum PluginTarget {
|
||||
processService = 'processService',
|
||||
processAutomation = 'processAutomation',
|
||||
governance = 'governance'
|
||||
}
|
||||
|
||||
export interface PluginInterface {
|
||||
name: string;
|
||||
host: string;
|
||||
|
18
package-lock.json
generated
18
package-lock.json
generated
@ -90,7 +90,7 @@
|
||||
"@typescript-eslint/parser": "5.62.0",
|
||||
"@typescript-eslint/typescript-estree": "7.1.1",
|
||||
"ajv": "^8.12.0",
|
||||
"commander": "6.2.1",
|
||||
"commander": "12.0.0",
|
||||
"css-loader": "^6.10.0",
|
||||
"dotenv": "16.1.3",
|
||||
"editorjs-html": "3.4.3",
|
||||
@ -19004,6 +19004,15 @@
|
||||
"node": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@storybook/core/node_modules/commander": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz",
|
||||
"integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/@storybook/core/node_modules/cosmiconfig": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz",
|
||||
@ -27780,11 +27789,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "6.2.1",
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz",
|
||||
"integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/comment-json": {
|
||||
|
@ -135,7 +135,7 @@
|
||||
"@typescript-eslint/parser": "5.62.0",
|
||||
"@typescript-eslint/typescript-estree": "7.1.1",
|
||||
"ajv": "^8.12.0",
|
||||
"commander": "6.2.1",
|
||||
"commander": "12.0.0",
|
||||
"css-loader": "^6.10.0",
|
||||
"dotenv": "16.1.3",
|
||||
"editorjs-html": "3.4.3",
|
||||
|
Loading…
x
Reference in New Issue
Block a user