[AAE-10835] adf-cli Being able to pass params as input to handle custom cases (#7880)

* Being able to pass params as input to handle hxp

* Fix default

* Fix lint

* Use a default value for tokenEndpoint for compatibility

* Fix the lint
This commit is contained in:
Maurizio Vitale 2022-10-31 13:20:15 +00:00 committed by GitHub
parent 864bc33598
commit 65e0961a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,10 +35,12 @@ export interface ConfigArgs {
modelerPassword: string; modelerPassword: string;
devopsUsername: string; devopsUsername: string;
devopsPassword: string; devopsPassword: string;
clientId: string;
host: string;
oauth: string; oauth: string;
identityHost: boolean; tokenEndpoint: string;
clientId: string;
secret: string;
scope: string;
host: string;
tag: string; tag: string;
} }
@ -267,6 +269,11 @@ function deploy(model: any) {
} }
} }
function initializeDefaultToken(options) {
options.tokenEndpoint = options.tokenEndpoint.replace('${clientId}', options.clientId);
return options;
}
function getAlfrescoJsApiInstance(configArgs: ConfigArgs) { function getAlfrescoJsApiInstance(configArgs: ConfigArgs) {
let ssoHost = configArgs.oauth; let ssoHost = configArgs.oauth;
ssoHost = ssoHost ?? configArgs.host; ssoHost = ssoHost ?? configArgs.host;
@ -275,11 +282,12 @@ function getAlfrescoJsApiInstance(configArgs: ConfigArgs) {
provider: 'BPM', provider: 'BPM',
hostBpm: `${configArgs.host}`, hostBpm: `${configArgs.host}`,
authType: 'OAUTH', authType: 'OAUTH',
oauth2: { oauth2 : {
host: `${ssoHost}/auth/realms/alfresco`, host: `${ssoHost}`,
tokenUrl: `${ssoHost}/${configArgs.tokenEndpoint}`,
clientId: `${configArgs.clientId}`, clientId: `${configArgs.clientId}`,
scope: 'openid', scope: `${configArgs.scope}`,
secret: '', secret: `${configArgs.secret}`,
implicitFlow: false, implicitFlow: false,
silentLogin: false, silentLogin: false,
redirectUri: '/' redirectUri: '/'
@ -454,13 +462,11 @@ async function sleep(time: number) {
return; return;
} }
export default async function(configArgs: ConfigArgs) { export default async function() {
await main(configArgs); await main();
} }
async function main(configArgs: ConfigArgs) { async function main() {
args = configArgs;
program program
.version('0.1.0') .version('0.1.0')
.description('The following command is in charge of Initializing the activiti cloud env with the default apps' + .description('The following command is in charge of Initializing the activiti cloud env with the default apps' +
@ -468,6 +474,9 @@ async function main(configArgs: ConfigArgs) {
.option('-h, --host [type]', 'Host gateway') .option('-h, --host [type]', 'Host gateway')
.option('--oauth [type]', 'SSO host') .option('--oauth [type]', 'SSO host')
.option('--clientId [type]', 'sso client') .option('--clientId [type]', 'sso client')
.option('--secret [type]', 'sso secret', '')
.option('--scope [type]', 'sso scope', 'openid')
.option('--tokenEndpoint [type]', 'discovery token Endpoint', 'auth/realms/${clientId}/protocol/openid-connect/token')
.option('--modelerUsername [type]', 'username of a user with role ACTIVIT_MODELER') .option('--modelerUsername [type]', 'username of a user with role ACTIVIT_MODELER')
.option('--modelerPassword [type]', 'modeler password') .option('--modelerPassword [type]', 'modeler password')
.option('--devopsUsername [type]', 'username of a user with role ACTIVIT_DEVOPS') .option('--devopsUsername [type]', 'username of a user with role ACTIVIT_DEVOPS')
@ -480,6 +489,22 @@ async function main(configArgs: ConfigArgs) {
return; return;
} }
const options = initializeDefaultToken(program.opts());
args = {
host: options.host,
clientId: options.clientId,
devopsUsername: options.devopsUsername,
devopsPassword: options.devopsPassword,
modelerUsername: options.modelerUsername,
modelerPassword: options.modelerPassword,
oauth: options.oauth,
tokenEndpoint: options.tokenEndpoint,
scope: options.scope,
secret: options.secret,
tag: options.tag
};
alfrescoJsApiModeler = getAlfrescoJsApiInstance(args); alfrescoJsApiModeler = getAlfrescoJsApiInstance(args);
AAE_MICROSERVICES.map(async (serviceName) => { AAE_MICROSERVICES.map(async (serviceName) => {