Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async resolveEnvironment(account: string | undefined, region: string | undefined, ) {
if (region === cxapi.UNKNOWN_REGION) {
region = await this.defaultRegion();
}
if (account === cxapi.UNKNOWN_ACCOUNT) {
account = await this.defaultAccount();
}
if (!region) {
throw new Error(`AWS region must be configured either when you configure your CDK stack or through the environment`);
}
if (!account) {
throw new Error(`Unable to resolve AWS account to use. It must be either configured when you define your CDK or through the environment`);
}
const environment: cxapi.Environment = {
region, account, name: cxapi.EnvironmentUtils.format(account, region)
};
return environment;
async function parseEnvironment(sdk: ISDK, env: cxapi.Environment): Promise {
const account = env.account === cxapi.UNKNOWN_ACCOUNT ? await sdk.defaultAccount() : env.account;
const region = env.region === cxapi.UNKNOWN_REGION ? await sdk.defaultRegion() : env.region;
if (!account || !region) {
throw new Error(`Unable to determine default account and/or region`);
}
return {
account, region,
name: cxapi.EnvironmentUtils.format(account, region)
};
}