Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/amplify-cli-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -66,6 +67,7 @@ export async function buildAuthParams(opts = {}, config) {
persistSecrets: undefined,
platformUrl: undefined,
realm,
region: region,
secretFile: undefined,
serverHost: undefined,
serverPort: undefined,
Expand Down
5 changes: 3 additions & 2 deletions packages/amplify-sdk/src/amplify-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' ]) {
Expand Down Expand Up @@ -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') {
Expand Down
10 changes: 7 additions & 3 deletions packages/amplify-sdk/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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}`);
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 });
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-sdk/src/authenticators/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
27 changes: 22 additions & 5 deletions packages/amplify-sdk/src/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
}
};

Expand All @@ -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');
Expand All @@ -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]
};
}
2 changes: 1 addition & 1 deletion packages/axway-cli-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/axway-cli-pm/src/pm.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function install(pkgName) {
emitter.emit('install', info);
const args = [
'install',
'--production',
'--omit=dev',
'--force', // needed for npm 7
...createNPMRequestArgs()
];
Expand Down
15 changes: 0 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected], cli-spinners@^2.5.0:
version "2.6.1"
resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.6.1.tgz"
Expand Down
Loading