diff --git a/packages/amplify-cli-utils/src/index.js b/packages/amplify-cli-utils/src/index.js index 43ec50b1..4136caf9 100644 --- a/packages/amplify-cli-utils/src/index.js +++ b/packages/amplify-cli-utils/src/index.js @@ -52,6 +52,7 @@ export async function buildAuthParams(opts = {}, config) { } const env = environments.resolve(opts.env || await config.get('env')); + const region = opts.region || await config.get('region'); const { clientId, realm } = env.auth; const params = {}; @@ -66,6 +67,7 @@ export async 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 7551c654..1acfb8b5 100644 --- a/packages/amplify-sdk/src/amplify-sdk.js +++ b/packages/amplify-sdk/src/amplify-sdk.js @@ -30,6 +30,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 @@ -51,7 +52,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' ]) { @@ -406,7 +407,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 e701f9d0..6e44eaed 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 0f4830b4..0f7cabfc 100644 --- a/packages/amplify-sdk/src/authenticators/authenticator.js +++ b/packages/amplify-sdk/src/authenticators/authenticator.js @@ -101,6 +101,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. @@ -118,7 +119,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-auth/package.json b/packages/axway-cli-auth/package.json index 586a1c5a..11c01d64 100644 --- a/packages/axway-cli-auth/package.json +++ b/packages/axway-cli-auth/package.json @@ -25,7 +25,7 @@ "dependencies": { "@axway/amplify-cli-utils": "^6.0.5", "@axway/amplify-utils": "^2.0.5", - "cli-kit": "github:kasuvy/cli-kit#APIGOV-29723", + "cli-kit": "^2.1.1", "enquirer": "^2.3.6", "pretty-ms": "^7.0.1", "snooplogg": "^5.1.0", diff --git a/packages/axway-cli-pm/src/pm.js b/packages/axway-cli-pm/src/pm.js index c3ca4244..4d2dd8a8 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() ]; diff --git a/yarn.lock b/yarn.lock index 597e2546..52aa173f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3034,21 +3034,6 @@ cli-kit@^2.1.1: snooplogg "^5.0.0" which "^2.0.2" -"cli-kit@github:kasuvy/cli-kit#APIGOV-29723": - version "2.0.2" - resolved "https://codeload.github.com/kasuvy/cli-kit/tar.gz/908da5e9433b3044f34ceef4e02bd20e51569bc9" - dependencies: - argv-split "^2.0.1" - fastest-levenshtein "^1.0.12" - fs-extra "^10.1.0" - hook-emitter "^6.0.0" - lodash.camelcase "^4.3.0" - pkg-dir "^6.0.1" - pluralize "^8.0.0" - semver "^7.3.7" - snooplogg "^5.0.0" - which "^2.0.2" - cli-spinners@2.6.1, cli-spinners@^2.5.0: version "2.6.1" resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.6.1.tgz"