@gradientedge/cdk-utils-aws 2.7.0 → 2.9.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 +90 -2
- package/package.json +2 -2
|
@@ -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);
|
|
@@ -94,10 +98,55 @@ export class CommonStack extends Stack {
|
|
|
94
98
|
const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'));
|
|
95
99
|
/* set each of the property into the cdk node context */
|
|
96
100
|
_.keys(extraContextProps).forEach((propKey) => {
|
|
97
|
-
|
|
101
|
+
if (typeof extraContextProps[propKey] === 'object' && !Array.isArray(extraContextProps[propKey])) {
|
|
102
|
+
this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), extraContextProps[propKey]));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this.node.setContext(propKey, extraContextProps[propKey]);
|
|
106
|
+
}
|
|
98
107
|
});
|
|
99
108
|
});
|
|
100
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* @summary Method to determine region cdk contexts apart from the main cdk.json
|
|
112
|
+
* - Region is resolved from `region` CDK context
|
|
113
|
+
* - Loads `{regionContextPath}/{region}.json` if present
|
|
114
|
+
* - Primary use is to have layered config for each region in separate files
|
|
115
|
+
*/
|
|
116
|
+
determineRegionContexts() {
|
|
117
|
+
const region = this.node.tryGetContext('region');
|
|
118
|
+
const regionContextPath = this.node.tryGetContext('regionContextPath');
|
|
119
|
+
const debug = this.node.tryGetContext('debug');
|
|
120
|
+
if (!region || !regionContextPath) {
|
|
121
|
+
if (debug)
|
|
122
|
+
console.debug(`No region context provided. Using default context properties from cdk.json`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const regionContextFilePath = path.join(appRoot.path, regionContextPath, `${region}.json`);
|
|
126
|
+
/* alert default context usage when region config is missing */
|
|
127
|
+
if (!fs.existsSync(regionContextFilePath)) {
|
|
128
|
+
if (debug)
|
|
129
|
+
console.debug(`Region context properties unavailable in path:${regionContextFilePath}`);
|
|
130
|
+
if (debug)
|
|
131
|
+
console.debug(`Using default context properties for ${region} region`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
/* read the region properties */
|
|
135
|
+
const regionContextPropsBuffer = fs.readFileSync(regionContextFilePath);
|
|
136
|
+
if (debug)
|
|
137
|
+
console.debug(`Adding region contexts provided in ${regionContextFilePath}`);
|
|
138
|
+
/* parse as JSON properties */
|
|
139
|
+
const regionContextProps = JSON.parse(regionContextPropsBuffer.toString('utf-8'));
|
|
140
|
+
/* set each of the property into the cdk node context */
|
|
141
|
+
_.keys(regionContextProps).forEach((propKey) => {
|
|
142
|
+
if (typeof regionContextProps[propKey] === 'object' && !Array.isArray(regionContextProps[propKey])) {
|
|
143
|
+
this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), regionContextProps[propKey]));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.node.setContext(propKey, regionContextProps[propKey]);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
101
150
|
/**
|
|
102
151
|
* @summary Method to determine extra cdk stage contexts apart from the main cdk.json
|
|
103
152
|
* - Sets the properties from the extra stage contexts into cdk node context
|
|
@@ -105,7 +154,7 @@ export class CommonStack extends Stack {
|
|
|
105
154
|
*/
|
|
106
155
|
determineStageContexts() {
|
|
107
156
|
const stage = this.node.tryGetContext('stage');
|
|
108
|
-
const stageContextPath = this.node.tryGetContext('stageContextPath') || '
|
|
157
|
+
const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdk-env';
|
|
109
158
|
const stageContextFilePath = path.join(appRoot.path, stageContextPath, `${stage}.json`);
|
|
110
159
|
const debug = this.node.tryGetContext('debug');
|
|
111
160
|
if (isDevStage(stage)) {
|
|
@@ -138,6 +187,45 @@ export class CommonStack extends Stack {
|
|
|
138
187
|
}
|
|
139
188
|
});
|
|
140
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* @summary Method to determine stage-region cdk contexts for environment and region-specific overrides
|
|
192
|
+
* - Loads `{stageRegionContextPath}/{stage}.{region}.json` if present
|
|
193
|
+
* - Has the highest priority in the configuration hierarchy
|
|
194
|
+
* - Primary use is to override config for a specific stage+region combination (e.g., prd.eu-west-1.json)
|
|
195
|
+
*/
|
|
196
|
+
determineStageRegionContexts() {
|
|
197
|
+
const stage = this.node.tryGetContext('stage');
|
|
198
|
+
const region = this.node.tryGetContext('region');
|
|
199
|
+
const stageRegionContextPath = this.node.tryGetContext('stageRegionContextPath');
|
|
200
|
+
const debug = this.node.tryGetContext('debug');
|
|
201
|
+
if (!stage || !region || !stageRegionContextPath) {
|
|
202
|
+
if (debug)
|
|
203
|
+
console.debug(`No stage-region context provided. Using default context properties from cdk.json`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const stageRegionContextFilePath = path.join(appRoot.path, stageRegionContextPath, `${stage}.${region}.json`);
|
|
207
|
+
/* gracefully skip when stage-region config is missing */
|
|
208
|
+
if (!fs.existsSync(stageRegionContextFilePath)) {
|
|
209
|
+
if (debug)
|
|
210
|
+
console.debug(`Stage-region context properties unavailable in path:${stageRegionContextFilePath}`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
/* read the stage-region properties */
|
|
214
|
+
const stageRegionContextPropsBuffer = fs.readFileSync(stageRegionContextFilePath);
|
|
215
|
+
if (debug)
|
|
216
|
+
console.debug(`Adding stage-region contexts provided in ${stageRegionContextFilePath}`);
|
|
217
|
+
/* parse as JSON properties */
|
|
218
|
+
const stageRegionContextProps = JSON.parse(stageRegionContextPropsBuffer.toString('utf-8'));
|
|
219
|
+
/* set each of the property into the cdk node context */
|
|
220
|
+
_.keys(stageRegionContextProps).forEach((propKey) => {
|
|
221
|
+
if (typeof stageRegionContextProps[propKey] === 'object' && !Array.isArray(stageRegionContextProps[propKey])) {
|
|
222
|
+
this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), stageRegionContextProps[propKey]));
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
this.node.setContext(propKey, stageRegionContextProps[propKey]);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
141
229
|
/**
|
|
142
230
|
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
143
231
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils-aws",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "AWS CDK utilities for @gradientedge/cdk-utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
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",
|