@gradientedge/cdk-utils 8.121.0 → 8.123.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.
Files changed (124) hide show
  1. package/README.md +2 -1
  2. package/dist/src/lib/aws/common/construct.d.ts +0 -1
  3. package/dist/src/lib/aws/common/construct.js +6 -13
  4. package/dist/src/lib/aws/common/stack.js +7 -9
  5. package/dist/src/lib/aws/common/types.d.ts +2 -8
  6. package/dist/src/lib/aws/construct/api-to-any-target/main.js +24 -26
  7. package/dist/src/lib/aws/construct/api-to-eventbridge-target/main.js +85 -103
  8. package/dist/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.js +94 -120
  9. package/dist/src/lib/aws/construct/api-to-lambda-target/main.js +8 -10
  10. package/dist/src/lib/aws/construct/graphql-api-lambda/main.js +7 -3
  11. package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.js +5 -1
  12. package/dist/src/lib/aws/construct/lambda-with-iam-access/main.js +5 -1
  13. package/dist/src/lib/aws/construct/rest-api-lambda/main.js +7 -3
  14. package/dist/src/lib/aws/construct/rest-api-lambda-with-cache/main.js +5 -1
  15. package/dist/src/lib/aws/construct/site-with-ecs-backend/main.js +8 -6
  16. package/dist/src/lib/aws/construct/static-asset-deployment/main.js +5 -1
  17. package/dist/src/lib/aws/services/api-gateway/main.js +18 -10
  18. package/dist/src/lib/aws/services/cloudfront/main.js +11 -7
  19. package/dist/src/lib/aws/services/cloudwatch/logs.js +8 -4
  20. package/dist/src/lib/aws/services/cloudwatch/main.js +36 -78
  21. package/dist/src/lib/aws/services/dynamodb/main.js +6 -2
  22. package/dist/src/lib/aws/services/elastic-container-service/main.js +8 -4
  23. package/dist/src/lib/aws/services/elastic-file-system/main.js +5 -1
  24. package/dist/src/lib/aws/services/elasticache/main.js +6 -2
  25. package/dist/src/lib/aws/services/eventbridge/main.js +8 -4
  26. package/dist/src/lib/aws/services/lambda/main.js +7 -3
  27. package/dist/src/lib/aws/services/simple-notification-service/main.js +6 -2
  28. package/dist/src/lib/aws/services/simple-queue-service/main.js +6 -2
  29. package/dist/src/lib/aws/services/simple-storage-service/main.js +8 -4
  30. package/dist/src/lib/aws/services/step-function/main.js +52 -32
  31. package/dist/src/lib/aws/services/virtual-private-cloud/main.js +8 -4
  32. package/dist/src/lib/aws/types/index.d.ts +6 -1
  33. package/dist/src/lib/aws/types/index.js +0 -15
  34. package/dist/src/lib/aws/utils/index.d.ts +13 -23
  35. package/dist/src/lib/aws/utils/index.js +37 -46
  36. package/dist/src/lib/azure/common/construct.d.ts +35 -0
  37. package/dist/src/lib/azure/common/construct.js +49 -0
  38. package/dist/src/lib/azure/common/index.d.ts +3 -0
  39. package/dist/src/lib/azure/common/index.js +19 -0
  40. package/dist/src/lib/azure/common/stack.d.ts +52 -0
  41. package/dist/src/lib/azure/common/stack.js +134 -0
  42. package/dist/src/lib/azure/common/types.d.ts +7 -0
  43. package/dist/src/lib/azure/index.d.ts +4 -0
  44. package/dist/src/lib/azure/index.js +20 -0
  45. package/dist/src/lib/azure/services/index.d.ts +1 -0
  46. package/dist/src/lib/azure/services/index.js +17 -0
  47. package/dist/src/lib/azure/services/storage/index.d.ts +2 -0
  48. package/dist/src/lib/azure/services/storage/index.js +18 -0
  49. package/dist/src/lib/azure/services/storage/main.d.ts +43 -0
  50. package/dist/src/lib/azure/services/storage/main.js +124 -0
  51. package/dist/src/lib/azure/services/storage/types.d.ts +10 -0
  52. package/dist/src/lib/azure/services/storage/types.js +2 -0
  53. package/dist/src/lib/azure/types/index.d.ts +3 -0
  54. package/dist/src/lib/azure/types/index.js +2 -0
  55. package/dist/src/lib/azure/utils/index.d.ts +3 -0
  56. package/dist/src/lib/azure/utils/index.js +20 -0
  57. package/dist/src/lib/common/construct.d.ts +29 -0
  58. package/dist/src/lib/common/construct.js +8 -0
  59. package/dist/src/lib/common/index.d.ts +5 -0
  60. package/dist/src/lib/common/index.js +33 -0
  61. package/dist/src/lib/common/stack.d.ts +21 -0
  62. package/dist/src/lib/common/stack.js +8 -0
  63. package/dist/src/lib/common/types.d.ts +9 -0
  64. package/dist/src/lib/common/types.js +2 -0
  65. package/dist/src/lib/common/utils.d.ts +26 -0
  66. package/dist/src/lib/common/utils.js +34 -0
  67. package/dist/src/lib/index.d.ts +2 -0
  68. package/dist/src/lib/index.js +2 -0
  69. package/package.json +9 -7
  70. package/setup.js +2 -0
  71. package/src/lib/aws/common/construct.ts +2 -13
  72. package/src/lib/aws/common/stack.ts +6 -8
  73. package/src/lib/aws/common/types.ts +2 -8
  74. package/src/lib/aws/construct/api-to-any-target/main.ts +25 -27
  75. package/src/lib/aws/construct/api-to-eventbridge-target/main.ts +85 -103
  76. package/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.ts +94 -120
  77. package/src/lib/aws/construct/api-to-lambda-target/main.ts +8 -10
  78. package/src/lib/aws/construct/graphql-api-lambda/main.ts +4 -3
  79. package/src/lib/aws/construct/graphql-api-lambda-with-cache/main.ts +2 -1
  80. package/src/lib/aws/construct/lambda-with-iam-access/main.ts +2 -1
  81. package/src/lib/aws/construct/rest-api-lambda/main.ts +4 -3
  82. package/src/lib/aws/construct/rest-api-lambda-with-cache/main.ts +2 -1
  83. package/src/lib/aws/construct/site-with-ecs-backend/main.ts +8 -9
  84. package/src/lib/aws/construct/static-asset-deployment/main.ts +2 -1
  85. package/src/lib/aws/services/api-gateway/main.ts +9 -6
  86. package/src/lib/aws/services/cloudfront/main.ts +8 -7
  87. package/src/lib/aws/services/cloudwatch/logs.ts +6 -5
  88. package/src/lib/aws/services/cloudwatch/main.ts +35 -81
  89. package/src/lib/aws/services/dynamodb/main.ts +3 -2
  90. package/src/lib/aws/services/elastic-container-service/main.ts +5 -4
  91. package/src/lib/aws/services/elastic-file-system/main.ts +2 -1
  92. package/src/lib/aws/services/elasticache/main.ts +3 -2
  93. package/src/lib/aws/services/eventbridge/main.ts +5 -4
  94. package/src/lib/aws/services/lambda/main.ts +4 -3
  95. package/src/lib/aws/services/simple-notification-service/main.ts +3 -2
  96. package/src/lib/aws/services/simple-queue-service/main.ts +3 -2
  97. package/src/lib/aws/services/simple-storage-service/main.ts +5 -4
  98. package/src/lib/aws/services/step-function/main.ts +17 -16
  99. package/src/lib/aws/services/virtual-private-cloud/main.ts +5 -4
  100. package/src/lib/aws/types/index.ts +6 -1
  101. package/src/lib/aws/utils/index.ts +41 -29
  102. package/src/lib/azure/common/construct.ts +57 -0
  103. package/src/lib/azure/common/index.ts +3 -0
  104. package/src/lib/azure/common/stack.ts +143 -0
  105. package/src/lib/azure/common/types.ts +8 -0
  106. package/src/lib/azure/index.ts +4 -0
  107. package/src/lib/azure/services/index.ts +1 -0
  108. package/src/lib/azure/services/storage/index.ts +2 -0
  109. package/src/lib/azure/services/storage/main.ts +134 -0
  110. package/src/lib/azure/services/storage/types.ts +10 -0
  111. package/src/lib/azure/types/index.ts +3 -0
  112. package/src/lib/azure/utils/index.ts +23 -0
  113. package/src/lib/common/construct.ts +35 -0
  114. package/src/lib/common/index.ts +18 -0
  115. package/src/lib/common/stack.ts +26 -0
  116. package/src/lib/common/types.ts +9 -0
  117. package/src/lib/common/utils.ts +27 -0
  118. package/src/lib/index.ts +2 -0
  119. package/dist/src/lib/aws/types/aws/index.d.ts +0 -6
  120. package/dist/src/lib/aws/utils/aws/index.d.ts +0 -17
  121. package/dist/src/lib/aws/utils/aws/index.js +0 -40
  122. package/src/lib/aws/types/aws/index.ts +0 -6
  123. package/src/lib/aws/utils/aws/index.ts +0 -41
  124. /package/dist/src/lib/{aws/types/aws/index.js → azure/common/types.js} +0 -0
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SfnManager = void 0;
4
7
  const aws_cdk_lib_1 = require("aws-cdk-lib");
