Compare commits

...

1 Commits

Author SHA1 Message Date
Bennett Buchanan aa78aca697 feature: ZENKO-1163 Don't replicate deletions 2018-10-15 17:17:33 -07:00
5 changed files with 66 additions and 0 deletions

View File

@ -11,4 +11,5 @@ module.exports = {
putObjectTagging: require('./putTagging'),
getObjectTagging: require('./getTagging'),
deleteObjectTagging: require('./deleteTagging'),
updateObject: require('./updateObject'),
};

View File

@ -0,0 +1,18 @@
const async = require('async');
const { errors } = require('arsenal');
function updateObject(params, cb) {
const { Bucket, Key, Metadata } = params;
return async.waterfall([
next => this.headObject({ Bucket, Key }, next),
(res, next) => this.copyObject({
Bucket,
Key,
CopySource: `${Bucket}/${Key}`,
Metadata: Object.assign({}, res.Metadata, Metadata),
MetadataDirective: 'REPLACE',
}, next),
], cb);
}
module.exports = updateObject;

View File

@ -97,6 +97,15 @@ class GcpClient extends AwsClient {
});
}
updateObject(bucketName, key, metadata, log, cb) {
const gcpKey = this._createGcpKey(bucketName, key, this._bucketMatch);
return this._client.updateObject({
Bucket: this._gcpBucketName,
Key: gcpKey,
Metadata: metadata,
}, cb);
}
createMPU(key, metaHeaders, bucketName, websiteRedirectHeader, contentType,
cacheControl, contentDisposition, contentEncoding, log, callback) {
const metaHeadersTrimmed = {};

View File

@ -253,6 +253,14 @@ const multipleBackendGateway = {
return cb();
},
updateObject(bucketName, key, metadata, location, log, cb) {
const client = clients[location];
if (client.updateObject) {
return client.updateObject(bucketName, key, metadata, log, cb);
}
return cb();
},
abortMPU: (key, uploadId, location, bucketName, log, cb) => {
const client = clients[location];
const skipDataDelete = true;

View File

@ -141,6 +141,12 @@ function _checkMultipleBackendRequest(request, log) {
log.error(errMessage);
return errors.BadRequest.customizeDescription(errMessage);
}
if (operation === 'updateobject' &&
headers['x-scal-metadata'] === undefined) {
errMessage = 'bad request: missing x-scal-metadata header';
log.error(errMessage);
return errors.BadRequest.customizeDescription(errMessage);
}
if (headers['x-scal-storage-class'] === undefined) {
errMessage = 'bad request: missing x-scal-storage-class header';
log.error(errMessage);
@ -406,6 +412,29 @@ function putObject(request, response, log, callback) {
});
}
function updateObject(request, response, log, callback) {
const userMetadata = {};
try {
const attr = JSON.parse(request.headers['x-scal-user-metadata']);
Object.keys(attr).forEach(key => (userMetadata[key] = `${data[key]}`));
} catch (e) {
errMessage = 'invalid request: invalid user metadata in request';
return callback(errors.InvalidRequest.customizeDescription(errMessage));
}
const storageLocation = request.headers['x-scal-storage-class'];
return multipleBackendGateway.updateObject(request.bucketName,
request.objectKey, userMetadata, storageLocation, log, (err, res) => {
if (err) {
log.error('error putting user metadata', {
error: err,
method: 'updateObject',
});
return callback(err);
}
return _respond(response, {}, log, callback);
});
}
function deleteObject(request, response, log, callback) {
const err = _checkMultipleBackendRequest(request, log);
if (err) {
@ -709,6 +738,7 @@ const backbeatRoutes = {
multiplebackenddata: {
putobject: putObject,
putpart: putPart,
updateobject: updateObject,
},
},
POST: {