@goldstack/infra-aws 0.3.26 → 0.3.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- import { AWSConfiguration, AWSUser, AWSRegion, AWSProfileConfig, AWSAPIKeyUserConfig, AWSAccessKeyId, AWSSecretAccessKey, AWSEnvironmentVariableUserConfig, Name } from './types/awsAccount';
2
- import AWS from 'aws-sdk';
3
- import { AWSTerraformState, RemoteState } from './types/awsTerraformState';
4
- export type { AWSConfiguration, AWSUser, AWSRegion, AWSAccessKeyId, AWSSecretAccessKey, AWSProfileConfig as AWSLocalUserConfig, AWSAPIKeyUserConfig as AWSAPIKeyUser, AWSEnvironmentVariableUserConfig, AWSTerraformState, RemoteState, };
5
- import { AWSDeployment } from './types/awsDeployment';
6
- export type { AWSDeployment, AWSDeploymentRegion, AWSUserName, } from './types/awsDeployment';
7
- export declare const readDeploymentFromPackageConfig: (deploymentName: string, path?: string | undefined) => AWSDeployment;
8
- export declare const assertTerraformConfig: (user: Name, path?: string | undefined) => AWSTerraformState;
9
- export declare const writeTerraformConfig: (config: AWSTerraformState, path?: string | undefined) => void;
10
- export declare const hasConfig: (path?: string | undefined) => boolean;
11
- export declare const readConfig: (path?: string | undefined) => AWSConfiguration;
12
- export declare const writeConfig: (config: AWSConfiguration, path?: string | undefined) => void;
13
- export declare const createDefaultConfig: () => AWSConfiguration;
14
- /**
15
- * Obtains AWS user credentials from config file or environment variables.
16
- **/
17
- export declare const getAWSUser: (userName: string, configPath?: string | undefined) => Promise<AWS.Credentials>;
1
+ import { AWSConfiguration, AWSUser, AWSRegion, AWSProfileConfig, AWSAPIKeyUserConfig, AWSAccessKeyId, AWSSecretAccessKey, AWSEnvironmentVariableUserConfig, Name } from './types/awsAccount';
2
+ import AWS from 'aws-sdk';
3
+ import { AWSTerraformState, RemoteState } from './types/awsTerraformState';
4
+ export type { AWSConfiguration, AWSUser, AWSRegion, AWSAccessKeyId, AWSSecretAccessKey, AWSProfileConfig as AWSLocalUserConfig, AWSAPIKeyUserConfig as AWSAPIKeyUser, AWSEnvironmentVariableUserConfig, AWSTerraformState, RemoteState, };
5
+ import { AWSDeployment } from './types/awsDeployment';
6
+ export type { AWSDeployment, AWSDeploymentRegion, AWSUserName, } from './types/awsDeployment';
7
+ export declare const readDeploymentFromPackageConfig: (deploymentName: string, path?: string | undefined) => AWSDeployment;
8
+ export declare const assertTerraformConfig: (user: Name, path?: string | undefined) => AWSTerraformState;
9
+ export declare const writeTerraformConfig: (config: AWSTerraformState, path?: string | undefined) => void;
10
+ export declare const hasConfig: (path?: string | undefined) => boolean;
11
+ export declare const readConfig: (path?: string | undefined) => AWSConfiguration;
12
+ export declare const writeConfig: (config: AWSConfiguration, path?: string | undefined) => void;
13
+ export declare const createDefaultConfig: () => AWSConfiguration;
14
+ /**
15
+ * Obtains AWS user credentials from config file or environment variables.
16
+ **/
17
+ export declare const getAWSUser: (userName: string, configPath?: string | undefined) => Promise<AWS.Credentials>;
18
18
  //# sourceMappingURL=infraAws.d.ts.map