5
8
  const aws_stepfunctions_1 = require("aws-cdk-lib/aws-stepfunctions");
6
9
  const aws_stepfunctions_tasks_1 = require("aws-cdk-lib/aws-stepfunctions-tasks");
10
+ const lodash_1 = __importDefault(require("lodash"));
7
11
  const uuid_1 = require("uuid");
8
12
  const utils_1 = require("../../utils");
9
13
  const DEFAULT_RETRY_CONFIG = [
@@ -160,10 +164,12 @@ class SfnManager {
160
164
  if (!retries || retries.length === 0) {
161
165
  retries = DEFAULT_RETRY_CONFIG;
162
166
  }
163
- retries.forEach(retry => step.addRetry({
164
- ...retry,
165
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
166
- }));
167
+ lodash_1.default.forEach(retries, retry => {
168
+ step.addRetry({
169
+ ...retry,
170
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
171
+ });
172
+ });
167
173
  return step;
168
174
  }
169
175
  /**
@@ -202,10 +208,12 @@ class SfnManager {
202
208
  if (!retries || retries.length === 0) {
203
209
  retries = DEFAULT_RETRY_CONFIG;
204
210
  }
205
- retries.forEach(retry => step.addRetry({
206
- ...retry,
207
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
208
- }));
211
+ lodash_1.default.forEach(retries, retry => {
212
+ step.addRetry({
213
+ ...retry,
214
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
215
+ });
216
+ });
209
217
  return step;
210
218
  }
211
219
  /**
@@ -244,10 +252,12 @@ class SfnManager {
244
252
  if (!retries || retries.length === 0) {
245
253
  retries = DEFAULT_RETRY_CONFIG;
246
254
  }
247
- retries.forEach(retry => step.addRetry({
248
- ...retry,
249
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
250
- }));
255
+ lodash_1.default.forEach(retries, retry => {
256
+ step.addRetry({
257
+ ...retry,
258
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
259
+ });
260
+ });
251
261
  return step;
252
262
  }
253
263
  /**
@@ -284,10 +294,12 @@ class SfnManager {
284
294
  if (!retries || retries.length === 0) {
285
295
  retries = DEFAULT_RETRY_CONFIG;
286
296
  }
287
- retries.forEach(retry => step.addRetry({
288
- ...retry,
289
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
290
- }));
297
+ lodash_1.default.forEach(retries, retry => {
298
+ step.addRetry({
299
+ ...retry,
300
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
301
+ });
302
+ });
291
303
  return step;
292
304
  }
293
305
  /**
@@ -311,10 +323,12 @@ class SfnManager {
311
323
  if (!retries || retries.length === 0) {
312
324
  retries = DEFAULT_RETRY_CONFIG;
313
325
  }
314
- retries.forEach(retry => step.addRetry({
315
- ...retry,
316
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
317
- }));
326
+ lodash_1.default.forEach(retries, retry => {
327
+ step.addRetry({
328
+ ...retry,
329
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
330
+ });
331
+ });
318
332
  return step;
319
333
  }
320
334
  /**
@@ -341,10 +355,12 @@ class SfnManager {
341
355
  if (!retries || retries.length === 0) {
342
356
  retries = DEFAULT_RETRY_CONFIG;
343
357
  }
344
- retries.forEach(retry => step.addRetry({
345
- ...retry,
346
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
347
- }));
358
+ lodash_1.default.forEach(retries, retry => {
359
+ step.addRetry({
360
+ ...retry,
361
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
362
+ });
363
+ });
348
364
  return step;
349
365
  }
350
366
  /**
@@ -369,10 +385,12 @@ class SfnManager {
369
385
  if (!retries || retries.length === 0) {
370
386
  retries = DEFAULT_RETRY_CONFIG;
371
387
  }
372
- retries.forEach(retry => step.addRetry({
373
- ...retry,
374
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
375
- }));
388
+ lodash_1.default.forEach(retries, retry => {
389
+ step.addRetry({
390
+ ...retry,
391
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
392
+ });
393
+ });
376
394
  return step;
377
395
  }
378
396
  /**
@@ -394,10 +412,12 @@ class SfnManager {
394
412
  if (!retries || retries.length === 0) {
395
413
  retries = DEFAULT_RETRY_CONFIG;
396
414
  }
397
- retries.forEach(retry => step.addRetry({
398
- ...retry,
399
- ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
400
- }));
415
+ lodash_1.default.forEach(retries, retry => {
416
+ step.addRetry({
417
+ ...retry,
418
+ ...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
419
+ });
420
+ });
401
421
  return step;
402
422
  }
403
423
  /**
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.VpcManager = void 0;
4
7
  const aws_cdk_lib_1 = require("aws-cdk-lib");
5
8
  const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
6
9
  const utils_1 = require("../../utils");
10
+ const lodash_1 = __importDefault(require("lodash"));
7
11
  /**
8
12
  */
9
13
  const CommonVpcIdentifier = 'CommonVpc';
@@ -38,10 +42,10 @@ class VpcManager {
38
42
  maxAzs: props.maxAzs,
39
43
  });
