(managementEndpoint, instanceId, log, callback)
| 26 | } |
| 27 | |
| 28 | function issueCredentials(managementEndpoint, instanceId, log, callback) { |
| 29 | log.info('registering with API to get token'); |
| 30 | |
| 31 | const keyPair = forge.pki.rsa.generateKeyPair({ bits: 2048, e: 0x10001 }); |
| 32 | const privateKey = forge.pki.privateKeyToPem(keyPair.privateKey); |
| 33 | const publicKey = forge.pki.publicKeyToPem(keyPair.publicKey); |
| 34 | |
| 35 | const postData = { |
| 36 | publicKey, |
| 37 | }; |
| 38 | |
| 39 | request.post(`${managementEndpoint}/${instanceId}/register`, |
| 40 | { body: postData, json: true }, (error, response, body) => { |
| 41 | if (error) { |
| 42 | return callback(error); |
| 43 | } |
| 44 | if (response.statusCode !== 201) { |
| 45 | log.error('could not register instance', { |
| 46 | statusCode: response.statusCode, |
| 47 | }); |
| 48 | return callback(arsenal.errors.InternalError); |
| 49 | } |
| 50 | /* eslint-disable no-param-reassign */ |
| 51 | body.privateKey = privateKey; |
| 52 | /* eslint-enable no-param-reassign */ |
| 53 | return callback(null, body); |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | function confirmInstanceCredentials( |
| 58 | managementEndpoint, instanceId, creds, log, callback) { |
no test coverage detected