@@ -1,192 +1,192 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getAWSUser = exports.createDefaultConfig = exports.writeConfig = exports.readConfig = exports.hasConfig = exports.writeTerraformConfig = exports.assertTerraformConfig = exports.readDeploymentFromPackageConfig = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const assert_1 = __importDefault(require("assert"));
9
- const utils_config_1 = require("@goldstack/utils-config");
10
- const utils_package_1 = require("@goldstack/utils-package");
11
- const utils_sh_1 = require("@goldstack/utils-sh");
12
- const accountConfigSchema_json_1 = __importDefault(require("./schemas/accountConfigSchema.json"));
13
- const deploymentConfigSchema_json_1 = __importDefault(require("./schemas/deploymentConfigSchema.json"));
14
- const awsTerraformStateSchema_json_1 = __importDefault(require("./schemas/awsTerraformStateSchema.json"));
15
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
16
- const readDeploymentFromPackageConfig = (deploymentName, path) => {
17
- const packageConfig = (0, utils_package_1.readPackageConfig)(path);
18
- const deployment = packageConfig.deployments.find((d) => d.name === deploymentName);
19
- if (!deployment) {
20
- throw new Error('Cannot find deployment with name: ' + deploymentName);
21
- }
22
- (0, utils_config_1.validateConfig)(deployment, deploymentConfigSchema_json_1.default, {
23
- errorMessage: `Invalid AWS deployment ${deploymentName}`,
24
- });
25
- return deployment;
26
- };
27
- exports.readDeploymentFromPackageConfig = readDeploymentFromPackageConfig;
28
- const assertTerraformConfig = (user, path) => {
29
- if (!path) {
30
- path = (0, utils_config_1.getAwsTerraformConfigPath)('./../../');
31
- }
32
- let res;
33
- if (fs_1.default.existsSync(path)) {
34
- res = (0, utils_config_1.parseConfig)((0, utils_sh_1.read)(path), awsTerraformStateSchema_json_1.default, {
35
- errorMessage: `Cannot load AWS Terraform configuration from ${path}`,
36
- });
37
- }
38
- else {
39
- res = {
40
- remoteState: [],
41
- };
42
- }
43
- if (!res.remoteState.find((el) => el.user == user)) {
44
- res.remoteState.push({
45
- user: user,
46
- });
47
- }
48
- return res;
49
- };
50
- exports.assertTerraformConfig = assertTerraformConfig;
51
- const writeTerraformConfig = (config, path) => {
52
- if (!path) {
53
- path = (0, utils_config_1.getAwsTerraformConfigPath)('./../../');
54
- }
55
- (0, utils_sh_1.write)(JSON.stringify(config, null, 2), path);
56
- };
57
- exports.writeTerraformConfig = writeTerraformConfig;
58
- const hasConfig = (path) => {
59
- if (!path) {
60
- path = (0, utils_config_1.getAwsConfigPath)('./../../');
61
- }
62
- // otherwise check default config file location
63
- return fs_1.default.existsSync(path);
64
- };
65
- exports.hasConfig = hasConfig;
66
- const readConfig = (path) => {
67
- if (!path) {
68
- path = (0, utils_config_1.getAwsConfigPath)('./../../');
69
- }
70
- // otherwise check default config file location
71
- if (!fs_1.default.existsSync(path)) {
72
- throw new Error(`AWS configuration file does not exist: ${path}.`);
73
- }
74
- return (0, utils_config_1.parseConfig)((0, utils_sh_1.read)(path), accountConfigSchema_json_1.default, {
75
- errorMessage: `Cannot load AWS configuration from ${path}`,
76
- });
77
- };
78
- exports.readConfig = readConfig;
79
- const writeConfig = (config, path) => {
80
- if (!path) {
81
- path = (0, utils_config_1.getAwsConfigPath)('./../../');
82
- }
83
- (0, utils_sh_1.write)(JSON.stringify(config, null, 2), path);
84
- };
85
- exports.writeConfig = writeConfig;
86
- const createDefaultConfig = () => {
87
- return {
88
- users: [],
89
- };
90
- };
91
- exports.createDefaultConfig = createDefaultConfig;
92
- /**
93
- * Obtains AWS user credentials from config file or environment variables.
94
- **/
95
- const getAWSUser = async (userName, configPath) => {
96
- // check if running in ECS
97
- if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
98
- const ecsCredentials = new aws_sdk_1.default.ECSCredentials({
99
- httpOptions: { timeout: 5000 },
100
- maxRetries: 10, // retry 10 times
101
- });
102
- await ecsCredentials.getPromise();
103
- aws_sdk_1.default.config.credentials = ecsCredentials;
104
- if (!process.env.AWS_REGION) {
105
- throw new Error('AWS region environment variable ("AWS_REGION") not defined for ECS task.');
106
- }
107
- aws_sdk_1.default.config.update({ region: process.env.AWS_REGION });
108
- return ecsCredentials;
109
- }
110
- // always prefer gettting credentials from environment variables
111
- if (process.env.AWS_ACCESS_KEY_ID) {
112
- (0, assert_1.default)(process.env.AWS_ACCESS_KEY_ID, 'AWS_ACCESS_KEY_ID not defined.');
113
- (0, assert_1.default)(process.env.AWS_SECRET_ACCESS_KEY, 'AWS_SECRET_ACCESS_KEY not defined');
114
- const region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION;
115
- (0, assert_1.default)(region, 'Neither AWS_REGION nor AWS_DEFAULT_REGION are defined.');
116
- const credentials = new aws_sdk_1.default.EnvironmentCredentials('AWS');
117
- await credentials.getPromise();
118
- aws_sdk_1.default.config.credentials = credentials;
119
- aws_sdk_1.default.config.update({ region });
120
- return credentials;
121
- }
122
- // try loading default user if no config file provided
123
- if (!(0, exports.hasConfig)(configPath)) {
124
- const credentials = new aws_sdk_1.default.SharedIniFileCredentials();
125
- if (!credentials.accessKeyId) {
126
- throw new Error('Cannot load user from AWS configuration. Please provide a Goldstack AWS Configuration in infra/aws/config.json or perform aws login for a default profile using the AWS CLI.');
127
- }
128
- aws_sdk_1.default.config.credentials = credentials;
129
- // see https://github.com/aws/aws-sdk-js/pull/1391
130
- process.env.AWS_SDK_LOAD_CONFIG = 'true';
131
- return credentials;
132
- }
133
- const config = (0, exports.readConfig)(configPath);
134
- const user = config.users.find((user) => user.name === userName);
135
- if (!user) {
136
- throw new Error(`User '${userName}' does not exist in AWS configuration.`);
137
- }
138
- if (user.type === 'apiKey') {
139
- const config = user.config;
140
- if (!config.awsAccessKeyId || !config.awsSecretAccessKey) {
141
- throw new Error(`AWS Access credentials not defined for user ${userName}. Define them in infra/aws/config.json.`);
142
- }
143
- const credentials = new aws_sdk_1.default.Credentials({
144
- accessKeyId: config.awsAccessKeyId || '',
145
- secretAccessKey: config.awsSecretAccessKey || '',
146
- });
147
- aws_sdk_1.default.config.credentials = credentials;
148
- aws_sdk_1.default.config.update({ region: config.awsDefaultRegion });
149
- return credentials;
150
- }
151
- if (user.type === 'environmentVariables') {
152
- const userConfig = user.config;
153
- const awsAccessKeyId = process.env[userConfig.awsAccessKeyIdVariableName];
154
- if (!awsAccessKeyId) {
155
- throw new Error(`Environment variable expected but not found: ${userConfig.awsAccessKeyIdVariableName}`);
156
- }
157
- const awsSecretAccessKey = process.env[userConfig.awsSecretAccessKeyVariableName];
158
- if (!awsSecretAccessKey) {
159
- throw new Error(`Environment variable expected but not found: ${userConfig.awsSecretAccessKeyVariableName}`);
160
- }
161
- const awsDefaultRegion = process.env[userConfig.awsDefaultRegionVariableName];
162
- if (!awsDefaultRegion) {
163
- throw new Error(`Environment variable expected but not found: ${userConfig.awsDefaultRegionVariableName}`);
164
- }
165
- const credentials = new aws_sdk_1.default.Credentials({
166
- accessKeyId: awsAccessKeyId,
167
- secretAccessKey: awsSecretAccessKey,
168
- });
169
- aws_sdk_1.default.config.credentials = credentials;
170
- aws_sdk_1.default.config.update({ region: awsDefaultRegion });
171
- return credentials;
172
- }
173
- if (user.type === 'profile') {
174
- const userConfig = user.config;
175
- const credentials = new aws_sdk_1.default.SharedIniFileCredentials({
176
- profile: userConfig.profile,
177
- });
178
- if (!credentials.accessKeyId) {
179
- throw new Error('Cannot load profile ' +
180
- userConfig.profile +
181
- ' from AWS configuration for user ' +
182
- user.name +
183
- '. Please perform `aws login` for the profile using the AWS CLI.');
184
- }
185
- aws_sdk_1.default.config.credentials = credentials;
186
- aws_sdk_1.default.config.update({ region: userConfig.awsDefaultRegion });
187
- return credentials;
188
- }
189
- throw new Error(`Unknown user config type ${user.type}`);
190
- };
191
- exports.getAWSUser = getAWSUser;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getAWSUser = exports.createDefaultConfig = exports.writeConfig = exports.readConfig = exports.hasConfig = exports.writeTerraformConfig = exports.assertTerraformConfig = exports.readDeploymentFromPackageConfig = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const assert_1 = __importDefault(require("assert"));
9
+ const utils_config_1 = require("@goldstack/utils-config");
10
+ const utils_package_1 = require("@goldstack/utils-package");
11
+ const utils_sh_1 = require("@goldstack/utils-sh");
12
+ const accountConfigSchema_json_1 = __importDefault(require("./schemas/accountConfigSchema.json"));
13
+ const deploymentConfigSchema_json_1 = __importDefault(require("./schemas/deploymentConfigSchema.json"));
14
+ const awsTerraformStateSchema_json_1 = __importDefault(require("./schemas/awsTerraformStateSchema.json"));
15
+ const aws_sdk_1 = __importDefault(require("aws-sdk"));
16
+ const readDeploymentFromPackageConfig = (deploymentName, path) => {
17
+ const packageConfig = (0, utils_package_1.readPackageConfig)(path);
18
+ const deployment = packageConfig.deployments.find((d) => d.name === deploymentName);
19
+ if (!deployment) {
20
+ throw new Error('Cannot find deployment with name: ' + deploymentName);
21
+ }
22
+ (0, utils_config_1.validateConfig)(deployment, deploymentConfigSchema_json_1.default, {
23
+ errorMessage: `Invalid AWS deployment ${deploymentName}`,
24
+ });
25
+ return deployment;
26
+ };
27
+ exports.readDeploymentFromPackageConfig = readDeploymentFromPackageConfig;
28
+ const assertTerraformConfig = (user, path) => {
29
+ if (!path) {
30
+ path = (0, utils_config_1.getAwsTerraformConfigPath)('./../../');
31
+ }
32
+ let res;
33
+ if (fs_1.default.existsSync(path)) {
34
+ res = (0, utils_config_1.parseConfig)((0, utils_sh_1.read)(path), awsTerraformStateSchema_json_1.default, {
35
+ errorMessage: `Cannot load AWS Terraform configuration from ${path}`,
36
+ });
37
+ }
38
+ else {
39
+ res = {
40
+ remoteState: [],
41
+ };
42
+ }
43
+ if (!res.remoteState.find((el) => el.user == user)) {
44
+ res.remoteState.push({
45
+ user: user,
46
+ });
47
+ }
48
+ return res;
49
+ };
50
+ exports.assertTerraformConfig = assertTerraformConfig;
51
+ const writeTerraformConfig = (config, path) => {
52
+ if (!path) {
53
+ path = (0, utils_config_1.getAwsTerraformConfigPath)('./../../');
54
+ }
55
+ (0, utils_sh_1.write)(JSON.stringify(config, null, 2), path);
56
+ };
57
+ exports.writeTerraformConfig = writeTerraformConfig;
58
+ const hasConfig = (path) => {
59
+ if (!path) {
60
+ path = (0, utils_config_1.getAwsConfigPath)('./../../');
61
+ }
62
+ // otherwise check default config file location
63
+ return fs_1.default.existsSync(path);
64
+ };
65
+ exports.hasConfig = hasConfig;
66
+ const readConfig = (path) => {
67
+ if (!path) {
68
+ path = (0, utils_config_1.getAwsConfigPath)('./../../');
69
+ }
70
+ // otherwise check default config file location
71
+ if (!fs_1.default.existsSync(path)) {
72
+ throw new Error(`AWS configuration file does not exist: ${path}.`);
73
+ }
74
+ return (0, utils_config_1.parseConfig)((0, utils_sh_1.read)(path), accountConfigSchema_json_1.default, {
75
+ errorMessage: `Cannot load AWS configuration from ${path}`,
76
+ });
77
+ };
78
+ exports.readConfig = readConfig;
79
+ const writeConfig = (config, path) => {
80
+ if (!path) {
81
+ path = (0, utils_config_1.getAwsConfigPath)('./../../');
82
+ }
83
+ (0, utils_sh_1.write)(JSON.stringify(config, null, 2), path);
84
+ };
85
+ exports.writeConfig = writeConfig;
86
+ const createDefaultConfig = () => {
87
+ return {
88
+ users: [],
89
+ };
90
+ };
91
+ exports.createDefaultConfig = createDefaultConfig;
92
+ /**
93
+ * Obtains AWS user credentials from config file or environment variables.
94
+ **/
95
+ const getAWSUser = async (userName, configPath) => {
96
+ // check if running in ECS
97
+ if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
98
+ const ecsCredentials = new aws_sdk_1.default.ECSCredentials({
99
+ httpOptions: { timeout: 5000 },
100
+ maxRetries: 10, // retry 10 times
101
+ });
102
+ await ecsCredentials.getPromise();
103
+ aws_sdk_1.default.config.credentials = ecsCredentials;
104
+ if (!process.env.AWS_REGION) {
105
+ throw new Error('AWS region environment variable ("AWS_REGION") not defined for ECS task.');
106
+ }
107
+ aws_sdk_1.default.config.update({ region: process.env.AWS_REGION });
108
+ return ecsCredentials;
109
+ }
110
+ // always prefer gettting credentials from environment variables
111
+ if (process.env.AWS_ACCESS_KEY_ID) {
112
+ (0, assert_1.default)(process.env.AWS_ACCESS_KEY_ID, 'AWS_ACCESS_KEY_ID not defined.');
113
+ (0, assert_1.default)(process.env.AWS_SECRET_ACCESS_KEY, 'AWS_SECRET_ACCESS_KEY not defined');
114
+ const region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION;
115
+ (0, assert_1.default)(region, 'Neither AWS_REGION nor AWS_DEFAULT_REGION are defined.');
116
+ const credentials = new aws_sdk_1.default.EnvironmentCredentials('AWS');
117
+ await credentials.getPromise();
118
+ aws_sdk_1.default.config.credentials = credentials;
119
+ aws_sdk_1.default.config.update({ region });
120
+ return credentials;
121
+ }
122
+ // try loading default user if no config file provided
123
+ if (!(0, exports.hasConfig)(configPath)) {
124
+ const credentials = new aws_sdk_1.default.SharedIniFileCredentials();
125
+ if (!credentials.accessKeyId) {
126
+ throw new Error('Cannot load user from AWS configuration. Please provide a Goldstack AWS Configuration in infra/aws/config.json or perform aws login for a default profile using the AWS CLI.');
127
+ }
128
+ aws_sdk_1.default.config.credentials = credentials;
129
+ // see https://github.com/aws/aws-sdk-js/pull/1391
130
+ process.env.AWS_SDK_LOAD_CONFIG = 'true';
131
+ return credentials;
132
+ }
133
+ const config = (0, exports.readConfig)(configPath);
134
+ const user = config.users.find((user) => user.name === userName);
135
+ if (!user) {
136
+ throw new Error(`User '${userName}' does not exist in AWS configuration.`);
137
+ }
138
+ if (user.type === 'apiKey') {
139
+ const config = user.config;
140
+ if (!config.awsAccessKeyId || !config.awsSecretAccessKey) {
141
+ throw new Error(`AWS Access credentials not defined for user ${userName}. Define them in infra/aws/config.json.`);
142
+ }
143
+ const credentials = new aws_sdk_1.default.Credentials({
144
+ accessKeyId: config.awsAccessKeyId || '',
145
+ secretAccessKey: config.awsSecretAccessKey || '',
146
+ });
147
+ aws_sdk_1.default.config.credentials = credentials;
148
+ aws_sdk_1.default.config.update({ region: config.awsDefaultRegion });
149
+ return credentials;
150
+ }
151
+ if (user.type === 'environmentVariables') {
152
+ const userConfig = user.config;
153
+ const awsAccessKeyId = process.env[userConfig.awsAccessKeyIdVariableName];
154
+ if (!awsAccessKeyId) {
155
+ throw new Error(`Environment variable expected but not found: ${userConfig.awsAccessKeyIdVariableName}`);
156
+ }
157
+ const awsSecretAccessKey = process.env[userConfig.awsSecretAccessKeyVariableName];
158
+ if (!awsSecretAccessKey) {
159
+ throw new Error(`Environment variable expected but not found: ${userConfig.awsSecretAccessKeyVariableName}`);
160
+ }
161
+ const awsDefaultRegion = process.env[userConfig.awsDefaultRegionVariableName];
162
+ if (!awsDefaultRegion) {
163
+ throw new Error(`Environment variable expected but not found: ${userConfig.awsDefaultRegionVariableName}`);
164
+ }
165
+ const credentials = new aws_sdk_1.default.Credentials({
166
+ accessKeyId: awsAccessKeyId,
167
+ secretAccessKey: awsSecretAccessKey,
168
+ });
169
+ aws_sdk_1.default.config.credentials = credentials;
170
+ aws_sdk_1.default.config.update({ region: awsDefaultRegion });
171
+ return credentials;
172
+ }
173
+ if (user.type === 'profile') {
174
+ const userConfig = user.config;
175
+ const credentials = new aws_sdk_1.default.SharedIniFileCredentials({
176
+ profile: userConfig.profile,
177
+ });
178
+ if (!credentials.accessKeyId) {
179
+ throw new Error('Cannot load profile ' +
180
+ userConfig.profile +
181
+ ' from AWS configuration for user ' +
182
+ user.name +
183
+ '. Please perform `aws login` for the profile using the AWS CLI.');
184
+ }
185
+ aws_sdk_1.default.config.credentials = credentials;
186
+ aws_sdk_1.default.config.update({ region: userConfig.awsDefaultRegion });
187
+ return credentials;
188
+ }
189
+ throw new Error(`Unknown user config type ${user.type}`);
190
+ };
191
+ exports.getAWSUser = getAWSUser;
192
192
  //# sourceMappingURL=infraAws.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=infraAws.spec.d.ts.map
