-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfigure.js
174 lines (157 loc) · 4.7 KB
/
configure.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env node
const AWS = require('aws-sdk'),
readline = require('readline-sync'),
pathPrefix = '/felix/',
{ ssmToObjByPath } = require('ssm-params');
if (!AWS.config.region) {
const region = readline.question('Please specify which region to set these parameters in (us-east-1): ', { defaultInput: 'us-east-1' });
AWS.config.update({ region });
}
const ssm = new AWS.SSM();
const config = [
{
Name: 'aws',
Description: 'AWS-specific settings for locating IAM users and notifying SNS.',
required: true,
parameters: [
{
Name: 'snsTopic',
default: `arn:aws:sns:${AWS.config.region}:[account id]:FelixReports`,
Description: 'The SNS topic to publish Felix reports.',
Type: 'String'
},
{
Name: 'userPath',
default: '/service/',
Description: 'The path preflix to look in for IAM users.',
Type: 'String'
}
]
},
{
Name: 'gitlab',
Description: 'Gitlab settings for updating IAM keys used by Pipelines jobs.',
required: false,
parameters: [
{
Name: 'url',
default: 'https://gitlab.com',
Description: 'The base URL for the GitLab API.',
Type: 'String'
},
{
Name: 'token',
Description: 'The GitLab API token for managing repository settings.',
KeyId: 'alias/felix/settings',
Type: 'SecureString'
},
{
Name: 'protectedKeys',
default: 'false',
Description: 'Should GitLab mark the keys as protected? Protected keys can only be used on protected branches. (true or false)',
Type: 'String'
}
]
},
{
Name: 'sumologic',
Description: 'SumoLogic settings for updating AWS sources.',
required: false,
parameters: [
{
Name: 'keyId',
Description: 'The Id of the SumoLogic Authentication Key',
KeyId: 'alias/felix/settings',
Type: 'SecureString'
},
{
Name: 'secretKey',
Description: 'The SumoLogic Authentication secret Key',
KeyId: 'alias/felix/settings',
Type: 'SecureString'
},
{
Name: 'url',
Description: 'The SumoLogic API endpoint url.',
default: 'https://api.us2.sumologic.com/api/v1',
Type: 'String'
}
]
},
{
Name: 'travis',
Description: 'Travis CI settings for managing repositories.',
required: false,
parameters: [
{
Name: 'token',
Description: 'The Travis API token.',
KeyId: 'alias/felix/settings',
Type: 'SecureString'
}
]
}
];
ssmToObjByPath({
Path: pathPrefix,
nestObject: true,
WithDecryption: true
}, (_, existingValues) => {
console.log(`Felix Configuration Setup:
Felix uses the EC2 Parameter Store to load its configuration. Let's make sure you
have all of the correct parameters created in the right paths and the right ones
are encrypted.
`);
const corrections = [];
config.forEach(plugin => {
console.log(`Plugin: ${plugin.Name}
Description: ${plugin.Description}`);
if (!plugin.required && readline.keyInYN('Do you want to configure this plugin? ') === false) {
console.log('');
return;
}
plugin.parameters.forEach(param => {
console.log(` Parameter: ${pathPrefix}${plugin.Name}/${param.Name}
Description: ${param.Description}`);
let existingValue = '';
if (existingValues && plugin.Name in existingValues && param.Name in existingValues[plugin.Name]) {
existingValue = existingValues[plugin.Name][param.Name];
} else if ('default' in param) {
existingValue = param.default;
}
const newValue = readline.question(` Value (${existingValue}): `, { defaultInput: existingValue });
param.Name = `${pathPrefix}${plugin.Name}/${param.Name}`;
param.Value = newValue;
param.Overwrite = true;
if (newValue === '' || newValue === undefined) {
console.log(` Refusing to update empty setting ${pathPrefix}${plugin.Name}${param.Name}.`);
} else {
console.log(` ${pathPrefix}${plugin.Name}${param.Name} => ${newValue}`);
corrections.push(param);
}
console.log('');
});
console.log('');
});
console.log('');
updateParams(corrections.shift(), corrections);
});
function updateParams (param, array) {
console.log(`${param.Name} => ${param.Value}`);
if ('default' in param) {
delete param.default;
}
ssm.putParameter(param, (err, data) => {
if (err) {
console.log(' ERROR!');
console.log(err);
} else {
console.log(' SUCCESS!');
if (array.length > 0) updateParams(array.shift(), array);
else {
console.log('');
console.log('DONE!');
}
}
});
}