-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy path028-move-security-settings-to-secret-store.js
57 lines (45 loc) · 1.71 KB
/
028-move-security-settings-to-secret-store.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
"use strict";
const log = require('winston')
, SecretStoreService = require('../security/secret-store-service');
exports.id = 'move-security-settings-to-secret-store';
function moveSecuritySettings(settings, blacklist) {
const data = {};
Object.keys(settings).forEach(key => {
if (blacklist.includes(key.toLowerCase())) {
data[key] = settings[key];
delete settings[key];
}
});
return data;
}
exports.up = async function (done) {
const blacklist = ['clientid', 'clientsecret', 'client_id', 'bindcredentials'];
const authenticationConfigurationsCollection = await this.db.collection('authenticationconfigurations');
const cursor = authenticationConfigurationsCollection.find();
let hasNext = true;
while (hasNext === true) {
hasNext = await cursor.hasNext()
if (hasNext !== true) break;
const authConfig = await cursor.next();
if (authConfig.settings) {
const data = moveSecuritySettings(authConfig.settings, blacklist);
if (Object.keys(data).length > 0) {
log.info('Moving security settings for auth config ' + authConfig.name);
const store = new SecretStoreService();
try {
await store.write(authConfig._id.toString(), data);
await authenticationConfigurationsCollection.updateOne({ _id: authConfig._id }, authConfig);
} catch (err) {
log.warn(err);
return done(err);
}
}
} else {
log.info('No settings found for ' + authConfig.name);
}
}
done();
};
exports.down = function (done) {
done();
}