cloudmason 0.0.1 → 1.0.2
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/.github/workflows/CODEOWNERS +1 -0
- package/.github/workflows/main.yml +27 -27
- package/README.md +373 -25
- package/build.js +20 -20
- package/commands/delete.js +67 -28
- package/commands/helpers/cf.js +181 -117
- package/commands/helpers/common.js +82 -0
- package/commands/helpers/ec2.js +154 -40
- package/commands/helpers/params.js +231 -178
- package/commands/helpers/s3.js +186 -67
- package/commands/helpers/stacks/asg.yaml +420 -224
- package/commands/helpers/stacks/infra.yaml +102 -106
- package/commands/helpers/stacks.js +25 -25
- package/commands/index.html +22 -0
- package/commands/init_org.js +54 -61
- package/commands/inspect.js +40 -0
- package/commands/launch_app.js +80 -57
- package/commands/list_apps.js +21 -21
- package/commands/new_app.js +44 -50
- package/commands/new_instance.js +133 -186
- package/commands/reset_stack.js +27 -27
- package/commands/starter.js +21 -0
- package/commands/starters/asg_node/index.js +62 -0
- package/commands/starters/asg_node/mason.txt +1 -0
- package/commands/starters/asg_node/modules/appConfig.js +131 -0
- package/commands/starters/asg_node/package-lock.json +5877 -0
- package/commands/starters/asg_node/package.json +23 -0
- package/commands/starters/asg_node/public/css/favicon-16x16.png +0 -0
- package/commands/starters/asg_node/public/css/fonts/Lato-Bold.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/Lato-Regular.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/Montserrat-Var.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/OpenSans.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/bpmn.woff2 +0 -0
- package/commands/starters/asg_node/public/css/fonts/fonts.css +17 -0
- package/commands/starters/asg_node/public/css/index.css +9 -0
- package/commands/starters/asg_node/public/index.html +15 -0
- package/commands/starters/asg_node/public/js/index.js +5 -0
- package/commands/starters/asg_node/start.sh +4 -0
- package/commands/update_app.js +235 -272
- package/commands/update_stack.js +27 -0
- package/commands/utils.js +32 -32
- package/main.js +262 -220
- package/package.json +1 -28
- package/test.bat +16 -9
- package/commands/delete_app.js +0 -28
- package/commands/helpers/stacks/asg_draft.json +0 -321
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const { SSMClient,GetParametersByPathCommand } = require("@aws-sdk/client-ssm");
|
|
2
|
+
const { S3Client, PutObjectCommand, ListObjectsV2Command } = require("@aws-sdk/client-s3");
|
|
3
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
4
|
+
const { DynamoDBDocumentClient, QueryCommand } = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
|
|
6
|
+
const fetch = require('node-fetch');
|
|
7
|
+
const JWS = require('jws');
|
|
8
|
+
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.setParams = async function(rootDir){
|
|
14
|
+
console.log('Setting Params');
|
|
15
|
+
// Read App Name and Region from mason.txt
|
|
16
|
+
const configPath = path.resolve(rootDir,'mason.txt');
|
|
17
|
+
const configText = fs.readFileSync(configPath,'utf-8');
|
|
18
|
+
const configLines = configText.split(',');
|
|
19
|
+
process.env.$APP_REGION = configLines[0].trim();
|
|
20
|
+
process.env.$APP_ID = configLines[1].trim();
|
|
21
|
+
process.env.$IS_LOCAL = configLines[2] ? 'y' : '';
|
|
22
|
+
process.env.$APP_ENV = configLines[2].trim()
|
|
23
|
+
console.log(`REGION: ${process.env.$APP_REGION} APP_ID: ${process.env.$APP_ID} LOCAL: ${process.env.$IS_LOCAL}`)
|
|
24
|
+
|
|
25
|
+
// Get the parameters from SSM
|
|
26
|
+
const ssmClient = new SSMClient({ region: process.env.$APP_REGION }); // Set your preferred region
|
|
27
|
+
const pathPrefix = `/${process.env.$APP_ID}/`;
|
|
28
|
+
const parameters = [];
|
|
29
|
+
let nextToken;
|
|
30
|
+
|
|
31
|
+
do {
|
|
32
|
+
const response = await ssmClient.send(new GetParametersByPathCommand({
|
|
33
|
+
Path: pathPrefix,
|
|
34
|
+
NextToken: nextToken
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
if (response.Parameters) {
|
|
38
|
+
parameters.push(...response.Parameters);
|
|
39
|
+
}
|
|
40
|
+
nextToken = response.NextToken;
|
|
41
|
+
|
|
42
|
+
} while (nextToken);
|
|
43
|
+
// Set Params to ENV
|
|
44
|
+
parameters.forEach(p=>{
|
|
45
|
+
const pname = p.Name.replace(`/${process.env.$APP_ID}/`,'');
|
|
46
|
+
const key = `$APP_${pname.toUpperCase()}`;
|
|
47
|
+
process.env[key] = p.Value;
|
|
48
|
+
});
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.verifyUser = async function(req,res,next){
|
|
53
|
+
// Return Mock User if Local
|
|
54
|
+
if (process.env.$APP_ENV == 'local') {
|
|
55
|
+
res.locals.user = {
|
|
56
|
+
ok: true,
|
|
57
|
+
email: 'test@example.com',
|
|
58
|
+
groups: ['user-admin']
|
|
59
|
+
};
|
|
60
|
+
return next();
|
|
61
|
+
}
|
|
62
|
+
if (!req.headers['x-amzn-oidc-data']){
|
|
63
|
+
res.status(200).send('OK');
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Extract User Info from Access Token
|
|
68
|
+
const accessJWT = decode(req.headers['x-amzn-oidc-accesstoken'],1);
|
|
69
|
+
res.locals.user = {
|
|
70
|
+
username: accessJWT.username,
|
|
71
|
+
groups: accessJWT['cognito:groups']
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Parse Data Token
|
|
75
|
+
const dataJWT = decode(req.headers['x-amzn-oidc-data'],1);
|
|
76
|
+
res.locals.user.email = dataJWT.email;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// Verify Token
|
|
80
|
+
const { kid } = decode(req.headers['x-amzn-oidc-data'],0);
|
|
81
|
+
const verificationURL = `https://public-keys.auth.elb.${process.env.$APP_REGION}.amazonaws.com/${kid}`
|
|
82
|
+
const pbRes = await fetch(verificationURL);
|
|
83
|
+
const pubKey = await pbRes.text();
|
|
84
|
+
const isValid = JWS.verify(req.headers['x-amzn-oidc-data'],'ES256', pubKey);
|
|
85
|
+
if (!isValid) {
|
|
86
|
+
req.status(403).send('Forbidden: Invalid Token');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
return next();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.checkDDBConnection = async function(){
|
|
93
|
+
const client = new DynamoDBClient({ region: process.env.$APP_REGION }); // Replace with your region
|
|
94
|
+
const ddbDocClient = DynamoDBDocumentClient.from(client);
|
|
95
|
+
try {
|
|
96
|
+
const params = {
|
|
97
|
+
TableName: process.env.$APP_DDBTABLE,
|
|
98
|
+
KeyConditionExpression: "pk = :pkValue",
|
|
99
|
+
ExpressionAttributeValues: {
|
|
100
|
+
":pkValue": 'test'
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const command = new QueryCommand(params);
|
|
105
|
+
const response = await ddbDocClient.send(command);
|
|
106
|
+
console.log("Query response:", response);
|
|
107
|
+
return { ok: true, msg: response.Items.length };
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return { ok: false, msg: error };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
exports.checkS3Connection = async function(){
|
|
114
|
+
const client = new S3Client({ region: process.env.$APP_REGION }); // Replace with your region
|
|
115
|
+
const command = new ListObjectsV2Command({
|
|
116
|
+
Bucket: process.env.$APP_S3BUCKET,
|
|
117
|
+
MaxKeys: 2
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
const response = await client.send(command);
|
|
121
|
+
return { ok: true, msg: response.Contents.length };
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw { ok: false, msg: error };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function decode(token,index=0){
|
|
128
|
+
const payload = token.split('.')[index]
|
|
129
|
+
const decoded = Buffer.from(payload, 'base64').toString('utf8');
|
|
130
|
+
return JSON.parse(decoded);
|
|
131
|
+
}
|