@gradientedge/cdk-utils 8.35.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.
- package/README.md +6 -0
- package/dist/src/lib/common/stack.d.ts +1 -0
- package/dist/src/lib/common/stack.js +1 -0
- package/dist/src/lib/manager/aws/s3-manager.d.ts +14 -7
- package/dist/src/lib/manager/aws/s3-manager.js +24 -14
- package/dist/src/lib/types/aws/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/lib/common/stack.ts +1 -0
- package/src/lib/manager/aws/s3-manager.ts +25 -14
- package/src/lib/types/aws/index.ts +1 -0
package/README.md
CHANGED
|
@@ -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 {
|
|
38
|
-
* @
|
|
37
|
+
* @param {string} bucketName the bucket name
|
|
38
|
+
* @protected
|
|
39
39
|
*/
|
|
40
|
-
protected static
|
|
40
|
+
protected static determineBucketNameByAccountAndRegion(scope: common.CommonConstruct, bucketName: string): string;
|
|
41
41
|
/**
|
|
42
|
-
* @summary Method to determine the
|
|
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 {
|
|
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
|
|
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 {
|
|
85
|
-
* @
|
|
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
|
|
96
|
+
static determineBucketNameByDomainName(scope, bucketName) {
|
|
88
97
|
return scope.isProductionStage()
|
|
89
|
-
? `${
|
|
90
|
-
: `${
|
|
98
|
+
? `${bucketName}.${scope.fullyQualifiedDomainName}`
|
|
99
|
+
: `${bucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`;
|
|
91
100
|
}
|
|
92
101
|
/**
|
|
93
|
-
* @summary Method to determine the
|
|
102
|
+
* @summary Method to determine the bucket name
|
|
94
103
|
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
95
|
-
* @param {
|
|
104
|
+
* @param {string} bucketName the bucket name
|
|
96
105
|
* @private
|
|
97
106
|
*/
|
|
98
|
-
static
|
|
99
|
-
|
|
100
|
-
?
|
|
101
|
-
:
|
|
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.
|
|
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`, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.37.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
},
|
|
96
96
|
"config": {
|
|
97
97
|
"commitizen": {
|
|
98
|
-
"path": "
|
|
98
|
+
"path": "cz-conventional-changelog"
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
"workspaces": [
|
package/src/lib/common/stack.ts
CHANGED
|
@@ -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 {
|
|
65
|
-
* @
|
|
64
|
+
* @param {string} bucketName the bucket name
|
|
65
|
+
* @protected
|
|
66
66
|
*/
|
|
67
|
-
protected static
|
|
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
|
-
? `${
|
|
70
|
-
: `${
|
|
79
|
+
? `${bucketName}.${scope.fullyQualifiedDomainName}`
|
|
80
|
+
: `${bucketName}-${scope.props.stage}.${scope.fullyQualifiedDomainName}`
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
/**
|
|
74
|
-
* @summary Method to determine the
|
|
84
|
+
* @summary Method to determine the bucket name
|
|
75
85
|
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
76
|
-
* @param {
|
|
86
|
+
* @param {string} bucketName the bucket name
|
|
77
87
|
* @private
|
|
78
88
|
*/
|
|
79
|
-
protected static
|
|
80
|
-
|
|
81
|
-
?
|
|
82
|
-
:
|
|
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.
|
|
114
|
+
const logBucketName = S3Manager.determineBucketName(scope, props.logBucketName)
|
|
104
115
|
logBucket = s3.Bucket.fromBucketName(scope, `${id}-logs`, logBucketName)
|
|
105
116
|
}
|
|
106
117
|
|