@gradientedge/cdk-utils 8.36.0 → 8.37.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.
@@ -37,6 +37,7 @@ export declare class CommonStack extends cdk.Stack {
37
37
  extraContexts: any;
38
38
  skipStageForARecords: any;
39
39
  logRetention: any;
40
+ excludeDomainNameForBuckets: any;
40
41
  nodejsRuntime: any;
41
42
  };
42
43
  /**
@@ -76,6 +76,7 @@ class CommonStack extends cdk.Stack {
76
76
  extraContexts: this.node.tryGetContext('extraContexts'),
77
77
  skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
78
78
  logRetention: this.node.tryGetContext('logRetention'),
79
+ excludeDomainNameForBuckets: this.node.tryGetContext('excludeDomainNameForBuckets'),
79
80
  nodejsRuntime: this.node.tryGetContext('nodejsRuntime') ?? CommonStack.NODEJS_RUNTIME,
80
81
  };
81
82
  }
@@ -32,19 +32,26 @@ export declare class S3Manager {
32
32
  */
33
33
  protected determineBucketLifecycleRules(props: types.S3BucketProps): types.LifecycleRule[] | undefined;
34
34
  /**
35
- * @summary Method to determine the bucket name
35
+ * @summary Method to determine the bucket name using account and region
36
36
  * @param {common.CommonConstruct} scope scope in which this resource is defined
37
- * @param {types.S3BucketProps} props bucket properties
38
- * @private
37
+ * @param {string} bucketName the bucket name
38
+ * @protected
39
39
  */
40
- protected static determineBucketName(scope: common.CommonConstruct, props: types.S3BucketProps): string;
40
+ protected static determineBucketNameByAccountAndRegion(scope: common.CommonConstruct, bucketName: string): string;
41
41
  /**
42
- * @summary Method to determine the log bucket name
42
+ * @summary Method to determine the bucket name using domain name
43
43
  * @param {common.CommonConstruct} scope scope in which this resource is defined
44
- * @param {types.S3BucketProps} props bucket properties
44
+ * @param {string} bucketName the bucket name
45
+ * @protected
46
+ */
47
+ protected static determineBucketNameByDomainName(scope: common.CommonConstruct, bucketName: string): string;
48
+ /**
49
+ * @summary Method to determine the bucket name
50
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
51
+ * @param {string} bucketName the bucket name
45
52
  * @private
46
53
  */
47
- protected static determineLogBucketName(scope: common.CommonConstruct, props: types.S3BucketProps): string;
54
+ protected static determineBucketName(scope: common.CommonConstruct, bucketName: string): string;
48
55
  /**
49
56
  * @summary Method to create a s3 bucket
50
57
  * @param {string} id scoped id of the resource
@@ -79,26 +79,36 @@ class S3Manager {
79
79
  return bucketLifecycleRules;
80
80
  }
81
81
  /**
82
- * @summary Method to determine the bucket name
82
+ * @summary Method to determine the bucket name using account and region
83
83
  * @param {common.CommonConstruct} scope scope in which this resource is defined
84
- * @param {types.S3BucketProps} props bucket properties
85
- * @private
84
+ * @param {string} bucketName the bucket name
85
+ * @protected
86
+ */
87
+ static determineBucketNameByAccountAndRegion(scope, bucketName) {
88
+ return `${bucketName}-${cdk.Stack.of(scope).account}-${scope.props.region}-${scope.props.stage}`;
89
+ }
90
+ /**
91
+ * @summary Method to determine the bucket name using domain name
92
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
93
+ * @param {string} bucketName the bucket name
94
+ * @protected
86
95
  */