40
44
  (0, utils_1.createCfnOutput)(`${id}Id`, scope, vpc.vpcId);
41
- (0, utils_1.createCfnOutput)(`${id}PublicSubnetIds`, scope, vpc.publicSubnets.map(subnet => subnet.subnetId).toString());
42
- (0, utils_1.createCfnOutput)(`${id}PrivateSubnetIds`, scope, vpc.privateSubnets.map(subnet => subnet.subnetId).toString());
43
- (0, utils_1.createCfnOutput)(`${id}PublicSubnetRouteTableIds`, scope, vpc.publicSubnets.map(subnet => subnet.routeTable.routeTableId).toString());
44
- (0, utils_1.createCfnOutput)(`${id}PrivateSubnetRouteTableIds`, scope, vpc.privateSubnets.map(subnet => subnet.routeTable.routeTableId).toString());
45
+ (0, utils_1.createCfnOutput)(`${id}PublicSubnetIds`, scope, lodash_1.default.map(vpc.publicSubnets, subnet => subnet.subnetId).toString());
46
+ (0, utils_1.createCfnOutput)(`${id}PrivateSubnetIds`, scope, lodash_1.default.map(vpc.privateSubnets, subnet => subnet.subnetId).toString());
47
+ (0, utils_1.createCfnOutput)(`${id}PublicSubnetRouteTableIds`, scope, lodash_1.default.map(vpc.publicSubnets, subnet => subnet.routeTable.routeTableId).toString());
48
+ (0, utils_1.createCfnOutput)(`${id}PrivateSubnetRouteTableIds`, scope, lodash_1.default.map(vpc.privateSubnets, subnet => subnet.routeTable.routeTableId).toString());
45
49
  (0, utils_1.createCfnOutput)(`${id}AvailabilityZones`, scope, vpc.availabilityZones.toString());
