@gradientedge/cdk-utils-aws 2.6.0 → 2.8.0
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.
- package/dist/src/common/stack.d.ts +14 -0
- package/dist/src/common/stack.js +74 -1
- package/package.json +5 -5
|
@@ -59,12 +59,26 @@ export declare class CommonStack extends Stack {
|
|
|
59
59
|
* - Primary use is to have layered config in separate files to enable easier maintenance and readability
|
|
60
60
|
*/
|
|
61
61
|
protected determineExtraContexts(): void;
|
|
62
|
+
/**
|
|
63
|
+
* @summary Method to determine region cdk contexts apart from the main cdk.json
|
|
64
|
+
* - Region is resolved from `region` CDK context
|
|
65
|
+
* - Loads `{regionContextPath}/{region}.json` if present
|
|
66
|
+
* - Primary use is to have layered config for each region in separate files
|
|
67
|
+
*/
|
|
68
|
+
protected determineRegionContexts(): void;
|
|
62
69
|
/**
|
|
63
70
|
* @summary Method to determine extra cdk stage contexts apart from the main cdk.json
|
|
64
71
|
* - Sets the properties from the extra stage contexts into cdk node context
|
|
65
72
|
* - Primary use is to have layered config for each environment which is injected into the context
|
|
66
73
|
*/
|
|
67
74
|
protected determineStageContexts(): void;
|
|
75
|
+
/**
|
|
76
|
+
* @summary Method to determine stage-region cdk contexts for environment and region-specific overrides
|
|
77
|
+
* - Loads `{stageRegionContextPath}/{stage}.{region}.json` if present
|
|
78
|
+
* - Has the highest priority in the configuration hierarchy
|
|
79
|
+
* - Primary use is to override config for a specific stage+region combination (e.g., prd.eu-west-1.json)
|
|
80
|
+
*/
|
|
81
|
+
protected determineStageRegionContexts(): void;
|
|
68
82
|
/**
|
|
69
83
|
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
70
84
|
*/
|
package/dist/src/common/stack.js
CHANGED
|
@@ -36,8 +36,12 @@ export class CommonStack extends Stack {
|
|
|
36
36
|
super(parent, name, props);
|
|
37
37
|
/* determine extra cdk contexts */
|
|
38
38
|
this.determineExtraContexts();
|
|
39
|
+
/* determine region cdk contexts */
|
|
40
|
+
this.determineRegionContexts();
|
|
39
41
|
/* determine extra cdk stage contexts */
|
|
40
42
|
this.determineStageContexts();
|
|
43
|
+
/* determine stage-region cdk contexts */
|
|
44
|
+
this.determineStageRegionContexts();
|
|
41
45
|
this.props = this.determineConstructProps(props);
|
|
42
46
|
/* initialise the construct */
|
|
43
47
|
this.construct = new CommonConstruct(this, 'cdk-utils', this.props);
|
|
@@ -98,6 +102,41 @@ export class CommonStack extends Stack {
|
|
|
98
102
|
});
|
|
99
103
|
});
|
|
100
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* @summary Method to determine region cdk contexts apart from the main cdk.json
|
|
107
|
+
* - Region is resolved from `region` CDK context
|
|
108
|
+
* - Loads `{regionContextPath}/{region}.json` if present
|
|
109
|
+
* - Primary use is to have layered config for each region in separate files
|
|
110
|
+
*/
|
|
111
|
+
determineRegionContexts() {
|
|
112
|
+
const region = this.node.tryGetContext('region');
|
|
113
|
+
const regionContextPath = this.node.tryGetContext('regionContextPath');
|
|
114
|
+
const debug = this.node.tryGetContext('debug');
|
|
115
|
+
if (!region || !regionContextPath) {
|
|
116
|
+
if (debug)
|
|
117
|
+
console.debug(`No region context provided. Using default context properties from cdk.json`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const regionContextFilePath = path.join(appRoot.path, regionContextPath, `${region}.json`);
|
|
121
|
+
/* alert default context usage when region config is missing */
|
|
122
|
+
if (!fs.existsSync(regionContextFilePath)) {
|
|
123
|
+
if (debug)
|
|
124
|
+
console.debug(`Region context properties unavailable in path:${regionContextFilePath}`);
|
|
125
|
+
if (debug)
|
|
126
|
+
console.debug(`Using default context properties for ${region} region`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
/* read the region properties */
|
|
130
|
+
const regionContextPropsBuffer = fs.readFileSync(regionContextFilePath);
|
|
131
|
+
if (debug)
|
|
132
|
+
console.debug(`Adding region contexts provided in ${regionContextFilePath}`);
|
|
133
|
+
/* parse as JSON properties */
|
|
134
|
+
const regionContextProps = JSON.parse(regionContextPropsBuffer.toString('utf-8'));
|
|
135
|
+
/* set each of the property into the cdk node context */
|
|
136
|
+
_.keys(regionContextProps).forEach((propKey) => {
|
|
137
|
+
this.node.setContext(propKey, regionContextProps[propKey]);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
101
140
|
/**
|
|
102
141
|
* @summary Method to determine extra cdk stage contexts apart from the main cdk.json
|
|
103
142
|
* - Sets the properties from the extra stage contexts into cdk node context
|
|
@@ -105,7 +144,7 @@ export class CommonStack extends Stack {
|
|
|
105
144
|
*/
|
|
106
145
|
determineStageContexts() {
|
|
107
146
|
const stage = this.node.tryGetContext('stage');
|
|
108
|
-
const stageContextPath = this.node.tryGetContext('stageContextPath') || '
|
|
147
|
+
const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdk-env';
|
|
109
148
|
const stageContextFilePath = path.join(appRoot.path, stageContextPath, `${stage}.json`);
|
|
110
149
|
const debug = this.node.tryGetContext('debug');
|
|
111
150
|
if (isDevStage(stage)) {
|
|
@@ -138,6 +177,40 @@ export class CommonStack extends Stack {
|
|
|
138
177
|
}
|
|
139
178
|
});
|
|
140
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* @summary Method to determine stage-region cdk contexts for environment and region-specific overrides
|
|
182
|
+
* - Loads `{stageRegionContextPath}/{stage}.{region}.json` if present
|
|
183
|
+
* - Has the highest priority in the configuration hierarchy
|
|
184
|
+
* - Primary use is to override config for a specific stage+region combination (e.g., prd.eu-west-1.json)
|
|
185
|
+
*/
|
|
186
|
+
determineStageRegionContexts() {
|
|
187
|
+
const stage = this.node.tryGetContext('stage');
|
|
188
|
+
const region = this.node.tryGetContext('region');
|
|
189
|
+
const stageRegionContextPath = this.node.tryGetContext('stageRegionContextPath');
|
|
190
|
+
const debug = this.node.tryGetContext('debug');
|
|
191
|
+
if (!stage || !region || !stageRegionContextPath) {
|
|
192
|
+
if (debug)
|
|
193
|
+
console.debug(`No stage-region context provided. Using default context properties from cdk.json`);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const stageRegionContextFilePath = path.join(appRoot.path, stageRegionContextPath, `${stage}.${region}.json`);
|
|
197
|
+
/* gracefully skip when stage-region config is missing */
|
|
198
|
+
if (!fs.existsSync(stageRegionContextFilePath)) {
|
|
199
|
+
if (debug)
|
|
200
|
+
console.debug(`Stage-region context properties unavailable in path:${stageRegionContextFilePath}`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
/* read the stage-region properties */
|
|
204
|
+
const stageRegionContextPropsBuffer = fs.readFileSync(stageRegionContextFilePath);
|
|
205
|
+
if (debug)
|
|
206
|
+
console.debug(`Adding stage-region contexts provided in ${stageRegionContextFilePath}`);
|
|
207
|
+
/* parse as JSON properties */
|
|
208
|
+
const stageRegionContextProps = JSON.parse(stageRegionContextPropsBuffer.toString('utf-8'));
|
|
209
|
+
/* set each of the property into the cdk node context */
|
|
210
|
+
_.keys(stageRegionContextProps).forEach((propKey) => {
|
|
211
|
+
this.node.setContext(propKey, stageRegionContextProps[propKey]);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
141
214
|
/**
|
|
142
215
|
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
143
216
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils-aws",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "AWS CDK utilities for @gradientedge/cdk-utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
"dist/src/"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@aws-sdk/client-secrets-manager": "3.
|
|
18
|
-
"@aws-sdk/credential-providers": "3.
|
|
17
|
+
"@aws-sdk/client-secrets-manager": "3.1048.0",
|
|
18
|
+
"@aws-sdk/credential-providers": "3.1048.0",
|
|
19
19
|
"@aws-sdk/types": "3.973.8",
|
|
20
20
|
"@types/lodash": "4.17.24",
|
|
21
21
|
"app-root-path": "3.1.0",
|
|
22
|
-
"aws-cdk-lib": "2.
|
|
22
|
+
"aws-cdk-lib": "2.254.0",
|
|
23
23
|
"lodash": "4.18.1",
|
|
24
24
|
"constructs": "10.6.0",
|
|
25
25
|
"moment": "2.30.1",
|
|
26
26
|
"uuid": "14.0.0",
|
|
27
|
-
"@gradientedge/cdk-utils-common": "2.
|
|
27
|
+
"@gradientedge/cdk-utils-common": "2.4.0"
|
|
28
28
|
},
|
|
29
29
|
"keywords": [
|
|
30
30
|
"gradientedge",
|