MCPcopy
hub / github.com/scality/cloudserver / patchConfiguration

Function patchConfiguration

lib/management/configuration.js:38–136  ·  view source on GitHub ↗

* Updates the live {Config} object with the new overlay configuration. * * No-op if this version was already applied to the live {Config}. * * @param {object} newConf Overlay configuration to apply * @param {werelogs~Logger} log Request-scoped logger * @param {function} cb Function to call

(newConf, log, cb)

Source from the content-addressed store, hash-verified

36 * @returns {undefined}
37 */
38function patchConfiguration(newConf, log, cb) {
39 if (newConf.version === undefined) {
40 log.debug('no remote configuration created yet');
41 return process.nextTick(cb, null, newConf);
42 }
43
44 if (_config.overlayVersion !== undefined &&
45 newConf.version <= _config.overlayVersion) {
46 log.debug('configuration version already applied',
47 { configurationVersion: newConf.version });
48 return process.nextTick(cb, null, newConf);
49 }
50 return getStoredCredentials(log, (err, creds) => {
51 if (err) {
52 return cb(err);
53 }
54 const accounts = [];
55 if (newConf.users) {
56 newConf.users.forEach(u => {
57 if (u.secretKey && u.secretKey.length > 0) {
58 const secretKey = decryptSecret(creds, u.secretKey);
59 // accountType will be service-replication or service-clueso
60 let serviceName;
61 if (u.accountType && u.accountType.startsWith('service-')) {
62 serviceName = u.accountType.split('-')[1];
63 }
64 const newAccount = buildAuthDataAccount(
65 u.accessKey, secretKey, u.canonicalId, serviceName,
66 u.userName);
67 accounts.push(newAccount.accounts[0]);
68 }
69 });
70 }
71
72 const restEndpoints = Object.assign({}, _config.restEndpoints);
73 if (newConf.endpoints) {
74 newConf.endpoints.forEach(e => {
75 restEndpoints[e.hostname] = e.locationName;
76 });
77 }
78
79 if (!restEndpoints[replicatorEndpoint]) {
80 restEndpoints[replicatorEndpoint] = 'us-east-1';
81 }
82
83 const locations = patchLocations(newConf.locations, creds, log);
84 if (Object.keys(locations).length !== 0) {
85 try {
86 _config.setLocationConstraints(locations);
87 } catch (error) {
88 const exceptionError = reshapeExceptionError(error);
89 log.error('could not apply configuration version location ' +
90 'constraints', { error: exceptionError,
91 method: 'getStoredCredentials' });
92 return cb(exceptionError);
93 }
94 try {
95 const locationsWithReplicationBackend = Object.keys(locations)

Callers 5

initManagementClientFunction · 0.85
initManagementFunction · 0.85
applyAndSaveOverlayFunction · 0.85
configuration.jsFile · 0.85

Calls 10

getStoredCredentialsFunction · 0.85
buildAuthDataAccountFunction · 0.85
debugMethod · 0.80
errorMethod · 0.80
setAuthDataAccountsMethod · 0.80
setRestEndpointsMethod · 0.80
setPublicInstanceIdMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected