(params, toUpdate, cb)
| 7 | // This approach is preferred over directly updating the metadata in MongoDB, |
| 8 | // as it allows the tests to be compatible with S3C metadata. |
| 9 | function updateMetadata(params, toUpdate, cb) { |
| 10 | const { bucket, objectKey, versionId, authCredentials } = params; |
| 11 | const { dataStoreName } = toUpdate; |
| 12 | const options = { |
| 13 | authCredentials, |
| 14 | hostname: ipAddress, |
| 15 | port: 8000, |
| 16 | method: 'GET', |
| 17 | path: `/_/backbeat/metadata/${bucket}/${objectKey}`, |
| 18 | jsonResponse: true, |
| 19 | }; |
| 20 | if (versionId) { |
| 21 | options.queryObj = { versionId }; |
| 22 | } |
| 23 | return makeRequest(options, (err, data) => { |
| 24 | if (err) { |
| 25 | return cb(err); |
| 26 | } |
| 27 | let parsedBody; |
| 28 | try { |
| 29 | parsedBody = JSON.parse(data.body); |
| 30 | } catch (err) { |
| 31 | return cb(err); |
| 32 | } |
| 33 | const { result, error } = ObjectMD.createFromBlob(parsedBody.Body); |
| 34 | if (error) { |
| 35 | return cb(error); |
| 36 | } |
| 37 | |
| 38 | if (dataStoreName) { |
| 39 | result.setDataStoreName(dataStoreName); |
| 40 | } |
| 41 | const options = { |
| 42 | authCredentials, |
| 43 | hostname: ipAddress, |
| 44 | port: 8000, |
| 45 | method: 'PUT', |
| 46 | path: `/_/backbeat/metadata/${bucket}/${objectKey}`, |
| 47 | requestBody: result.getSerialized(), |
| 48 | jsonResponse: true, |
| 49 | }; |
| 50 | if (versionId) { |
| 51 | options.queryObj = { versionId }; |
| 52 | } |
| 53 | return makeRequest(options, err => cb(err)); |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | /** makeBackbeatRequest - utility function to generate a request going |
| 58 | * through backbeat route |
no test coverage detected