87
- static determineBucketName(scope, props) {
96
+ static determineBucketNameByDomainName(scope, bucketName) {
88
97
  return scope.isProductionStage()
89
- ? `${props.bucketName}.${scope.fullyQualifiedDomainName}`
90
- : `${props.bucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`;
98
+ ? `${bucketName}.${scope.fullyQualifiedDomainName}`
99
+ : `${bucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`;
91
100
  }
92
101
  /**
93
- * @summary Method to determine the log bucket name
102
+ * @summary Method to determine the bucket name
94
103
  * @param {common.CommonConstruct} scope scope in which this resource is defined
95
- * @param {types.S3BucketProps} props bucket properties
104
+ * @param {string} bucketName the bucket name
96
105
  * @private
97
106
  */
98
- static determineLogBucketName(scope, props) {
99
- return scope.isProductionStage()
100
- ? `${props.logBucketName}.${scope.fullyQualifiedDomainName}`
101
- : `${props.logBucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`;
107
+ static determineBucketName(scope, bucketName) {
108
+ const sanitisedBucketName = scope.props.excludeDomainNameForBuckets
109
+ ? S3Manager.determineBucketNameByAccountAndRegion(scope, bucketName)
110
+ : S3Manager.determineBucketNameByDomainName(scope, bucketName);
111
+ return sanitisedBucketName;
102
112
  }
103
113
  /**
104
114
  * @summary Method to create a s3 bucket
@@ -110,14 +120,14 @@ class S3Manager {
110
120
  if (!props)
111
121
  throw `S3 props undefined for ${id}`;
112
122
  let bucket;
113
- const bucketName = S3Manager.determineBucketName(scope, props);
123
+ const bucketName = S3Manager.determineBucketName(scope, props.bucketName);
114
124
  if (props.existingBucket && props.bucketName) {
115
125
  bucket = s3.Bucket.fromBucketName(scope, `${id}`, bucketName);
116
126
  }
117
127
  else {
118
128
  let logBucket;
119
129
  if (props.logBucketName) {
120
- const logBucketName = S3Manager.determineLogBucketName(scope, props);
130
+ const logBucketName = S3Manager.determineBucketName(scope, props.logBucketName);
121
131
  logBucket = s3.Bucket.fromBucketName(scope, `${id}-logs`, logBucketName);
122
132
  }
123
133
  bucket = new s3.Bucket(scope, `${id}-bucket`, {
@@ -53,6 +53,7 @@ export interface CommonStackProps extends cdk.StackProps {
53
53
  stageContextPath?: string;
54
54
  skipStageForARecords: boolean;
55
55
  logRetention?: logs.RetentionDays;
56
+ excludeDomainNameForBuckets?: boolean;
56
57
  nodejsRuntime?: lambda.Runtime;
57
58
  }
58
59
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.36.0",
3
+ "version": "8.37.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -60,6 +60,7 @@ export class CommonStack extends cdk.Stack {
60
60
  extraContexts: this.node.tryGetContext('extraContexts'),
61
61
  skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
62
62
  logRetention: this.node.tryGetContext('logRetention'),
63
+ excludeDomainNameForBuckets: this.node.tryGetContext('excludeDomainNameForBuckets'),
63
64
  nodejsRuntime: this.node.tryGetContext('nodejsRuntime') ?? CommonStack.NODEJS_RUNTIME,
64
65
  }
65
66
  }
@@ -59,27 +59,38 @@ export class S3Manager {
59
59
  }
60
60
 
61
61
  /**
62
- * @summary Method to determine the bucket name
62
+ * @summary Method to determine the bucket name using account and region
63
63
  * @param {common.CommonConstruct} scope scope in which this resource is defined
64
- * @param {types.S3BucketProps} props bucket properties
65
- * @private
64
+ * @param {string} bucketName the bucket name
65
+ * @protected
66
66
  */
67
- protected static determineBucketName(scope: common.CommonConstruct, props: types.S3BucketProps) {
67
+ protected static determineBucketNameByAccountAndRegion(scope: common.CommonConstruct, bucketName: string) {
68
+ return `${bucketName}-${cdk.Stack.of(scope).account}-${scope.props.region}-${scope.props.stage}`
69
+ }
70
+
71
+ /**
72
+ * @summary Method to determine the bucket name using domain name
73
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
74
+ * @param {string} bucketName the bucket name
75
+ * @protected
76
+ */
77
+ protected static determineBucketNameByDomainName(scope: common.CommonConstruct, bucketName: string) {
68
78
  return scope.isProductionStage()
69
- ? `${props.bucketName}.${scope.fullyQualifiedDomainName}`
70
- : `${props.bucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`
79
+ ? `${bucketName}.${scope.fullyQualifiedDomainName}`
80
+ : `${bucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`
71
81
  }
72
82
 
73
83
  /**
74
- * @summary Method to determine the log bucket name
84
+ * @summary Method to determine the bucket name
75
85
  * @param {common.CommonConstruct} scope scope in which this resource is defined
76
- * @param {types.S3BucketProps} props bucket properties
86
+ * @param {string} bucketName the bucket name
77
87
  * @private
78
88
  */
79
- protected static determineLogBucketName(scope: common.CommonConstruct, props: types.S3BucketProps) {
80
- return scope.isProductionStage()
81
- ? `${props.logBucketName}.${scope.fullyQualifiedDomainName}`
82
- : `${props.logBucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`
89
+ protected static determineBucketName(scope: common.CommonConstruct, bucketName: string) {
90
+ const sanitisedBucketName = scope.props.excludeDomainNameForBuckets
91
+ ? S3Manager.determineBucketNameByAccountAndRegion(scope, bucketName)
92
+ : S3Manager.determineBucketNameByDomainName(scope, bucketName)
93
+ return sanitisedBucketName
83
94
  }
84
95
 
85
96
  /**
@@ -93,14 +104,14 @@ export class S3Manager {
93
104
 
94
105
  let bucket: s3.IBucket
95
106
 
96
- const bucketName = S3Manager.determineBucketName(scope, props)
107
+ const bucketName = S3Manager.determineBucketName(scope, props.bucketName)
97
108
 
98
109
  if (props.existingBucket && props.bucketName) {
99
110
  bucket = s3.Bucket.fromBucketName(scope, `${id}`, bucketName)
100
111
  } else {
101
112
  let logBucket
102
113
  if (props.logBucketName) {
103
- const logBucketName = S3Manager.determineLogBucketName(scope, props)
114
+ const logBucketName = S3Manager.determineBucketName(scope, props.logBucketName)
104
115
  logBucket = s3.Bucket.fromBucketName(scope, `${id}-logs`, logBucketName)
105
116
  }
106
117
 
@@ -55,6 +55,7 @@ export interface CommonStackProps extends cdk.StackProps {
55
55
  stageContextPath?: string
56
56
  skipStageForARecords: boolean
57
57
  logRetention?: logs.RetentionDays
58
+ excludeDomainNameForBuckets?: boolean
58
59
  nodejsRuntime?: lambda.Runtime
59
60
  }
60
61