* 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)
| 36 | * @returns {undefined} |
| 37 | */ |
| 38 | function 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) |
no test coverage detected