@fishawack/lab-env 5.6.1 → 5.7.0-beta.10
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/CHANGELOG.md +136 -0
- package/_Test/boilerplate-adonis.js +1 -1
- package/_Test/boilerplate-craftcms.js +1 -1
- package/_Test/boilerplate-drupal.js +1 -1
- package/_Test/boilerplate-laravel.js +1 -1
- package/_Test/boilerplate-python.js +1 -1
- package/_Test/boilerplate-wordpress.js +1 -1
- package/_Test/boilerplate.js +1 -1
- package/_Test/provision.js +4 -9
- package/_Test/prune.js +8 -5
- package/bitbucket-pipelines.yml +2 -2
- package/cli.js +2 -0
- package/commands/create/cmds/dekey.js +13 -9
- package/commands/create/cmds/deprovision.js +66 -6
- package/commands/create/cmds/diagnose.js +10 -0
- package/commands/create/cmds/key.js +74 -41
- package/commands/create/cmds/provision.js +641 -22
- package/commands/create/cmds/rekey.js +283 -0
- package/commands/create/cmds/sync-secrets.js +198 -0
- package/commands/create/libs/output-credentials.js +59 -0
- package/commands/create/libs/parallel-runner.js +296 -0
- package/commands/create/libs/resolve-operator.js +59 -0
- package/commands/create/libs/utilities.js +75 -8
- package/commands/create/libs/vars.js +273 -377
- package/commands/create/services/aws/acm.js +61 -0
- package/commands/create/services/aws/cloudfront.js +51 -45
- package/commands/create/services/aws/ec2.js +781 -5
- package/commands/create/services/aws/elasticache.js +159 -0
- package/commands/create/services/aws/elasticbeanstalk.js +200 -48
- package/commands/create/services/aws/iam.js +430 -82
- package/commands/create/services/aws/index.js +1598 -100
- package/commands/create/services/aws/opensearch.js +155 -0
- package/commands/create/services/aws/rds.js +272 -0
- package/commands/create/services/aws/s3.js +52 -31
- package/commands/create/services/aws/secretsmanager.js +82 -0
- package/commands/create/services/aws/ses.js +203 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/cron.config +45 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/queue-worker.config +29 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/rds-ssl.config +5 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/software.config +12 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/misc/setvars.config +1 -0
- package/commands/create/templates/elasticbeanstalk/.platform/confighooks/postdeploy/restart_queue.sh +4 -0
- package/commands/create/templates/elasticbeanstalk/.platform/confighooks/postdeploy/rewrite-flush.sh +1 -1
- package/commands/create/templates/elasticbeanstalk/.platform/confighooks/prebuild/setvars.sh +19 -0
- package/commands/create/templates/elasticbeanstalk/.platform/hooks/postdeploy/restart_queue.sh +4 -0
- package/commands/create/templates/elasticbeanstalk/.platform/hooks/prebuild/setvars.sh +19 -0
- package/commands/scan.js +1 -1
- package/core/1/CHANGELOG.md +41 -0
- package/core/1/Dockerfile +3 -3
- package/core/1/bitbucket-pipelines.yml +5 -5
- package/core/1/package.json +1 -1
- package/globals.js +4 -0
- package/package.json +9 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const {
|
|
2
|
+
OpenSearchClient,
|
|
3
|
+
CreateDomainCommand,
|
|
4
|
+
DeleteDomainCommand,
|
|
5
|
+
DescribeDomainCommand,
|
|
6
|
+
} = require("@aws-sdk/client-opensearch");
|
|
7
|
+
const { Spinner, poll } = require("../../libs/utilities");
|
|
8
|
+
const { awsClientConfig } = require("../../libs/vars");
|
|
9
|
+
|
|
10
|
+
const getClient = () => new OpenSearchClient(awsClientConfig);
|
|
11
|
+
|
|
12
|
+
module.exports.createOpenSearchDomain = async (
|
|
13
|
+
name,
|
|
14
|
+
securityGroupId,
|
|
15
|
+
privateSubnetIds,
|
|
16
|
+
instanceProfileRole,
|
|
17
|
+
tags = [],
|
|
18
|
+
) => {
|
|
19
|
+
const accountId = instanceProfileRole.split(":")[4] || "*";
|
|
20
|
+
const region = process.env.AWS_REGION;
|
|
21
|
+
|
|
22
|
+
const res = await Spinner.prototype.simple(
|
|
23
|
+
`Creating OpenSearch domain ${name}`,
|
|
24
|
+
() => {
|
|
25
|
+
return getClient().send(
|
|
26
|
+
new CreateDomainCommand({
|
|
27
|
+
DomainName: name,
|
|
28
|
+
EngineVersion: "OpenSearch_2.19",
|
|
29
|
+
ClusterConfig: {
|
|
30
|
+
InstanceType: "t3.small.search",
|
|
31
|
+
InstanceCount: 2,
|
|
32
|
+
ZoneAwarenessEnabled: true,
|
|
33
|
+
ZoneAwarenessConfig: {
|
|
34
|
+
AvailabilityZoneCount: 2,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
EBSOptions: {
|
|
38
|
+
EBSEnabled: true,
|
|
39
|
+
VolumeType: "gp3",
|
|
40
|
+
VolumeSize: 20,
|
|
41
|
+
},
|
|
42
|
+
VPCOptions: {
|
|
43
|
+
SubnetIds: privateSubnetIds,
|
|
44
|
+
SecurityGroupIds: [securityGroupId],
|
|
45
|
+
},
|
|
46
|
+
EncryptionAtRestOptions: {
|
|
47
|
+
Enabled: true,
|
|
48
|
+
},
|
|
49
|
+
NodeToNodeEncryptionOptions: {
|
|
50
|
+
Enabled: true,
|
|
51
|
+
},
|
|
52
|
+
DomainEndpointOptions: {
|
|
53
|
+
EnforceHTTPS: true,
|
|
54
|
+
TLSSecurityPolicy: "Policy-Min-TLS-1-2-2019-07",
|
|
55
|
+
},
|
|
56
|
+
AdvancedSecurityOptions: {
|
|
57
|
+
Enabled: false,
|
|
58
|
+
InternalUserDatabaseEnabled: false,
|
|
59
|
+
},
|
|
60
|
+
AccessPolicies: JSON.stringify({
|
|
61
|
+
Version: "2012-10-17",
|
|
62
|
+
Statement: [
|
|
63
|
+
{
|
|
64
|
+
Effect: "Allow",
|
|
65
|
+
Principal: {
|
|
66
|
+
AWS: instanceProfileRole,
|
|
67
|
+
},
|
|
68
|
+
Action: "es:ESHttp*",
|
|
69
|
+
Resource: `arn:aws:es:${region}:${accountId}:domain/${name}/*`,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
}),
|
|
73
|
+
TagList: [
|
|
74
|
+
{ Key: "client", Value: process.env.AWS_PROFILE },
|
|
75
|
+
].concat(
|
|
76
|
+
tags.map((t) => ({
|
|
77
|
+
Key: t.Key,
|
|
78
|
+
Value: String(t.Value),
|
|
79
|
+
})),
|
|
80
|
+
),
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return res;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
module.exports.waitForOpenSearchDomain = async (name) => {
|
|
90
|
+
const res = await Spinner.prototype.simple(
|
|
91
|
+
`Waiting for OpenSearch domain to become available (this may take 15-20 minutes)`,
|
|
92
|
+
(spinner) => {
|
|
93
|
+
return poll(
|
|
94
|
+
async () => {
|
|
95
|
+
const { DomainStatus } = await getClient().send(
|
|
96
|
+
new DescribeDomainCommand({ DomainName: name }),
|
|
97
|
+
);
|
|
98
|
+
return DomainStatus;
|
|
99
|
+
},
|
|
100
|
+
(status) =>
|
|
101
|
+
status.Processing ||
|
|
102
|
+
(!status.Endpoint && !status.Endpoints),
|
|
103
|
+
undefined,
|
|
104
|
+
spinner,
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
return res;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
module.exports.describeOpenSearchDomain = async (name) => {
|
|
113
|
+
const res = await Spinner.prototype.simple(
|
|
114
|
+
`Describing OpenSearch domain ${name}`,
|
|
115
|
+
() => {
|
|
116
|
+
return getClient().send(
|
|
117
|
+
new DescribeDomainCommand({ DomainName: name }),
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return res.DomainStatus;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
module.exports.deleteOpenSearchDomain = async (name) => {
|
|
126
|
+
await Spinner.prototype.simple(`Deleting OpenSearch domain ${name}`, () => {
|
|
127
|
+
return getClient().send(new DeleteDomainCommand({ DomainName: name }));
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
module.exports.waitForOpenSearchDeletion = async (name) => {
|
|
132
|
+
await Spinner.prototype.simple(
|
|
133
|
+
`Waiting for OpenSearch domain to be deleted`,
|
|
134
|
+
(spinner) => {
|
|
135
|
+
return poll(
|
|
136
|
+
async () => {
|
|
137
|
+
try {
|
|
138
|
+
const { DomainStatus } = await getClient().send(
|
|
139
|
+
new DescribeDomainCommand({ DomainName: name }),
|
|
140
|
+
);
|
|
141
|
+
return DomainStatus;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
if (e.name === "ResourceNotFoundException") {
|
|
144
|
+
return { deleted: true };
|
|
145
|
+
}
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
(status) => !status.deleted,
|
|
150
|
+
undefined,
|
|
151
|
+
spinner,
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
};
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
const {
|
|
2
|
+
RDSClient,
|
|
3
|
+
CreateDBInstanceCommand,
|
|
4
|
+
CreateDBSubnetGroupCommand,
|
|
5
|
+
DeleteDBInstanceCommand,
|
|
6
|
+
DescribeDBInstancesCommand,
|
|
7
|
+
DescribeDBSnapshotsCommand,
|
|
8
|
+
DescribeDBSubnetGroupsCommand,
|
|
9
|
+
RestoreDBInstanceFromDBSnapshotCommand,
|
|
10
|
+
ModifyDBInstanceCommand,
|
|
11
|
+
DescribeDBParameterGroupsCommand,
|
|
12
|
+
CreateDBParameterGroupCommand,
|
|
13
|
+
ModifyDBParameterGroupCommand,
|
|
14
|
+
} = require("@aws-sdk/client-rds");
|
|
15
|
+
const { Spinner, poll } = require("../../libs/utilities");
|
|
16
|
+
const { awsClientConfig } = require("../../libs/vars");
|
|
17
|
+
|
|
18
|
+
const getClient = () => new RDSClient(awsClientConfig);
|
|
19
|
+
|
|
20
|
+
module.exports.ensureDBSubnetGroup = async (privateSubnetIds) => {
|
|
21
|
+
const name = "fw-auto-private-db-subnet-group";
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await getClient().send(
|
|
25
|
+
new DescribeDBSubnetGroupsCommand({
|
|
26
|
+
DBSubnetGroupName: name,
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return name;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e.name !== "DBSubnetGroupNotFoundFault") {
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await Spinner.prototype.simple(`Creating DB subnet group ${name}`, () => {
|
|
38
|
+
return getClient().send(
|
|
39
|
+
new CreateDBSubnetGroupCommand({
|
|
40
|
+
DBSubnetGroupName: name,
|
|
41
|
+
DBSubnetGroupDescription:
|
|
42
|
+
"Private subnets for lab-env RDS instances",
|
|
43
|
+
SubnetIds: privateSubnetIds,
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return name;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
module.exports.createRDSInstance = async (
|
|
52
|
+
name,
|
|
53
|
+
tags = [],
|
|
54
|
+
password,
|
|
55
|
+
securityGroupId,
|
|
56
|
+
subnetGroupName,
|
|
57
|
+
) => {
|
|
58
|
+
let res = await Spinner.prototype.simple(
|
|
59
|
+
`Creating RDS instance ${name}`,
|
|
60
|
+
() => {
|
|
61
|
+
return getClient().send(
|
|
62
|
+
new CreateDBInstanceCommand({
|
|
63
|
+
DBInstanceIdentifier: name,
|
|
64
|
+
DBInstanceClass: "db.t3.small",
|
|
65
|
+
Engine: "mysql",
|
|
66
|
+
EngineVersion: "8.0.43",
|
|
67
|
+
MasterUsername: "ebroot",
|
|
68
|
+
MasterUserPassword: password,
|
|
69
|
+
AllocatedStorage: 5,
|
|
70
|
+
StorageEncrypted: true,
|
|
71
|
+
PubliclyAccessible: false,
|
|
72
|
+
BackupRetentionPeriod: 7,
|
|
73
|
+
DBName: "ebdb",
|
|
74
|
+
DBParameterGroupName: "lab-env-mysql80-ssl-required",
|
|
75
|
+
DBSubnetGroupName: subnetGroupName,
|
|
76
|
+
VpcSecurityGroupIds: [securityGroupId],
|
|
77
|
+
Tags: [
|
|
78
|
+
{ Key: "client", Value: process.env.AWS_PROFILE },
|
|
79
|
+
].concat(tags),
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return res;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
module.exports.waitForRDSInstance = async (name) => {
|
|
89
|
+
const res = await Spinner.prototype.simple(
|
|
90
|
+
`Waiting for RDS instance to become available`,
|
|
91
|
+
(spinner) => {
|
|
92
|
+
return poll(
|
|
93
|
+
async () =>
|
|
94
|
+
(
|
|
95
|
+
await getClient().send(
|
|
96
|
+
new DescribeDBInstancesCommand({
|
|
97
|
+
DBInstanceIdentifier: name,
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
).DBInstances[0],
|
|
101
|
+
({ DBInstanceStatus }) => DBInstanceStatus !== "available",
|
|
102
|
+
undefined,
|
|
103
|
+
spinner,
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return res;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
module.exports.describeRDSInstance = async (name) => {
|
|
112
|
+
let res = await Spinner.prototype.simple(
|
|
113
|
+
`Describing RDS instance ${name}`,
|
|
114
|
+
() => {
|
|
115
|
+
return getClient().send(
|
|
116
|
+
new DescribeDBInstancesCommand({
|
|
117
|
+
DBInstanceIdentifier: name,
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
return res.DBInstances[0];
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
module.exports.deleteRDSInstance = async (name) => {
|
|
127
|
+
await Spinner.prototype.simple(`Deleting RDS instance ${name}`, () => {
|
|
128
|
+
return getClient().send(
|
|
129
|
+
new DeleteDBInstanceCommand({
|
|
130
|
+
DBInstanceIdentifier: name,
|
|
131
|
+
SkipFinalSnapshot: true,
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
module.exports.waitForRDSDeletion = async (name) => {
|
|
138
|
+
await Spinner.prototype.simple(
|
|
139
|
+
`Waiting for RDS instance to be deleted`,
|
|
140
|
+
(spinner) => {
|
|
141
|
+
return poll(
|
|
142
|
+
async () => {
|
|
143
|
+
try {
|
|
144
|
+
const res = await getClient().send(
|
|
145
|
+
new DescribeDBInstancesCommand({
|
|
146
|
+
DBInstanceIdentifier: name,
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
return res.DBInstances[0];
|
|
150
|
+
} catch (e) {
|
|
151
|
+
if (e.name === "DBInstanceNotFoundFault") {
|
|
152
|
+
return { DBInstanceStatus: "deleted" };
|
|
153
|
+
}
|
|
154
|
+
throw e;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
({ DBInstanceStatus }) => DBInstanceStatus !== "deleted",
|
|
158
|
+
undefined,
|
|
159
|
+
spinner,
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
module.exports.listManualSnapshots = async () => {
|
|
166
|
+
const res = await Spinner.prototype.simple(
|
|
167
|
+
`Fetching manual RDS snapshots`,
|
|
168
|
+
() => {
|
|
169
|
+
return getClient().send(
|
|
170
|
+
new DescribeDBSnapshotsCommand({
|
|
171
|
+
SnapshotType: "manual",
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return (res.DBSnapshots || [])
|
|
178
|
+
.filter((s) => s.Status === "available")
|
|
179
|
+
.sort(
|
|
180
|
+
(a, b) =>
|
|
181
|
+
new Date(b.SnapshotCreateTime) - new Date(a.SnapshotCreateTime),
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
module.exports.restoreRDSInstanceFromSnapshot = async (
|
|
186
|
+
name,
|
|
187
|
+
snapshotId,
|
|
188
|
+
securityGroupId,
|
|
189
|
+
tags = [],
|
|
190
|
+
subnetGroupName,
|
|
191
|
+
) => {
|
|
192
|
+
let res = await Spinner.prototype.simple(
|
|
193
|
+
`Restoring RDS instance ${name} from snapshot ${snapshotId}`,
|
|
194
|
+
() => {
|
|
195
|
+
return getClient().send(
|
|
196
|
+
new RestoreDBInstanceFromDBSnapshotCommand({
|
|
197
|
+
DBInstanceIdentifier: name,
|
|
198
|
+
DBSnapshotIdentifier: snapshotId,
|
|
199
|
+
DBInstanceClass: "db.t3.small",
|
|
200
|
+
PubliclyAccessible: false,
|
|
201
|
+
DBParameterGroupName: "lab-env-mysql80-ssl-required",
|
|
202
|
+
DBSubnetGroupName: subnetGroupName,
|
|
203
|
+
VpcSecurityGroupIds: [securityGroupId],
|
|
204
|
+
Tags: [
|
|
205
|
+
{ Key: "client", Value: process.env.AWS_PROFILE },
|
|
206
|
+
].concat(tags),
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
return res;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
module.exports.modifyRDSPassword = async (name, password) => {
|
|
216
|
+
await Spinner.prototype.simple(
|
|
217
|
+
`Updating master password for RDS instance ${name}`,
|
|
218
|
+
() => {
|
|
219
|
+
return getClient().send(
|
|
220
|
+
new ModifyDBInstanceCommand({
|
|
221
|
+
DBInstanceIdentifier: name,
|
|
222
|
+
MasterUserPassword: password,
|
|
223
|
+
ApplyImmediately: true,
|
|
224
|
+
}),
|
|
225
|
+
);
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const SSL_PARAMETER_GROUP = "lab-env-mysql80-ssl-required";
|
|
231
|
+
|
|
232
|
+
module.exports.ensureSSLParameterGroup = async () => {
|
|
233
|
+
try {
|
|
234
|
+
await getClient().send(
|
|
235
|
+
new DescribeDBParameterGroupsCommand({
|
|
236
|
+
DBParameterGroupName: SSL_PARAMETER_GROUP,
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
} catch {
|
|
240
|
+
await Spinner.prototype.simple(
|
|
241
|
+
`Creating parameter group ${SSL_PARAMETER_GROUP}`,
|
|
242
|
+
() => {
|
|
243
|
+
return getClient().send(
|
|
244
|
+
new CreateDBParameterGroupCommand({
|
|
245
|
+
DBParameterGroupName: SSL_PARAMETER_GROUP,
|
|
246
|
+
DBParameterGroupFamily: "mysql8.0",
|
|
247
|
+
Description:
|
|
248
|
+
"lab-env managed parameter group requiring SSL connections",
|
|
249
|
+
}),
|
|
250
|
+
);
|
|
251
|
+
},
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
await Spinner.prototype.simple(
|
|
255
|
+
`Enabling require_secure_transport on ${SSL_PARAMETER_GROUP}`,
|
|
256
|
+
() => {
|
|
257
|
+
return getClient().send(
|
|
258
|
+
new ModifyDBParameterGroupCommand({
|
|
259
|
+
DBParameterGroupName: SSL_PARAMETER_GROUP,
|
|
260
|
+
Parameters: [
|
|
261
|
+
{
|
|
262
|
+
ParameterName: "require_secure_transport",
|
|
263
|
+
ParameterValue: "1",
|
|
264
|
+
ApplyMethod: "immediate",
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
},
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
@@ -12,6 +12,9 @@ const {
|
|
|
12
12
|
DeleteObjectsCommand,
|
|
13
13
|
} = require("@aws-sdk/client-s3");
|
|
14
14
|
const { Spinner } = require("../../libs/utilities");
|
|
15
|
+
const { awsClientConfig } = require("../../libs/vars");
|
|
16
|
+
|
|
17
|
+
const getClient = () => new S3Client(awsClientConfig);
|
|
15
18
|
|
|
16
19
|
module.exports.createS3Bucket = async (
|
|
17
20
|
bucket,
|
|
@@ -19,36 +22,39 @@ module.exports.createS3Bucket = async (
|
|
|
19
22
|
blockAccess = true,
|
|
20
23
|
ObjectOwnership = "BucketOwnerEnforced",
|
|
21
24
|
) => {
|
|
22
|
-
const client = new S3Client({});
|
|
23
|
-
|
|
24
25
|
let res = await Spinner.prototype.simple(
|
|
25
26
|
`Creating s3 bucket ${bucket}`,
|
|
26
27
|
() => {
|
|
27
|
-
return
|
|
28
|
+
return getClient().send(
|
|
28
29
|
new CreateBucketCommand({ Bucket: bucket, ObjectOwnership }),
|
|
29
30
|
);
|
|
30
31
|
},
|
|
31
32
|
);
|
|
32
33
|
|
|
34
|
+
const publicAccessConfig =
|
|
35
|
+
typeof blockAccess === "object"
|
|
36
|
+
? blockAccess
|
|
37
|
+
: {
|
|
38
|
+
BlockPublicAcls: blockAccess,
|
|
39
|
+
BlockPublicPolicy: blockAccess,
|
|
40
|
+
IgnorePublicAcls: blockAccess,
|
|
41
|
+
RestrictPublicBuckets: blockAccess,
|
|
42
|
+
};
|
|
43
|
+
|
|
33
44
|
await Spinner.prototype.simple(
|
|
34
|
-
|
|
45
|
+
`Configuring public access settings for s3 bucket`,
|
|
35
46
|
() => {
|
|
36
|
-
return
|
|
47
|
+
return getClient().send(
|
|
37
48
|
new PutPublicAccessBlockCommand({
|
|
38
49
|
Bucket: bucket,
|
|
39
|
-
PublicAccessBlockConfiguration:
|
|
40
|
-
BlockPublicAcls: blockAccess,
|
|
41
|
-
BlockPublicPolicy: blockAccess,
|
|
42
|
-
IgnorePublicAcls: blockAccess,
|
|
43
|
-
RestrictPublicBuckets: blockAccess,
|
|
44
|
-
},
|
|
50
|
+
PublicAccessBlockConfiguration: publicAccessConfig,
|
|
45
51
|
}),
|
|
46
52
|
);
|
|
47
53
|
},
|
|
48
54
|
);
|
|
49
55
|
|
|
50
56
|
await Spinner.prototype.simple(`Adding tags to s3 bucket`, () => {
|
|
51
|
-
return
|
|
57
|
+
return getClient().send(
|
|
52
58
|
new PutBucketTaggingCommand({
|
|
53
59
|
Bucket: bucket,
|
|
54
60
|
Tagging: {
|
|
@@ -64,30 +70,24 @@ module.exports.createS3Bucket = async (
|
|
|
64
70
|
};
|
|
65
71
|
|
|
66
72
|
module.exports.listS3Buckets = async () => {
|
|
67
|
-
const client = new S3Client({});
|
|
68
|
-
|
|
69
73
|
let res = await Spinner.prototype.simple(`Listing s3 buckets`, () => {
|
|
70
|
-
return
|
|
74
|
+
return getClient().send(new ListBucketsCommand({}));
|
|
71
75
|
});
|
|
72
76
|
|
|
73
77
|
return res;
|
|
74
78
|
};
|
|
75
79
|
|
|
76
80
|
module.exports.removeS3Bucket = async (bucket) => {
|
|
77
|
-
const client = new S3Client({});
|
|
78
|
-
|
|
79
81
|
await Spinner.prototype.simple(`Removing s3 bucket ${bucket}`, () => {
|
|
80
|
-
return
|
|
82
|
+
return getClient().send(new DeleteBucketCommand({ Bucket: bucket }));
|
|
81
83
|
});
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
module.exports.setS3BucketPolicy = async (bucket, OAI) => {
|
|
85
|
-
const client = new S3Client({});
|
|
86
|
-
|
|
87
87
|
let res = await Spinner.prototype.simple(
|
|
88
88
|
`Updating s3 bucket policy`,
|
|
89
89
|
() => {
|
|
90
|
-
return
|
|
90
|
+
return getClient().send(
|
|
91
91
|
new PutBucketPolicyCommand({
|
|
92
92
|
Bucket: bucket,
|
|
93
93
|
Policy: JSON.stringify({
|
|
@@ -116,11 +116,36 @@ module.exports.setS3BucketPolicy = async (bucket, OAI) => {
|
|
|
116
116
|
return res;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
module.exports.
|
|
120
|
-
|
|
119
|
+
module.exports.setPublicReadPolicy = async (bucket, prefix) => {
|
|
120
|
+
let res = await Spinner.prototype.simple(
|
|
121
|
+
`Setting public read policy for ${prefix}`,
|
|
122
|
+
() => {
|
|
123
|
+
return getClient().send(
|
|
124
|
+
new PutBucketPolicyCommand({
|
|
125
|
+
Bucket: bucket,
|
|
126
|
+
Policy: JSON.stringify({
|
|
127
|
+
Version: "2012-10-17",
|
|
128
|
+
Statement: [
|
|
129
|
+
{
|
|
130
|
+
Sid: "PublicReadPrefix",
|
|
131
|
+
Effect: "Allow",
|
|
132
|
+
Principal: "*",
|
|
133
|
+
Action: "s3:GetObject",
|
|
134
|
+
Resource: `arn:aws:s3:::${bucket}/${prefix}`,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
}),
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
return res;
|
|
144
|
+
};
|
|
121
145
|
|
|
146
|
+
module.exports.addFileToS3Bucket = async (bucket, filepath, file) => {
|
|
122
147
|
let res = await Spinner.prototype.simple(`Adding file to s3 bucket`, () => {
|
|
123
|
-
return
|
|
148
|
+
return getClient().send(
|
|
124
149
|
new PutObjectCommand({
|
|
125
150
|
Bucket: bucket,
|
|
126
151
|
Body: file,
|
|
@@ -133,12 +158,10 @@ module.exports.addFileToS3Bucket = async (bucket, filepath, file) => {
|
|
|
133
158
|
};
|
|
134
159
|
|
|
135
160
|
module.exports.removeFileToS3Bucket = async (bucket, filepath) => {
|
|
136
|
-
const client = new S3Client({});
|
|
137
|
-
|
|
138
161
|
let res = await Spinner.prototype.simple(
|
|
139
162
|
`Removing file from s3 bucket`,
|
|
140
163
|
() => {
|
|
141
|
-
return
|
|
164
|
+
return getClient().send(
|
|
142
165
|
new DeleteObjectCommand({
|
|
143
166
|
Bucket: bucket,
|
|
144
167
|
Key: filepath,
|
|
@@ -151,8 +174,6 @@ module.exports.removeFileToS3Bucket = async (bucket, filepath) => {
|
|
|
151
174
|
};
|
|
152
175
|
|
|
153
176
|
module.exports.emptyS3Bucket = async (bucket) => {
|
|
154
|
-
const client = new S3Client({});
|
|
155
|
-
|
|
156
177
|
await Spinner.prototype.simple(`Emptying s3 bucket`, () => {
|
|
157
178
|
// eslint-disable-next-line no-async-promise-executor
|
|
158
179
|
return new Promise(async (resolve, reject) => {
|
|
@@ -160,7 +181,7 @@ module.exports.emptyS3Bucket = async (bucket) => {
|
|
|
160
181
|
let ContinuationToken = null;
|
|
161
182
|
|
|
162
183
|
do {
|
|
163
|
-
let list = await
|
|
184
|
+
let list = await getClient().send(
|
|
164
185
|
new ListObjectsV2Command({
|
|
165
186
|
Bucket: bucket,
|
|
166
187
|
ContinuationToken,
|
|
@@ -168,7 +189,7 @@ module.exports.emptyS3Bucket = async (bucket) => {
|
|
|
168
189
|
);
|
|
169
190
|
|
|
170
191
|
if (list.KeyCount) {
|
|
171
|
-
let deleted = await
|
|
192
|
+
let deleted = await getClient().send(
|
|
172
193
|
new DeleteObjectsCommand({
|
|
173
194
|
Bucket: bucket,
|
|
174
195
|
Delete: {
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const {
|
|
2
|
+
SecretsManagerClient,
|
|
3
|
+
CreateSecretCommand,
|
|
4
|
+
DescribeSecretCommand,
|
|
5
|
+
GetSecretValueCommand,
|
|
6
|
+
PutSecretValueCommand,
|
|
7
|
+
DeleteSecretCommand,
|
|
8
|
+
} = require("@aws-sdk/client-secrets-manager");
|
|
9
|
+
const { Spinner } = require("../../libs/utilities");
|
|
10
|
+
const { awsClientConfig } = require("../../libs/vars");
|
|
11
|
+
|
|
12
|
+
const getClient = () => new SecretsManagerClient(awsClientConfig);
|
|
13
|
+
|
|
14
|
+
module.exports.createSecret = async (name, secretObject, tags = []) => {
|
|
15
|
+
let res = await Spinner.prototype.simple(`Creating secret ${name}`, () => {
|
|
16
|
+
return getClient().send(
|
|
17
|
+
new CreateSecretCommand({
|
|
18
|
+
Name: name,
|
|
19
|
+
SecretString: JSON.stringify(secretObject),
|
|
20
|
+
Tags: tags.map((t) => ({ Key: t.Key, Value: String(t.Value) })),
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return res;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports.describeSecret = async (name) => {
|
|
29
|
+
let res = await Spinner.prototype.simple(
|
|
30
|
+
`Checking for existing secret ${name}`,
|
|
31
|
+
() => {
|
|
32
|
+
return getClient().send(
|
|
33
|
+
new DescribeSecretCommand({
|
|
34
|
+
SecretId: name,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return res;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports.getSecretValue = async (name) => {
|
|
44
|
+
let res = await Spinner.prototype.simple(
|
|
45
|
+
`Retrieving secret ${name}`,
|
|
46
|
+
() => {
|
|
47
|
+
return getClient().send(
|
|
48
|
+
new GetSecretValueCommand({
|
|
49
|
+
SecretId: name,
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return JSON.parse(res.SecretString);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports.updateSecretValue = async (name, secretObject) => {
|
|
59
|
+
let res = await Spinner.prototype.simple(`Updating secret ${name}`, () => {
|
|
60
|
+
return getClient().send(
|
|
61
|
+
new PutSecretValueCommand({
|
|
62
|
+
SecretId: name,
|
|
63
|
+
SecretString: JSON.stringify(secretObject),
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return res;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
module.exports.deleteSecret = async (name) => {
|
|
72
|
+
let res = await Spinner.prototype.simple(`Deleting secret ${name}`, () => {
|
|
73
|
+
return getClient().send(
|
|
74
|
+
new DeleteSecretCommand({
|
|
75
|
+
SecretId: name,
|
|
76
|
+
ForceDeleteWithoutRecovery: true,
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return res;
|
|
82
|
+
};
|