46
50
  (0, utils_1.createCfnOutput)(`${id}DefaultSecurityGroup`, scope, vpc.vpcDefaultSecurityGroup.toString());
47
51
  return vpc;
@@ -1 +1,6 @@
1
- export * from './aws';
1
+ /**
2
+ */
3
+ export interface TagProps {
4
+ key: string;
5
+ value: string;
6
+ }
@@ -1,17 +1,2 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./aws"), exports);
@@ -1,30 +1,20 @@
1
- export * from './aws';
1
+ import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
2
+ import { CfnOutput } from 'aws-cdk-lib';
3
+ import { CommonConstruct } from '../common';
2
4
  /**
5
+ * @summary Helper method to add CloudFormation outputs from the construct
6
+ * @param id scoped id of the resource
7
+ * @param scope scope in which this resource is defined
8
+ * @param value the value of the exported output
9
+ * @param description optional description for the output
10
+ * @param overrideId Flag which indicates whether to override the default logical id of the output
11
+ * @returns The CloudFormation output
3
12
  */
4
- export declare enum LogLevel {
5
- DEBUG = "DEBUG",
6
- INFO = "INFO",
7
- WARNING = "WARNING",
8
- TRACE = "TRACE",
9
- ERROR = "ERROR",
10
- CRITICAL = "CRITICAL"
11
- }
13
+ export declare function createCfnOutput(id: string, scope: CommonConstruct, value?: string, description?: string, overrideId?: boolean): CfnOutput;
12
14
  /**
13
- * @param stage
15
+ *
14
16
  */