@@ -1,13 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const infraAws_1 = require("./infraAws");
7
- const utils_sh_1 = require("@goldstack/utils-sh");
8
- const assert_1 = __importDefault(require("assert"));
9
- describe('AWS User config', () => {
10
- it('Should read AWS config from Goldstack config file', async () => {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const infraAws_1 = require("./infraAws");
7
+ const utils_sh_1 = require("@goldstack/utils-sh");
8
+ const assert_1 = __importDefault(require("assert"));
9
+ describe('AWS User config', () => {
10
+ it('Should read AWS config from Goldstack config file', async () => {
11
11
  const awsConfig = `{
12
12
  "users": [
13
13
  {
@@ -29,23 +29,23 @@ describe('AWS User config', () => {
29
29
  }
30
30
  }
31
31
  ]
32
- }`;
33
- const testDir = './goldstackLocal/tests/getAWSUser';
34
- (0, utils_sh_1.mkdir)('-p', testDir);
35
- (0, utils_sh_1.write)(awsConfig, testDir + '/config-embedded.json');
36
- const credentialsDev = await (0, infraAws_1.getAWSUser)('goldstack-dev', testDir + '/config-embedded.json');
37
- (0, assert_1.default)(credentialsDev.accessKeyId === 'dummy');
38
- const credentialsProd = await (0, infraAws_1.getAWSUser)('goldstack-prod', testDir + '/config-embedded.json');
39
- (0, assert_1.default)(credentialsProd.accessKeyId === 'dummy-prod');
40
- });
41
- // problems when initialising AWS config more than once, so leaving this as one test for now
42
- // following difficult to test
43
- it.skip('Should read from AWS config in user folder if no config provided', async () => {
44
- const credentials = await (0, infraAws_1.getAWSUser)('default', './invalid');
45
- (0, assert_1.default)(credentials.accessKeyId);
46
- });
47
- it.skip('Should read from AWS config in user folder if credentials config provided', async () => {
48
- const testDir = './goldstackLocal/tests/getAWSUser';
32
+ }`;
33
+ const testDir = './goldstackLocal/tests/getAWSUser';
34
+ (0, utils_sh_1.mkdir)('-p', testDir);
35
+ (0, utils_sh_1.write)(awsConfig, testDir + '/config-embedded.json');
36
+ const credentialsDev = await (0, infraAws_1.getAWSUser)('goldstack-dev', testDir + '/config-embedded.json');
37
+ (0, assert_1.default)(credentialsDev.accessKeyId === 'dummy');
38
+ const credentialsProd = await (0, infraAws_1.getAWSUser)('goldstack-prod', testDir + '/config-embedded.json');
39
+ (0, assert_1.default)(credentialsProd.accessKeyId === 'dummy-prod');
40
+ });
41
+ // problems when initialising AWS config more than once, so leaving this as one test for now
42
+ // following difficult to test
43
+ it.skip('Should read from AWS config in user folder if no config provided', async () => {
44
+ const credentials = await (0, infraAws_1.getAWSUser)('default', './invalid');
45
+ (0, assert_1.default)(credentials.accessKeyId);
46
+ });
47
+ it.skip('Should read from AWS config in user folder if credentials config provided', async () => {
48
+ const testDir = './goldstackLocal/tests/getAWSUser';
49
49
  const awsConfig = `{
50
50
  "users": [
51
51
  {
@@ -65,11 +65,11 @@ describe('AWS User config', () => {
65
65
  }
66
66
  }
67
67
  ]
68
- }`;
69
- (0, utils_sh_1.mkdir)('-p', testDir);
70
- (0, utils_sh_1.write)(awsConfig, testDir + '/config.json');
71
- const credentialsDefault = await (0, infraAws_1.getAWSUser)('dev', testDir + '/config.json');
72
- (0, assert_1.default)(credentialsDefault.accessKeyId);
73
- });
74
- });
68
+ }`;
69
+ (0, utils_sh_1.mkdir)('-p', testDir);
70
+ (0, utils_sh_1.write)(awsConfig, testDir + '/config.json');
71
+ const credentialsDefault = await (0, infraAws_1.getAWSUser)('dev', testDir + '/config.json');
72
+ (0, assert_1.default)(credentialsDefault.accessKeyId);
73
+ });
74
+ });
75
75
  //# sourceMappingURL=infraAws.spec.js.map