@fishawack/lab-env 2.2.0 → 3.0.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/CHANGELOG.md +9 -0
- package/_Test/key.js +33 -0
- package/cli.js +1 -1
- package/commands/create/cmds/dekey.js +75 -0
- package/commands/create/cmds/deprovision.js +17 -16
- package/commands/create/cmds/key.js +99 -0
- package/commands/create/cmds/provision.js +2 -2
- package/commands/create/libs/aws-cloudfront-auth.js +1 -1
- package/commands/create/libs/aws-cloudfront-simple.js +1 -1
- package/commands/create/services/aws/cloudfront.js +19 -13
- package/commands/create/services/aws/iam.js +170 -0
- package/commands/create/services/aws/index.js +8 -5
- package/commands/create/services/aws/misc.js +9 -0
- package/commands/create/services/aws/s3.js +19 -10
- package/drupal/9/apache/apache.conf +1 -0
- package/drupal/9/docker-compose.yml +1 -1
- package/drupal/9/php/Dockerfile +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
+
### 3.0.0 (2022-08-17)
|
|
4
|
+
* [Feature] Added newly setup AWS accounts to the client prompts on `fw provision`
|
|
5
|
+
* [Feature] Added key/dekey commands
|
|
6
|
+
* [Change] Provisioned environment variables now append client to uniqueify the services created
|
|
7
|
+
* [Change] `fw provision` no longer does two polls to cloudfront to speed up the process
|
|
8
|
+
* [Change] Drupal now defaults to 8.1 php
|
|
9
|
+
* [Bug] Added protocol to www in cloudfront function to ensure redirect works correctly
|
|
10
|
+
* [Bug] Added posiexem to fix M1 chip issue on drupal
|
|
11
|
+
|
|
3
12
|
### 2.2.0 (2022-08-10)
|
|
4
13
|
* [Feature] Can now skip diagnose in `fw diagnose`
|
|
5
14
|
* [Feature] Can now provision AWS environments using `fw provision`
|
package/_Test/key.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const expect = require('chai').expect;
|
|
4
|
+
const aws = require("../commands/create/services/aws/index.js");
|
|
5
|
+
|
|
6
|
+
describe('key', async () => {
|
|
7
|
+
let account = 'fishawack';
|
|
8
|
+
|
|
9
|
+
before(async () => {
|
|
10
|
+
let res = await aws.iam.createFWIAMUser('fw-test-user', account);
|
|
11
|
+
|
|
12
|
+
// Wait for key as AWS doesn't provide a way to wait for it to becom eactive
|
|
13
|
+
await new Promise(resolve => setTimeout(() => resolve(), 10000));
|
|
14
|
+
|
|
15
|
+
process.env.AWS_ACCESS_KEY_ID = res.AccessKey.AccessKeyId;
|
|
16
|
+
process.env.AWS_SECRET_ACCESS_KEY = res.AccessKey.SecretAccessKey;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('Should be able to access AWS service', async () => {
|
|
20
|
+
let res;
|
|
21
|
+
|
|
22
|
+
try{ res = await aws.s3.listS3Buckets(); } catch(e){ console.log(e.message); }
|
|
23
|
+
|
|
24
|
+
expect(res).to.not.be.undefined;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
after(async () => {
|
|
28
|
+
delete process.env.AWS_ACCESS_KEY_ID;
|
|
29
|
+
delete process.env.AWS_SECRET_ACCESS_KEY;
|
|
30
|
+
|
|
31
|
+
await aws.iam.removeIAMUser('fw-test-user', account);
|
|
32
|
+
});
|
|
33
|
+
});
|
package/cli.js
CHANGED
|
@@ -59,7 +59,7 @@ if(!_.services && !(args[0] === 'origin' || args[0] === '--version')) process.ex
|
|
|
59
59
|
['build', 'config', 'down', 'mocha', 'rebuild', 'up', 'volumes', 'compose'].forEach(d => cli.command(...require(`./commands/docker/${d}.js`)));
|
|
60
60
|
|
|
61
61
|
// Create commands
|
|
62
|
-
['new', 'provision', 'deprovision', 'diagnose', 'delete'].forEach(d => cli.command(...require(`./commands/create/cmds/${d}.js`)));
|
|
62
|
+
['new', 'provision', 'deprovision', 'diagnose', 'delete', 'key', 'dekey'].forEach(d => cli.command(...require(`./commands/create/cmds/${d}.js`)));
|
|
63
63
|
|
|
64
64
|
cli.demandCommand(1, '')
|
|
65
65
|
.wrap(null)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const _ = require('../../../globals.js');
|
|
2
|
+
const utilities = require('../libs/utilities');
|
|
3
|
+
const inquirer = require('inquirer');
|
|
4
|
+
const aws = require('../services/aws/index.js');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
module.exports = [
|
|
9
|
+
'dekey',
|
|
10
|
+
false,
|
|
11
|
+
yargs => {},
|
|
12
|
+
async argv => {
|
|
13
|
+
let config = JSON.parse(fs.readFileSync(`${os.homedir()}/.lab-env`, {encoding: 'utf8'}));
|
|
14
|
+
let users = [];
|
|
15
|
+
let clients = [];
|
|
16
|
+
|
|
17
|
+
let answer = await inquirer.prompt([
|
|
18
|
+
{
|
|
19
|
+
type: 'confirm',
|
|
20
|
+
name: 'check',
|
|
21
|
+
message: `Remove keys for all users`,
|
|
22
|
+
default: 'Y'
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
if(answer.check){
|
|
27
|
+
users = config.users.map(d => d.username);
|
|
28
|
+
} else {
|
|
29
|
+
answer = await inquirer.prompt([
|
|
30
|
+
{
|
|
31
|
+
type: 'checkbox',
|
|
32
|
+
name: 'users',
|
|
33
|
+
message: 'Select users',
|
|
34
|
+
choices: config.users.map(d => d.username)
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
users = answer.users;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
answer = await inquirer.prompt([
|
|
42
|
+
{
|
|
43
|
+
type: 'confirm',
|
|
44
|
+
name: 'check',
|
|
45
|
+
message: `Remove keys for all clients`,
|
|
46
|
+
default: 'Y'
|
|
47
|
+
}
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
if(answer.check){
|
|
51
|
+
clients = aws.clients;
|
|
52
|
+
} else {
|
|
53
|
+
answer = await inquirer.prompt([
|
|
54
|
+
{
|
|
55
|
+
type: 'checkbox',
|
|
56
|
+
name: 'clients',
|
|
57
|
+
message: 'Select clients',
|
|
58
|
+
choices: aws.clients
|
|
59
|
+
}
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
clients = answer.clients;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for(let i = 0; i < clients.length; i++){
|
|
66
|
+
let client = clients[i];
|
|
67
|
+
|
|
68
|
+
for(let j = 0; j < users.length; j++){
|
|
69
|
+
let user = users[j];
|
|
70
|
+
|
|
71
|
+
await aws.iam.removeIAMUser(`fw-automation-${user}`, client);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const _ = require('../../../globals.js');
|
|
2
2
|
const inquirer = require('inquirer');
|
|
3
3
|
const aws = require('../services/aws/index.js');
|
|
4
|
+
const utilities = require('../libs/utilities');
|
|
4
5
|
|
|
5
6
|
module.exports = [
|
|
6
7
|
['deprovision', 'deprov'],
|
|
@@ -14,19 +15,6 @@ module.exports = [
|
|
|
14
15
|
},
|
|
15
16
|
async argv => {
|
|
16
17
|
let branch = argv.branch || _.branch;
|
|
17
|
-
|
|
18
|
-
let answer = await inquirer.prompt([
|
|
19
|
-
{
|
|
20
|
-
type: 'confirm',
|
|
21
|
-
name: 'check',
|
|
22
|
-
message: `Deprovisioning fw-auto-${_.repo}-${branch}, are you sure you want to continue?`,
|
|
23
|
-
default: 'Y'
|
|
24
|
-
}
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
if(!answer.check){
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
18
|
|
|
31
19
|
const answers = await inquirer.prompt([
|
|
32
20
|
{
|
|
@@ -39,15 +27,28 @@ module.exports = [
|
|
|
39
27
|
type: 'list',
|
|
40
28
|
name: 'client',
|
|
41
29
|
message: 'Which AWS account is this deployed too?',
|
|
42
|
-
choices:
|
|
30
|
+
choices: aws.clients,
|
|
43
31
|
default: 'fishawack'
|
|
44
32
|
}
|
|
45
33
|
]);
|
|
46
34
|
|
|
47
|
-
|
|
35
|
+
let answer = await inquirer.prompt([
|
|
36
|
+
{
|
|
37
|
+
type: 'confirm',
|
|
38
|
+
name: 'check',
|
|
39
|
+
message: `Deprovisioning ${utilities.colorize(aws.slug(_.repo, answers.client, branch), 'error')} from ${utilities.colorize(answers.client, 'error')} AWS account, are you sure you want to continue?`,
|
|
40
|
+
default: false
|
|
41
|
+
}
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
if(!answer.check){
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try { await aws.s3.removeS3Bucket(aws.slug(_.repo, answers.client, branch), answers.client); } catch(e) {}
|
|
48
49
|
|
|
49
50
|
try { await aws.cloudfront.removeCloudFrontDistribution(answers.id, answers.client); } catch(e) {}
|
|
50
51
|
|
|
51
|
-
try { await aws.cloudfront.removeCloudFrontFunction(
|
|
52
|
+
try { await aws.cloudfront.removeCloudFrontFunction(aws.slug(_.repo, answers.client, branch), answers.client); } catch(e) {}
|
|
52
53
|
}
|
|
53
54
|
];
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const _ = require('../../../globals.js');
|
|
2
|
+
const utilities = require('../libs/utilities');
|
|
3
|
+
const inquirer = require('inquirer');
|
|
4
|
+
const aws = require('../services/aws/index.js');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
module.exports = [
|
|
9
|
+
'key',
|
|
10
|
+
false,
|
|
11
|
+
yargs => {},
|
|
12
|
+
async argv => {
|
|
13
|
+
let config = JSON.parse(fs.readFileSync(`${os.homedir()}/.lab-env`, {encoding: 'utf8'}));
|
|
14
|
+
let users = [];
|
|
15
|
+
let clients = [];
|
|
16
|
+
|
|
17
|
+
let answer = await inquirer.prompt([
|
|
18
|
+
{
|
|
19
|
+
type: 'confirm',
|
|
20
|
+
name: 'check',
|
|
21
|
+
message: `Set keys for all users`,
|
|
22
|
+
default: 'Y'
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
if(answer.check){
|
|
27
|
+
users = config.users.map(d => d.username);
|
|
28
|
+
} else {
|
|
29
|
+
answer = await inquirer.prompt([
|
|
30
|
+
{
|
|
31
|
+
type: 'checkbox',
|
|
32
|
+
name: 'users',
|
|
33
|
+
message: 'Select users',
|
|
34
|
+
choices: config.users.map(d => d.username)
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
users = answer.users;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
answer = await inquirer.prompt([
|
|
42
|
+
{
|
|
43
|
+
type: 'confirm',
|
|
44
|
+
name: 'check',
|
|
45
|
+
message: `Set keys for all clients`,
|
|
46
|
+
default: 'Y'
|
|
47
|
+
}
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
if(answer.check){
|
|
51
|
+
clients = aws.clients;
|
|
52
|
+
} else {
|
|
53
|
+
answer = await inquirer.prompt([
|
|
54
|
+
{
|
|
55
|
+
type: 'checkbox',
|
|
56
|
+
name: 'clients',
|
|
57
|
+
message: 'Select clients',
|
|
58
|
+
choices: aws.clients
|
|
59
|
+
}
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
clients = answer.clients;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let credentials = {};
|
|
66
|
+
|
|
67
|
+
for(let i = 0; i < clients.length; i++){
|
|
68
|
+
let client = clients[i];
|
|
69
|
+
|
|
70
|
+
for(let j = 0; j < users.length; j++){
|
|
71
|
+
let user = users[j];
|
|
72
|
+
|
|
73
|
+
if(!credentials[user]){
|
|
74
|
+
credentials[user] = {};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let res = await aws.iam.createFWIAMUser(`fw-automation-${user}`, client);
|
|
78
|
+
|
|
79
|
+
credentials[user][client] = {
|
|
80
|
+
key: res.AccessKey && res.AccessKey.AccessKeyId || res.AccessKeyMetadata[0].AccessKeyId,
|
|
81
|
+
secret: res.AccessKey && res.AccessKey.SecretAccessKey || '** secret **'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let output = '';
|
|
87
|
+
|
|
88
|
+
for(var user in credentials){
|
|
89
|
+
output += utilities.colorize(`\n${user}\n`, 'title');
|
|
90
|
+
for(var client in credentials[user]){
|
|
91
|
+
output += `\n[${client}]\n`;
|
|
92
|
+
output += `aws_access_key_id = ${credentials[user][client].key}\n`;
|
|
93
|
+
output += `aws_secret_access_key = ${credentials[user][client].secret}\n`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log(output);
|
|
98
|
+
}
|
|
99
|
+
];
|
|
@@ -43,7 +43,7 @@ module.exports = [
|
|
|
43
43
|
type: 'list',
|
|
44
44
|
name: 'client',
|
|
45
45
|
message: 'Which AWS account should this be deployed too?',
|
|
46
|
-
choices:
|
|
46
|
+
choices: aws.clients,
|
|
47
47
|
default: 'fishawack'
|
|
48
48
|
},
|
|
49
49
|
{
|
|
@@ -93,7 +93,7 @@ module.exports = [
|
|
|
93
93
|
let infastructure;
|
|
94
94
|
|
|
95
95
|
try{
|
|
96
|
-
infastructure = await aws.static(
|
|
96
|
+
infastructure = await aws.static(aws.slug(_.repo, answers.client, branch), answers.client, [{Key: 'repository', Value: _.repo}, {Key: 'environment', Value: branch}], credentials);
|
|
97
97
|
} catch(e){
|
|
98
98
|
console.log(e.message);
|
|
99
99
|
process.exit(1);
|
|
@@ -12,7 +12,7 @@ function handler(event) {
|
|
|
12
12
|
var response = {
|
|
13
13
|
statusCode: 301,
|
|
14
14
|
statusDescription: 'Moved Permanently',
|
|
15
|
-
headers: { "location": { "value":
|
|
15
|
+
headers: { "location": { "value": `https://${event.request.headers.host.value.split('www.')[1]}${event.request.uri}${query}` } }
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
return response;
|
|
@@ -12,7 +12,7 @@ function handler(event) {
|
|
|
12
12
|
var response = {
|
|
13
13
|
statusCode: 301,
|
|
14
14
|
statusDescription: 'Moved Permanently',
|
|
15
|
-
headers: { "location": { "value":
|
|
15
|
+
headers: { "location": { "value": `https://${event.request.headers.host.value.split('www.')[1]}${event.request.uri}${query}` } }
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
return response;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
const { CloudFrontClient, CreateDistributionWithTagsCommand, CreateCloudFrontOriginAccessIdentityCommand, DeleteDistributionCommand , DeleteCloudFrontOriginAccessIdentityCommand, GetDistributionCommand, UpdateDistributionCommand, GetCloudFrontOriginAccessIdentityCommand, CreateFunctionCommand, GetFunctionCommand, UpdateFunctionCommand, PublishFunctionCommand, DeleteFunctionCommand, DescribeFunctionCommand } = require("@aws-sdk/client-cloudfront");
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const { Spinner } = require('../../libs/utilities');
|
|
4
|
+
const { createClient } = require('./misc.js');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const client = new CloudFrontClient({ region });
|
|
8
|
-
|
|
9
|
-
module.exports.createCloudFrontDistribution = async (name, account, tags = []) => {
|
|
10
|
-
process.env.AWS_PROFILE = account;
|
|
6
|
+
module.exports.createCloudFrontDistribution = async (name, account, tags = [], FunctionARN = null, region = 'us-east-1') => {
|
|
7
|
+
const client = createClient(CloudFrontClient, account, region);
|
|
11
8
|
|
|
12
9
|
let OAI = await Spinner.prototype.simple(`Creating CloudFront OAI`, () => {
|
|
13
10
|
return client.send(
|
|
@@ -46,7 +43,16 @@ module.exports.createCloudFrontDistribution = async (name, account, tags = []) =
|
|
|
46
43
|
Compress: true,
|
|
47
44
|
TargetOriginId: `${name}.s3.${region}.amazonaws.com`,
|
|
48
45
|
ViewerProtocolPolicy: 'redirect-to-https',
|
|
49
|
-
CachePolicyId: '658327ea-f89d-4fab-a63d-7e88639e58f6' // Built in, Managed AWS Policy - Cache Optimized
|
|
46
|
+
CachePolicyId: '658327ea-f89d-4fab-a63d-7e88639e58f6', // Built in, Managed AWS Policy - Cache Optimized
|
|
47
|
+
FunctionAssociations: FunctionARN && {
|
|
48
|
+
Items: [
|
|
49
|
+
{
|
|
50
|
+
EventType: 'viewer-request',
|
|
51
|
+
FunctionARN
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
Quantity: 1
|
|
55
|
+
}
|
|
50
56
|
},
|
|
51
57
|
Origins: {
|
|
52
58
|
Items: [
|
|
@@ -86,7 +92,7 @@ module.exports.createCloudFrontDistribution = async (name, account, tags = []) =
|
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
module.exports.removeCloudFrontDistribution = async (Id, account) => {
|
|
89
|
-
|
|
95
|
+
const client = createClient(CloudFrontClient, account);
|
|
90
96
|
|
|
91
97
|
let res = await Spinner.prototype.simple(`Retrieving the CloudFront distribution ${Id}`, () => {
|
|
92
98
|
return client.send(
|
|
@@ -128,7 +134,7 @@ module.exports.removeCloudFrontDistribution = async (Id, account) => {
|
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
module.exports.waitForCloudFrontDistribution = async (Id, account) => {
|
|
131
|
-
|
|
137
|
+
const client = createClient(CloudFrontClient, account);
|
|
132
138
|
|
|
133
139
|
let status;
|
|
134
140
|
|
|
@@ -146,7 +152,7 @@ module.exports.waitForCloudFrontDistribution = async (Id, account) => {
|
|
|
146
152
|
}
|
|
147
153
|
|
|
148
154
|
module.exports.createCloudFrontFunction = async (name, account, fn, config) => {
|
|
149
|
-
|
|
155
|
+
const client = createClient(CloudFrontClient, account);
|
|
150
156
|
|
|
151
157
|
let FunctionConfig = {
|
|
152
158
|
Comment: `lab-env provisioned cloudfront function for project ${name} using code snippet ${fn}.js`,
|
|
@@ -202,7 +208,7 @@ module.exports.createCloudFrontFunction = async (name, account, fn, config) => {
|
|
|
202
208
|
}
|
|
203
209
|
|
|
204
210
|
module.exports.removeCloudFrontFunction = async (name, account) => {
|
|
205
|
-
|
|
211
|
+
const client = createClient(CloudFrontClient, account);
|
|
206
212
|
|
|
207
213
|
let res = await Spinner.prototype.simple(`Retrieving CloudFront function`, () => {
|
|
208
214
|
return client.send(
|
|
@@ -225,7 +231,7 @@ module.exports.removeCloudFrontFunction = async (name, account) => {
|
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
module.exports.setCloudFrontFunctionAssociation = async (Id, account) => {
|
|
228
|
-
|
|
234
|
+
const client = createClient(CloudFrontClient, account);
|
|
229
235
|
|
|
230
236
|
let res = await Spinner.prototype.simple(`Retrieving CloudFront distribution`, () => {
|
|
231
237
|
return client.send(
|
|
@@ -264,7 +270,7 @@ module.exports.setCloudFrontFunctionAssociation = async (Id, account) => {
|
|
|
264
270
|
};
|
|
265
271
|
|
|
266
272
|
module.exports.removeCloudFrontFunctionAssociation = async (Id, account) => {
|
|
267
|
-
|
|
273
|
+
const client = createClient(CloudFrontClient, account);
|
|
268
274
|
|
|
269
275
|
let res = await Spinner.prototype.simple(`Retrieving CloudFront distribution`, () => {
|
|
270
276
|
return client.send(
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
const { IAMClient, CreateUserCommand, GetUserCommand, DeleteUserCommand, AttachUserPolicyCommand, ListAttachedUserPoliciesCommand, DetachUserPolicyCommand, CreateAccessKeyCommand, DeleteAccessKeyCommand, ListAccessKeysCommand } = require("@aws-sdk/client-iam");
|
|
2
|
+
const { Spinner } = require('../../libs/utilities');
|
|
3
|
+
const { createClient } = require('./misc.js');
|
|
4
|
+
|
|
5
|
+
module.exports.createIAMUser = async (UserName, account) => {
|
|
6
|
+
const client = createClient(IAMClient, account);
|
|
7
|
+
|
|
8
|
+
let res;
|
|
9
|
+
|
|
10
|
+
try{
|
|
11
|
+
res = await Spinner.prototype.simple(`Creating IAM user ${UserName}`, () => {
|
|
12
|
+
return client.send(
|
|
13
|
+
new CreateUserCommand({ UserName })
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
} catch(e){
|
|
17
|
+
res = await Spinner.prototype.simple(`Retrieving the already existing IAM user ${UserName}`, () => {
|
|
18
|
+
return client.send(
|
|
19
|
+
new GetUserCommand({ UserName })
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return res;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports.createFWIAMUser = async (UserName, account) => {
|
|
28
|
+
await module.exports.createIAMUser(UserName, account);
|
|
29
|
+
|
|
30
|
+
await module.exports.syncFWIAMPolicies(UserName, account);
|
|
31
|
+
|
|
32
|
+
let res = await module.exports.createAccessKeySafe(UserName, account);
|
|
33
|
+
|
|
34
|
+
return res;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports.removeIAMUser = async (UserName, account) => {
|
|
38
|
+
const client = createClient(IAMClient, account);
|
|
39
|
+
|
|
40
|
+
let res;
|
|
41
|
+
|
|
42
|
+
try{
|
|
43
|
+
await Spinner.prototype.simple(`Checking if IAM user ${UserName} exists`, () => {
|
|
44
|
+
return client.send(
|
|
45
|
+
new GetUserCommand({ UserName })
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await module.exports.removeAllIAMPolicies(UserName, account);
|
|
50
|
+
|
|
51
|
+
await module.exports.removeAllAccessKeys(UserName, account);
|
|
52
|
+
|
|
53
|
+
res = await Spinner.prototype.simple(`Removing IAM user ${UserName}`, () => {
|
|
54
|
+
return client.send(
|
|
55
|
+
new DeleteUserCommand({ UserName })
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
} catch(e){
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return res;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports.attachIAMPolicy = async (UserName, account, policy) => {
|
|
65
|
+
const client = createClient(IAMClient, account);
|
|
66
|
+
|
|
67
|
+
let res = await Spinner.prototype.simple(`Attaching IAM policy ${policy}`, () => {
|
|
68
|
+
return client.send(
|
|
69
|
+
new AttachUserPolicyCommand({ UserName, PolicyArn: policy })
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return res;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
module.exports.syncFWIAMPolicies = async (UserName, account) => {
|
|
77
|
+
await module.exports.removeAllIAMPolicies(UserName, account);
|
|
78
|
+
await module.exports.attachIAMPolicy(UserName, account, 'arn:aws:iam::aws:policy/AmazonS3FullAccess');
|
|
79
|
+
await module.exports.attachIAMPolicy(UserName, account, 'arn:aws:iam::aws:policy/CloudFrontFullAccess');
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports.removeIAMPolicy = async (UserName, account, policy) => {
|
|
83
|
+
const client = createClient(IAMClient, account);
|
|
84
|
+
|
|
85
|
+
let res = await Spinner.prototype.simple(`Detaching IAM policy ${policy}`, () => {
|
|
86
|
+
return client.send(
|
|
87
|
+
new DetachUserPolicyCommand({ UserName, PolicyArn: policy })
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return res;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
module.exports.listIAMPolicies = async (UserName, account) => {
|
|
95
|
+
const client = createClient(IAMClient, account);
|
|
96
|
+
|
|
97
|
+
let res = await Spinner.prototype.simple(`Listing IAM policies`, () => {
|
|
98
|
+
return client.send(
|
|
99
|
+
new ListAttachedUserPoliciesCommand({ UserName })
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return res;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
module.exports.removeAllIAMPolicies = async (UserName, account) => {
|
|
107
|
+
let res = await module.exports.listIAMPolicies(UserName, account);
|
|
108
|
+
|
|
109
|
+
for(let i = 0; i < res.AttachedPolicies.length; i++){
|
|
110
|
+
await module.exports.removeIAMPolicy(UserName, account, res.AttachedPolicies[i].PolicyArn);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return res;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
module.exports.createAccessKey = async (UserName, account) => {
|
|
117
|
+
const client = createClient(IAMClient, account);
|
|
118
|
+
|
|
119
|
+
let res = await Spinner.prototype.simple(`Creating access key`, () => {
|
|
120
|
+
return client.send(
|
|
121
|
+
new CreateAccessKeyCommand({ UserName })
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return res;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
module.exports.removeAccessKey = async (UserName, account, AccessKeyId) => {
|
|
129
|
+
const client = createClient(IAMClient, account);
|
|
130
|
+
|
|
131
|
+
let res = await Spinner.prototype.simple(`Removing access key ${AccessKeyId}`, () => {
|
|
132
|
+
return client.send(
|
|
133
|
+
new DeleteAccessKeyCommand({ AccessKeyId, UserName })
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return res;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
module.exports.listAccessKeys = async (UserName, account) => {
|
|
141
|
+
const client = createClient(IAMClient, account);
|
|
142
|
+
|
|
143
|
+
let res = await Spinner.prototype.simple(`Listing access keys`, () => {
|
|
144
|
+
return client.send(
|
|
145
|
+
new ListAccessKeysCommand({ UserName })
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
return res;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
module.exports.removeAllAccessKeys = async (UserName, account) => {
|
|
153
|
+
let res = await module.exports.listAccessKeys(UserName, account);
|
|
154
|
+
|
|
155
|
+
for(let i = 0; i < res.AccessKeyMetadata.length; i++){
|
|
156
|
+
await module.exports.removeAccessKey(UserName, account, res.AccessKeyMetadata[i].AccessKeyId);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return res;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
module.exports.createAccessKeySafe = async (UserName, account) => {
|
|
163
|
+
let res = await module.exports.listAccessKeys(UserName, account);
|
|
164
|
+
|
|
165
|
+
if(!res.AccessKeyMetadata.length){
|
|
166
|
+
res = await module.exports.createAccessKey(UserName, account);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return res;
|
|
170
|
+
};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
module.exports.s3 = require("./s3.js");
|
|
2
2
|
module.exports.cloudfront = require("./cloudfront.js");
|
|
3
|
+
module.exports.iam = require("./iam.js");
|
|
4
|
+
|
|
5
|
+
module.exports.slug = (repo, client, branch) => `fw-auto-${client}-${repo}-${branch}`;
|
|
6
|
+
|
|
7
|
+
module.exports.clients = ['fishawack', 'abbvie', 'sanofigenzyme', 'gsk', 'janssen', 'astrazeneca', 'ptc', 'jazz', 'pfizer', 'heron', 'novartis', 'training'];
|
|
3
8
|
|
|
4
9
|
module.exports.static = async (name, account, tags = [], credentials = []) => {
|
|
5
10
|
let s3 = await module.exports.s3.createS3Bucket(name, account, tags);
|
|
6
11
|
|
|
7
|
-
let
|
|
12
|
+
let cloudfrontFunction = await module.exports.cloudfront.createCloudFrontFunction(name, account, credentials.length ? 'aws-cloudfront-auth' : 'aws-cloudfront-simple', {credentials: credentials.map(d => `Basic ${Buffer.from(`${d.username}:${d.password}`).toString('base64')}`)});
|
|
8
13
|
|
|
9
|
-
await module.exports.
|
|
14
|
+
let cloudfront = await module.exports.cloudfront.createCloudFrontDistribution(name, account, tags, cloudfrontFunction.FunctionSummary.FunctionMetadata.FunctionARN);
|
|
10
15
|
|
|
11
|
-
await module.exports.
|
|
12
|
-
|
|
13
|
-
await module.exports.cloudfront.setCloudFrontFunctionAssociation(cloudfront.Distribution.Id, account);
|
|
16
|
+
await module.exports.s3.setS3BucketPolicy(name, account, cloudfront.Distribution.DistributionConfig.Origins.Items[0].S3OriginConfig.OriginAccessIdentity.split('origin-access-identity/cloudfront/')[1]);
|
|
14
17
|
|
|
15
18
|
let config = {
|
|
16
19
|
"bucket": s3.Location,
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
const { S3Client, CreateBucketCommand, DeleteBucketCommand, PutPublicAccessBlockCommand, PutBucketTaggingCommand, PutBucketPolicyCommand, PutObjectCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3");
|
|
1
|
+
const { S3Client, CreateBucketCommand, DeleteBucketCommand, ListBucketsCommand, PutPublicAccessBlockCommand, PutBucketTaggingCommand, PutBucketPolicyCommand, PutObjectCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3");
|
|
2
2
|
const { Spinner } = require('../../libs/utilities');
|
|
3
|
-
|
|
4
|
-
let region = `us-east-1`;
|
|
5
|
-
|
|
6
|
-
const client = new S3Client({ region });
|
|
3
|
+
const { createClient } = require('./misc.js');
|
|
7
4
|
|
|
8
5
|
module.exports.createS3Bucket = async (bucket, account, tags = []) => {
|
|
9
|
-
|
|
6
|
+
const client = createClient(S3Client, account);
|
|
10
7
|
|
|
11
8
|
let res = await Spinner.prototype.simple(`Creating s3 bucket ${bucket}`, () => {
|
|
12
9
|
return client.send(
|
|
@@ -29,8 +26,20 @@ module.exports.createS3Bucket = async (bucket, account, tags = []) => {
|
|
|
29
26
|
return res;
|
|
30
27
|
}
|
|
31
28
|
|
|
29
|
+
module.exports.listS3Buckets = async (account) => {
|
|
30
|
+
const client = createClient(S3Client, account);
|
|
31
|
+
|
|
32
|
+
let res = await Spinner.prototype.simple(`Listing s3 buckets`, () => {
|
|
33
|
+
return client.send(
|
|
34
|
+
new ListBucketsCommand({})
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
module.exports.removeS3Bucket = async (bucket, account) => {
|
|
33
|
-
|
|
42
|
+
const client = createClient(S3Client, account);
|
|
34
43
|
|
|
35
44
|
await Spinner.prototype.simple(`Removing s3 bucket ${bucket}`, () => {
|
|
36
45
|
return client.send(
|
|
@@ -40,7 +49,7 @@ module.exports.removeS3Bucket = async (bucket, account) => {
|
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
module.exports.setS3BucketPolicy = async (bucket, account, OAI) => {
|
|
43
|
-
|
|
52
|
+
const client = createClient(S3Client, account);
|
|
44
53
|
|
|
45
54
|
let res = await Spinner.prototype.simple(`Updating s3 bucket policy`, () => {
|
|
46
55
|
return client.send(
|
|
@@ -69,7 +78,7 @@ module.exports.setS3BucketPolicy = async (bucket, account, OAI) => {
|
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
module.exports.addFileToS3Bucket = async (bucket, account, filepath, file) => {
|
|
72
|
-
|
|
81
|
+
const client = createClient(S3Client, account);
|
|
73
82
|
|
|
74
83
|
let res = await Spinner.prototype.simple(`Adding file to s3 bucket`, () => {
|
|
75
84
|
return client.send(
|
|
@@ -85,7 +94,7 @@ module.exports.addFileToS3Bucket = async (bucket, account, filepath, file) => {
|
|
|
85
94
|
};
|
|
86
95
|
|
|
87
96
|
module.exports.removeFileToS3Bucket = async (bucket, account, filepath) => {
|
|
88
|
-
|
|
97
|
+
const client = createClient(S3Client, account);
|
|
89
98
|
|
|
90
99
|
let res = await Spinner.prototype.simple(`Removing file from s3 bucket`, () => {
|
|
91
100
|
return client.send(
|
package/drupal/9/php/Dockerfile
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fishawack/lab-env",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Docker manager for FW",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@aws-sdk/client-cloudfront": "^3.141.0",
|
|
26
|
+
"@aws-sdk/client-iam": "^3.150.0",
|
|
26
27
|
"@aws-sdk/client-s3": "^3.141.0",
|
|
27
28
|
"axios": "^0.21.4",
|
|
28
29
|
"chalk": "4.1.0",
|