15
- export declare const isDevStage: (stage: string) => boolean;
16
- /**
17
- * @param stage
18
- */
19
- export declare const isTestStage: (stage: string) => boolean;
20
- /**
21
- * @param stage
22
- */
23
- export declare const isUatStage: (stage: string) => boolean;
24
- /**
25
- * @param stage
26
- */
27
- export declare const isPrdStage: (stage: string) => boolean;
17
+ export declare function determineCredentials(): AwsCredentialIdentityProvider;
28
18
  /**
29
19
  * @param error
30
20
  */
@@ -1,21 +1,43 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.redirectSuccess = exports.redirectError = exports.isPrdStage = exports.isUatStage = exports.isTestStage = exports.isDevStage = exports.LogLevel = void 0;
18
- __exportStar(require("./aws"), exports);
6
+ exports.redirectSuccess = exports.redirectError = exports.determineCredentials = exports.createCfnOutput = void 0;
7
+ const credential_providers_1 = require("@aws-sdk/credential-providers");
8
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ /**
11
+ * @summary Helper method to add CloudFormation outputs from the construct
12
+ * @param id scoped id of the resource
13
+ * @param scope scope in which this resource is defined
14
+ * @param value the value of the exported output
15
+ * @param description optional description for the output
16
+ * @param overrideId Flag which indicates whether to override the default logical id of the output
17
+ * @returns The CloudFormation output
18
+ */
19
+ function createCfnOutput(id, scope, value, description, overrideId = true) {
20
+ const camelName = lodash_1.default.camelCase(id);
21
+ const output = new aws_cdk_lib_1.CfnOutput(scope, id, {
22
+ description,
23
+ exportName: `${scope.props.stackName}-${camelName}`,
24
+ value: value ?? '',
25
+ });
26
+ if (overrideId) {
27
+ output.overrideLogicalId(camelName);
28
+ }
29
+ return output;
30
+ }
31
+ exports.createCfnOutput = createCfnOutput;
32
+ /**
33
+ *
34
+ */
35
+ function determineCredentials() {
36
+ if (process.env.AWS_PROFILE)
37
+ return (0, credential_providers_1.fromIni)();
38
+ return (0, credential_providers_1.fromEnv)();
39
+ }
40
+ exports.determineCredentials = determineCredentials;
19
41
  /**
20
42
  */
