From 562fa17f2909cf00994f6152092bf88e2b94b5b5 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 11 Aug 2025 15:47:19 -0700 Subject: [PATCH] APIGOV-30273 CLI - Update Axway CLI to set new region selection/URLs - V3 --- packages/amplify-cli-utils/src/index.js | 2 ++ packages/amplify-sdk/src/amplify-sdk.js | 5 ++-- packages/amplify-sdk/src/auth.js | 10 ++++--- .../src/authenticators/authenticator.js | 3 ++- packages/amplify-sdk/src/environments.js | 27 +++++++++++++++---- packages/axway-cli-pm/src/pm.js | 2 +- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/packages/amplify-cli-utils/src/index.js b/packages/amplify-cli-utils/src/index.js index 69c6e6e9..28657c41 100644 --- a/packages/amplify-cli-utils/src/index.js +++ b/packages/amplify-cli-utils/src/index.js @@ -50,6 +50,7 @@ export function buildAuthParams(opts = {}, config) { } const env = environments.resolve(opts.env || config.get('env')); + const region = opts.region || config.get('region'); const { clientId, realm } = env.auth; const params = {}; @@ -64,6 +65,7 @@ export function buildAuthParams(opts = {}, config) { persistSecrets: undefined, platformUrl: undefined, realm, + region: region, secretFile: undefined, serverHost: undefined, serverPort: undefined, diff --git a/packages/amplify-sdk/src/amplify-sdk.js b/packages/amplify-sdk/src/amplify-sdk.js index cdca1732..c13e2bac 100644 --- a/packages/amplify-sdk/src/amplify-sdk.js +++ b/packages/amplify-sdk/src/amplify-sdk.js @@ -27,6 +27,7 @@ export default class AmplifySDK { * * @param {Object} opts - Authentication options. * @param {Object} [opts.env=prod] - The environment name. + * @param {Object} [opts.region=us] - The region name. * @param {Object} [opts.requestOptions] - HTTP request options with proxy settings and such to * create a `got` HTTP client. * @access public @@ -48,7 +49,7 @@ export default class AmplifySDK { * Resolved environment-specific settings. * @type {Object} */ - this.env = environments.resolve(opts.env); + this.env = environments.resolve(opts.env, opts.region); // set the defaults based on the environment for (const prop of [ 'baseUrl', 'platformUrl', 'realm' ]) { @@ -403,7 +404,7 @@ export default class AmplifySDK { for (const account of accounts) { if (account.isPlatform && !account.isPlatformTooling) { // note: there should only be 1 platform account in the accounts list - const { platformUrl } = environments.resolve(account.auth.env); + const { platformUrl } = environments.resolve(account.auth.env, this.opts.region); const redirect = `${platformUrl}/signed.out?msg=signout`; const url = `${platformUrl}/auth/signout?redirect=${encodeURIComponent(redirect)}`; if (typeof opts.onOpenBrowser === 'function') { diff --git a/packages/amplify-sdk/src/auth.js b/packages/amplify-sdk/src/auth.js index c9c1787b..b14f2642 100644 --- a/packages/amplify-sdk/src/auth.js +++ b/packages/amplify-sdk/src/auth.js @@ -49,6 +49,7 @@ export default class Auth { * @param {String} [opts.clientId] - The client id to specify when authenticating. * @param {String} [opts.clientSecret] - The secret token to use to authenticate. * @param {String} [opts.env=prod] - The environment name. Must be `staging` or `prod`. + * @param {String} [opts.region=us] - The region name. Must be `us` or `eu`. * The environment is a shorthand way of specifying a Axway default base URL. * @param {Function} [opts.got] - A reference to a `got` HTTP client. If not defined, the * default `got` instance will be used. @@ -118,7 +119,8 @@ export default class Auth { username: { value: opts.username } }); - this.env = environments.resolve(opts.env).name; + this.env = environments.resolve(opts.env, opts.region).name; + this.region = opts.region; if (opts.tokenStore) { if (!(opts.tokenStore instanceof TokenStore)) { @@ -188,7 +190,8 @@ export default class Auth { } const name = opts.env || this.env; - const env = environments.resolve(name); + const region = opts.region || this.region; + const env = environments.resolve(name, region); if (!env) { throw E.INVALID_VALUE(`Invalid environment: ${name}`); } @@ -206,6 +209,7 @@ export default class Auth { persistSecrets: opts.persistSecrets !== undefined ? opts.persistSecrets : this.persistSecrets, platformUrl: opts.platformUrl || this.platformUrl, realm: opts.realm || this.realm, + region: region, secretFile: opts.secretFile || this.secretFile, serviceAccount: opts.serviceAccount || this.serviceAccount, timeout: opts.timeout || opts.interactiveLoginTimeout || this.interactiveLoginTimeout, @@ -455,7 +459,7 @@ export default class Auth { for (const entry of revoked) { // don't logout of platform accounts here, it's done in the Amplify SDK by opening the browser if (!entry.isPlatform) { - const { platformUrl } = environments.resolve(entry.auth.env); + const { platformUrl } = environments.resolve(entry.auth.env, this.region); const url = `${platformUrl}/auth/signout?id_token_hint=${entry.auth.tokens.id_token}`; try { const { statusCode } = await this.got(url, { responseType: 'json', retry: 0 }); diff --git a/packages/amplify-sdk/src/authenticators/authenticator.js b/packages/amplify-sdk/src/authenticators/authenticator.js index 71060d05..bf134eda 100644 --- a/packages/amplify-sdk/src/authenticators/authenticator.js +++ b/packages/amplify-sdk/src/authenticators/authenticator.js @@ -96,6 +96,7 @@ export default class Authenticator { * endpoints are: `auth`, `certs`, `logout`, `token`, `userinfo`, and `wellKnown`. * @param {String} [opts.env=prod] - The environment name. Must be `staging` or `prod`. * The environment is a shorthand way of specifying a Axway default base URL. + * @param {String} [opts.region=us] - The region name. Must be `us` or `eu`. * @param {Boolean} [opts.persistSecrets] - When `true`, adds the authenticator params * (client secret, private key, username/password) to the authenticated account object so that * the access token can be refreshed when a refresh token is not available. @@ -113,7 +114,7 @@ export default class Authenticator { } // check the environment - this.env = environments.resolve(opts.env); + this.env = environments.resolve(opts.env, opts.region); // process the base URL if (opts.baseUrl) { diff --git a/packages/amplify-sdk/src/environments.js b/packages/amplify-sdk/src/environments.js index 6f21e8fb..aa0c958a 100644 --- a/packages/amplify-sdk/src/environments.js +++ b/packages/amplify-sdk/src/environments.js @@ -10,9 +10,16 @@ export const environments = { realm: 'Broker' }, prod: { - baseUrl: 'https://login.axway.com', - platformUrl: 'https://platform.axway.com', - realm: 'Broker' + us: { + baseUrl: 'https://login.axway.com', + platformUrl: 'https://platform.axway.com', + realm: 'Broker' + }, + eu: { + baseUrl: 'https://login.eu-fr.axway.com', + platformUrl: 'https://platform.eu-fr.axway.com', + realm: 'Broker' + }, } }; @@ -26,8 +33,9 @@ const mapping = { test: 'staging' }; -export function resolve(env) { +export function resolve(env, reg) { let environment = 'prod'; + let region = 'us'; if (env) { if (typeof env !== 'string') { throw new TypeError('Expected environment to be a string'); @@ -38,9 +46,18 @@ export function resolve(env) { throw new Error(`Invalid environment "${env}"`); } } + if (reg) { + if (typeof reg !== 'string') { + throw new TypeError('Expected region to be a string'); + } + region = reg.toLowerCase(); + if (!environments[environment][region]) { + throw new Error(`Invalid region "${reg}" for environment "${env}"`); + } + } return { name: environment, - ...environments[environment] + ...environments[environment][region] }; } diff --git a/packages/axway-cli-pm/src/pm.js b/packages/axway-cli-pm/src/pm.js index ed3478b4..3a187b49 100644 --- a/packages/axway-cli-pm/src/pm.js +++ b/packages/axway-cli-pm/src/pm.js @@ -104,7 +104,7 @@ export function install(pkgName) { emitter.emit('install', info); const args = [ 'install', - '--production', + '--omit=dev', '--force', // needed for npm 7 ...createNPMRequestArgs() ];