-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.ts
More file actions
104 lines (92 loc) · 2.51 KB
/
update.ts
File metadata and controls
104 lines (92 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Argv } from 'yargs';
import { monitoring, aws } from '../../lib';
import { setVerbose } from '../../lib/logger';
export const command = 'update [options]';
export const desc = 'Update monitoring config';
export const builder = (yargs: Argv<{}>): Argv<{}> => {
return yargs.options({
c: {
alias: 'config',
describe: 'Config file to update',
type: 'string',
default: 'config.yml',
},
p: {
alias: 'profile',
describe: 'AWS profile used connect to AWS environment',
type: 'string',
},
r: {
alias: 'region',
describe: 'Target region',
type: 'string',
},
i: {
alias: 'include',
describe: 'List of included names',
type: 'array',
},
e: {
alias: 'exclude',
describe: 'List of excluded names',
type: 'array',
},
s: {
alias: 'service',
describe: 'List of services',
type: 'array',
choices: ['lambda', 'dynamodb', 'ecs', 'apigateway', 'cloudfront', 'rds', 'eks', 'loggroup', 'appsync', 'sqs'],
},
d: {
alias: 'dry',
default: false,
type: 'boolean',
},
t: {
alias: 'stage',
describe: 'Stage of the deployment',
type: 'string',
default: 'dev',
},
ep: {
alias: 'endpoints',
default: [],
describe:
'Add endpoints directly or AWS SSM params name to retrieve endpoints from SSM, e.g. ssm:my-endpoint-${stage}, stage is always added to the end',
type: 'array',
},
v: {
alias: 'verbose',
describe: 'Set verbose logging',
type: 'boolean',
default: false,
},
interactive: {
default: false,
type: 'boolean',
},
sso: {
default: false,
describe: 'Use an AWS profile with SSO credentials',
type: 'boolean',
},
});
};
export const handler = async (args: monitoring.Args): Promise<void> => {
setVerbose(args.verbose);
const config = new monitoring.ConfigGenerator(args);
await config.loadFromFile(args.config);
const combinedArgs = config.combineCLIArgs(args);
config.updateCLIArgs(combinedArgs);
await aws.setAWSCredentials(combinedArgs.profile, combinedArgs.region);
await config.setPagerDutyEndpoint(combinedArgs);
const awsConfig = await monitoring.getAllFromAWS(combinedArgs);
const newConfig = new monitoring.ConfigGenerator(combinedArgs);
newConfig.addAllLocal(awsConfig);
config.combine(newConfig);
if (args.dry) {
config.diff(newConfig);
return;
}
await config.write(args.config);
};