21
43
  const defaultResponseObject = {
@@ -26,37 +48,6 @@ const defaultResponseObject = {
26
48
  isBase64Encoded: false,
27
49
  statusCode: 200,
28
50
  };
29
- /**
30
- */
31
- var LogLevel;
32
- (function (LogLevel) {
33
- LogLevel["DEBUG"] = "DEBUG";
34
- LogLevel["INFO"] = "INFO";
35
- LogLevel["WARNING"] = "WARNING";
36
- LogLevel["TRACE"] = "TRACE";
37
- LogLevel["ERROR"] = "ERROR";
38
- LogLevel["CRITICAL"] = "CRITICAL";
39
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
40
- /**
41
- * @param stage
42
- */
43
- const isDevStage = (stage) => stage === 'dev';
44
- exports.isDevStage = isDevStage;
45
- /**
46
- * @param stage
47
- */
48
- const isTestStage = (stage) => stage === 'tst';
49
- exports.isTestStage = isTestStage;
50
- /**
51
- * @param stage
52
- */
53
- const isUatStage = (stage) => stage === 'uat';
54
- exports.isUatStage = isUatStage;
55
- /**
56
- * @param stage
57
- */
58
- const isPrdStage = (stage) => stage === 'prd';
59
- exports.isPrdStage = isPrdStage;
60
51
  /**
61
52
  * @param error
62
53
  */
@@ -0,0 +1,35 @@
1
+ import { TerraformStack } from 'cdktf';
2
+ import { Construct } from 'constructs';
3
+ import { AzureStorageManager } from '../services';
4
+ import { CommonAzureStackProps } from './types';
5
+ export declare class CommonAzureConstruct extends TerraformStack {
6
+ props: CommonAzureStackProps;
7
+ id: string;
8
+ fullyQualifiedDomainName: string;
9
+ storageManager: AzureStorageManager;
10
+ constructor(scope: Construct, id: string, props: CommonAzureStackProps);
11
+ /**
12
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
13
+ */
14
+ protected determineFullyQualifiedDomain(): void;
15
+ /**
16
+ * @summary Utility method to determine if the initialisation is in development (dev) stage
17
+ * This is determined by the stage property injected via cdk context
18
+ */
19
+ isDevelopmentStage: () => boolean;
20
+ /**
21
+ * @summary Utility method to determine if the initialisation is in test (tst) stage
22
+ * This is determined by the stage property injected via cdk context
23
+ */
24
+ isTestStage: () => boolean;
25
+ /**
26
+ * @summary Utility method to determine if the initialisation is in uat (uat) stage
27
+ * This is determined by the stage property injected via cdk context
28
+ */
29
+ isUatStage: () => boolean;
30
+ /**
31
+ * @summary Utility method to determine if the initialisation is in production (prd) stage
32
+ * This is determined by the stage property injected via cdk context
33
+ */
34
+ isProductionStage: () => boolean;
35
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommonAzureConstruct = void 0;
4
+ const provider_1 = require("@cdktf/provider-azurerm/lib/provider");
5
+ const cdktf_1 = require("cdktf");
6
+ const common_1 = require("../../common");
7
+ const services_1 = require("../services");
8
+ class CommonAzureConstruct extends cdktf_1.TerraformStack {
9
+ id;
10
+ fullyQualifiedDomainName;
11
+ storageManager;
12
+ constructor(scope, id, props) {
13
+ super(scope, id);
14
+ this.props = props;
15
+ this.id = id;
16
+ this.storageManager = new services_1.AzureStorageManager();
17
+ this.determineFullyQualifiedDomain();
18
+ new provider_1.AzurermProvider(this, `${this.id}-provider`, this.props);
19
+ }
20
+ /**
21
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
22
+ */
23
+ determineFullyQualifiedDomain() {
24
+ this.fullyQualifiedDomainName = this.props.subDomain
25
+ ? `${this.props.subDomain}.${this.props.domainName}`
26
+ : this.props.domainName;
27
+ }
28
+ /**
29
+ * @summary Utility method to determine if the initialisation is in development (dev) stage
30
+ * This is determined by the stage property injected via cdk context
31
+ */
32
+ isDevelopmentStage = () => (0, common_1.isDevStage)(this.props.stage);
33
+ /**
34
+ * @summary Utility method to determine if the initialisation is in test (tst) stage
35
+ * This is determined by the stage property injected via cdk context
36
+ */
37
+ isTestStage = () => (0, common_1.isTestStage)(this.props.stage);
38
+ /**
39
+ * @summary Utility method to determine if the initialisation is in uat (uat) stage
40
+ * This is determined by the stage property injected via cdk context
41
+ */
42
+ isUatStage = () => (0, common_1.isUatStage)(this.props.stage);
43
+ /**
44
+ * @summary Utility method to determine if the initialisation is in production (prd) stage
45
+ * This is determined by the stage property injected via cdk context
46
+ */
47
+ isProductionStage = () => (0, common_1.isPrdStage)(this.props.stage);
48
+ }
49
+ exports.CommonAzureConstruct = CommonAzureConstruct;
@@ -0,0 +1,3 @@
1
+ export * from './construct';
2
+ export * from './stack';
3
+ export * from './types';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./construct"), exports);
18
+ __exportStar(require("./stack"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,52 @@
1
+ import { CommonAzureConstruct } from './construct';
2
+ import { CommonAzureStackProps } from './types';
3
+ import { TerraformStack } from 'cdktf';
4
+ import { Construct } from 'constructs';
5
+ /**
6
+ * @classdesc Common stack to use as a base for all higher level constructs.
7
+ * @example
8
+ * import { CommonAzureStack } from '@gradientedge/cdk-utils'
9
+ *
10
+ * class CustomStack extends CommonAzureStack {
11
+ * constructor(parent: App, name: string, props: StackProps) {
12
+ * super(parent, name, props)
13
+ * // provision resources
14
+ * }
15
+ * }
16
+ */
17
+ export declare class CommonAzureStack extends TerraformStack {
18
+ construct: CommonAzureConstruct;
19
+ props: CommonAzureStackProps;
20
+ constructor(parent: Construct, name: string, props: CommonAzureStackProps);
21
+ /**
22
+ * @summary Method to determine the core CDK construct properties injected via context cdktf.json
23
+ * @param props The stack properties
24
+ * @returns The stack properties
25
+ */
26
+ protected determineConstructProps(props: CommonAzureStackProps): {
27
+ domainName: any;
28
+ extraContexts: any;
29
+ features: any;
30
+ name: any;
31
+ resourceGroupName: any;
32
+ skipStageForARecords: any;
33
+ stage: any;
34
+ subDomain: any;
35
+ };
36
+ /**
37
+ * @summary Method to determine extra cdk contexts apart from the main cdktf.json
38
+ * - Sets the properties from the extra contexts into cdk node context
39
+ * - Primary use is to have layered config in separate files to enable easier maintenance and readability
40
+ */
41
+ protected determineExtraContexts(): void;
42
+ /**
43
+ * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
44
+ * - Sets the properties from the extra stage contexts into cdk node context
45
+ * - Primary use is to have layered config for each environment which is injected into the context
46
+ */
47
+ protected determineStageContexts(): void;
48
+ /**
49
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
50
+ */
51
+ protected fullyQualifiedDomain(): any;
52
+ }
@@ -0,0 +1,134 @@
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.CommonAzureStack = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const construct_1 = require("./construct");
9
+ const app_root_path_1 = __importDefault(require("app-root-path"));
10
+ const cdktf_1 = require("cdktf");
11
+ const lodash_1 = __importDefault(require("lodash"));
12
+ const common_1 = require("../../common");
13
+ /**
14
+ * @classdesc Common stack to use as a base for all higher level constructs.
15
+ * @example
16
+ * import { CommonAzureStack } from '@gradientedge/cdk-utils'
17
+ *
18
+ * class CustomStack extends CommonAzureStack {
19
+ * constructor(parent: App, name: string, props: StackProps) {
20
+ * super(parent, name, props)
21
+ * // provision resources
22
+ * }
23
+ * }
24
+ */
25
+ class CommonAzureStack extends cdktf_1.TerraformStack {
26
+ construct;
27
+ props;
28
+ constructor(parent, name, props) {
29
+ super(parent, name);
30
+ /* determine extra cdk contexts */
31
+ this.determineExtraContexts();
32
+ /* determine extra cdk stage contexts */
33
+ this.determineStageContexts();
34
+ this.props = this.determineConstructProps(props);
35
+ /* initialise the construct */
36
+ this.construct = new construct_1.CommonAzureConstruct(this, 'cdk-utils', this.props);
37
+ }
38
+ /**
39
+ * @summary Method to determine the core CDK construct properties injected via context cdktf.json
40
+ * @param props The stack properties
41
+ * @returns The stack properties
42
+ */
43
+ determineConstructProps(props) {
44
+ return {
45
+ domainName: this.node.tryGetContext('domainName'),
46
+ extraContexts: this.node.tryGetContext('extraContexts'),
47
+ features: this.node.tryGetContext('features'),
48
+ name: this.node.tryGetContext('resourceGroupName'),
49
+ resourceGroupName: this.node.tryGetContext('resourceGroupName'),
50
+ skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
51
+ stage: this.node.tryGetContext('stage'),
52
+ subDomain: this.node.tryGetContext('subDomain'),
53
+ };
54
+ }
55
+ /**
56
+ * @summary Method to determine extra cdk contexts apart from the main cdktf.json
57
+ * - Sets the properties from the extra contexts into cdk node context
58
+ * - Primary use is to have layered config in separate files to enable easier maintenance and readability
59
+ */
60
+ determineExtraContexts() {
61
+ const extraContexts = this.node.tryGetContext('extraContexts');
62
+ const debug = this.node.tryGetContext('debug');
63
+ if (!extraContexts) {
64
+ if (debug)
65
+ console.debug(`No additional contexts provided. Using default context properties from cdktf.json`);
66
+ return;
67
+ }
68
+ lodash_1.default.forEach(extraContexts, (context) => {
69
+ const extraContextPath = `${app_root_path_1.default.path}/${context}`;
70
+ /* scenario where extra context is configured in cdk.json but absent in file system */
71
+ if (!fs_1.default.existsSync(extraContextPath))
72
+ throw `Extra context properties unavailable in path:${extraContextPath}`;
73
+ /* read the extra properties */
74
+ const extraContextPropsBuffer = fs_1.default.readFileSync(extraContextPath);
75
+ if (debug)
76
+ console.debug(`Adding additional contexts provided in ${extraContextPath}`);
77
+ /* parse as JSON properties */
78
+ const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'));
79
+ /* set each of the property into the cdk node context */
80
+ lodash_1.default.keys(extraContextProps).forEach((propKey) => {
81
+ this.node.setContext(propKey, extraContextProps[propKey]);
82
+ });
83
+ });
84
+ }
85
+ /**
86
+ * @summary Method to determine extra cdk stage contexts apart from the main cdktf.json
87
+ * - Sets the properties from the extra stage contexts into cdk node context
88
+ * - Primary use is to have layered config for each environment which is injected into the context
89
+ */
90
+ determineStageContexts() {
91
+ const stage = this.node.tryGetContext('stage');
92
+ const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv';
93
+ const stageContextFilePath = `${app_root_path_1.default.path}/${stageContextPath}/${stage}.json`;
94
+ const debug = this.node.tryGetContext('debug');
95
+ if ((0, common_1.isDevStage)(stage)) {
96
+ if (debug)
97
+ console.debug(`Development stage. Using default stage context properties`);
98
+ }
99
+ /* alert default context usage when extra stage config is missing */
100
+ if (!fs_1.default.existsSync(stageContextFilePath)) {
101
+ if (debug)
102
+ console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`);
103
+ if (debug)
104
+ console.debug(`Using default stage context properties for ${stage} stage`);
105
+ return;
106
+ }
107
+ /* read the extra properties */
108
+ const stageContextPropsBuffer = fs_1.default.readFileSync(stageContextFilePath);
109
+ if (debug)
110
+ console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`);
111
+ /* parse as JSON properties */
112
+ const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'));
113
+ /* set each of the property into the cdk node context */
114
+ lodash_1.default.keys(stageContextProps).forEach((propKey) => {
115
+ /* handle object, array properties */
116
+ if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
117
+ this.node.setContext(propKey, lodash_1.default.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]));
118
+ }
119
+ else {
120
+ /* handle all other primitive properties */
121
+ this.node.setContext(propKey, stageContextProps[propKey]);
122
+ }
123
+ });
124
+ }
125
+ /**
126
+ * @summary Determine the fully qualified domain name based on domainName & subDomain
127
+ */
128
+ fullyQualifiedDomain() {
129
+ const domainName = this.node.tryGetContext('domainName');
130
+ const subDomain = this.node.tryGetContext('subDomain');
131
+ return subDomain ? `${subDomain}.${domainName}` : domainName;
132
+ }
133
+ }
134
+ exports.CommonAzureStack = CommonAzureStack;
@@ -0,0 +1,7 @@
1
+ import { AzurermProviderConfig } from '@cdktf/provider-azurerm/lib/provider';
2
+ import { BaseProps } from '../../common';
3
+ /**
4
+ */
5
+ export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig {
6
+ resourceGroupName?: string;
7
+ }
@@ -0,0 +1,4 @@
1
+ export * from './common';
2
+ export * from './services';
3
+ export * from './types';
4
+ export * from './utils';