* Initializes Orbit-based management by: * - creating the management database in metadata * - generating a key pair for credentials encryption * - generating an instance-unique ID * - getting an authentication token for the API * - loading and applying the latest cached overlay configuration *
(log, callback)
| 75 | * @returns {undefined} |
| 76 | */ |
| 77 | function initManagement(log, callback) { |
| 78 | if ((process.env.REMOTE_MANAGEMENT_DISABLE && |
| 79 | process.env.REMOTE_MANAGEMENT_DISABLE !== '0') |
| 80 | || process.env.S3BACKEND === 'mem') { |
| 81 | log.info('remote management disabled'); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | /* Temporary check before to fully move to the process management agent. */ |
| 86 | if (isManagementAgentUsed() ^ typeof callback === 'function') { |
| 87 | let msg = 'misuse of initManagement function: '; |
| 88 | msg += `MANAGEMENT_USE_AGENT: ${process.env.MANAGEMENT_USE_AGENT}`; |
| 89 | msg += `, callback type: ${typeof callback}`; |
| 90 | throw new Error(msg); |
| 91 | } |
| 92 | |
| 93 | async.waterfall([ |
| 94 | // eslint-disable-next-line arrow-body-style |
| 95 | cb => { return isManagementAgentUsed() ? metadata.setup(cb) : cb(); }, |
| 96 | cb => initManagementDatabase(log, cb), |
| 97 | cb => metadata.getUUID(log, cb), |
| 98 | (instanceId, cb) => initManagementCredentials( |
| 99 | managementEndpoint, instanceId, log, cb), |
| 100 | (instanceId, token, cb) => { |
| 101 | if (!isManagementAgentUsed()) { |
| 102 | cb(null, instanceId, token, {}); |
| 103 | return; |
| 104 | } |
| 105 | loadCachedOverlay(log, (err, overlay) => cb(err, instanceId, |
| 106 | token, overlay)); |
| 107 | }, |
| 108 | (instanceId, token, overlay, cb) => { |
| 109 | if (!isManagementAgentUsed()) { |
| 110 | cb(null, instanceId, token, overlay); |
| 111 | return; |
| 112 | } |
| 113 | patchConfiguration(overlay, log, |
| 114 | err => cb(err, instanceId, token, overlay)); |
| 115 | }, |
| 116 | ], (error, instanceId, token, overlay) => { |
| 117 | if (error) { |
| 118 | log.error('could not initialize remote management, retrying later', |
| 119 | { error: reshapeExceptionError(error), |
| 120 | method: 'initManagement' }); |
| 121 | setTimeout(initManagement, |
| 122 | initRemoteManagementRetryDelay, |
| 123 | logger.newRequestLogger()); |
| 124 | } else { |
| 125 | log.info(`this deployment's Instance ID is ${instanceId}`); |
| 126 | log.end('management init done'); |
| 127 | startManagementListeners(instanceId, token); |
| 128 | if (callback) { |
| 129 | callback(overlay); |
| 130 | } |
| 131 | } |
| 132 | }); |
| 133 | } |
| 134 |
no test coverage detected