Skip to content

Commit

Permalink
Lint and rework SSE condition
Browse files Browse the repository at this point in the history
Issue: CLDSRV-408
  • Loading branch information
KillianG authored Jul 11, 2023
1 parent 646c3e2 commit e7730a4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
14 changes: 4 additions & 10 deletions lib/api/apiUtils/object/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,13 @@ function restoreMetadatas(objMD, metadataStoreParams) {
Object.keys(objMD).forEach(key => {
if (key.startsWith('x-amz-meta-') && !userMDToSkip.includes(key)) {
metadataStoreParams.metaHeaders[key] = objMD[key];
} else if (key.startsWith('content-')) {
metadataStoreParams[key] = objMD[key];
}
});

if (objMD['x-amz-server-side-encryption']) {
metadataStoreParams.cipherBundle = {
algorithm: objMD['x-amz-server-side-encryption'],
masterKeyId: objMD['x-amz-server-side-encryption-aws-kms-key-id'] || objMD['x-amz-server-side-encryption-customer-algorithm'],
}
}

if (objMD['x-amz-website-redirect-location']) {
if (!metadataStoreParams.headers) {
metadataStoreParams.headers = {};
}
metadataStoreParams.headers['x-amz-website-redirect-location'] = objMD['x-amz-website-redirect-location'];
}

Expand All @@ -473,7 +467,7 @@ function restoreMetadatas(objMD, metadataStoreParams) {
}

if (objMD.acl) {
metadataStoreParams.oldAcl = objMD.acl;
metadataStoreParams.acl = objMD.acl;
}

metadataStoreParams.creationTime = objMD['creation-time'];
Expand Down
11 changes: 3 additions & 8 deletions lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const services = {
tagging, taggingCopy, replicationInfo, defaultRetention,
dataStoreName, creationTime, retentionMode, retentionDate,
legalHold, originOp, updateMicroVersionId, archive, oldReplayId,
deleteNullKey, oldAcl } = params;
deleteNullKey } = params;
log.trace('storing object in metadata');
assert.strictEqual(typeof bucketName, 'string');
const md = new ObjectMD();
Expand Down Expand Up @@ -128,11 +128,6 @@ const services = {
if (lastModifiedDate) {
md.setLastModified(lastModifiedDate);
}

if (!cipherBundle && params.cipherBundle) {
cipherBundle = params.cipherBundle;
}

if (cipherBundle) {
md.setAmzServerSideEncryption(cipherBundle.algorithm);
// configuredMasterKeyId takes precedence
Expand Down Expand Up @@ -259,10 +254,10 @@ const services = {
if (multipart || md.getIsDeleteMarker()) {
return callback();
}
if (oldAcl) {
if (params.acl) {
// In case of a restore we dont pass ACL in the headers
// but we take them from the old metadata
md.setAcl(oldAcl);
md.setAcl(params.acl);
return callback();
}
const parseAclParams = {
Expand Down
1 change: 1 addition & 0 deletions tests/functional/aws-node-sdk/test/object/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ describe('Object Copy', () => {
restoreCompletedAt: new Date(10),
restoreWillExpireAt: new Date(10 + (5 * 24 * 60 * 60 * 1000)),
};
originalMetadata['custom-user-md'] = 'custom-md';
fakeMetadataArchive(sourceBucketName, sourceObjName, undefined, archiveCompleted, err => {
assert.ifError(err);
s3.copyObject({
Expand Down
16 changes: 14 additions & 2 deletions tests/functional/aws-node-sdk/test/object/putVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ describe('PUT object with x-scal-s3-version-id header', () => {
next => s3.putObject(params, next),
next => fakeMetadataArchive(bucketName, objectName, undefined, archive, next),
next => getMetadata(bucketName, objectName, undefined, (err, objMD) => {
if (err) {
return next(err);
}
// eslint-disable-next-line no-param-reassign
objMD.legalHold = true;
objMDBefore = objMD;
return next(err);
return metadata.putObjectMD(bucketName, objectName, objMD, params, log, err => next(err));
}),
next => metadata.listObject(bucketName, mdListingParams, log, (err, res) => {
versionsBefore = res.Versions;
Expand All @@ -114,7 +119,14 @@ describe('PUT object with x-scal-s3-version-id header', () => {
checkObjMdAndUpdate(objMDBefore, objMDAfter, ['location', 'content-length', 'content-md5',
'microVersionId', 'x-amz-restore', 'archive', 'dataStoreName', 'originOp']);
assert.deepStrictEqual(objMDAfter, objMDBefore);
return done();
return getMetadata(bucketName, objectName, undefined, (err, objMD) => {
if (err) {
return done(err);
}
// eslint-disable-next-line no-param-reassign
objMD.legalHold = false;
return metadata.putObjectMD(bucketName, objectName, objMD, params, log, err => done(err));
});
});
});

Expand Down
41 changes: 24 additions & 17 deletions tests/functional/aws-node-sdk/test/utils/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,36 @@ function fakeMetadataArchive(bucketName, objectName, versionId, archive, cb) {
objMD.dataStoreName = 'location-dmf-v1';
objMD.archive = archive;
objMD['x-amz-meta-custom-user-md'] = 'custom-md';
objMD.acl = {
'Canned': '',
'FULL_CONTROL': [
'cb676c668a4eb77a38c490548f9c95909353181a2ca8ec115d738920a7746a34'
],
'WRITE_ACP': [],
'READ': [],
'READ_ACP': []
};
objMD.tags = { tag1: 'value1', tag2: 'value2' };
objMD["x-amz-server-side-encryption"] = "AES256";
objMD["x-amz-server-side-encryption-aws-kms-key-id"] = "very-secret-key";
objMD['x-amz-website-redirect-location'] = 'https://scality.com/'
objMD['x-amz-website-redirect-location'] = 'https://scality.com/';
objMD.replicationInfo = {
"status" : "PENDING",
"backends" : [
'status': 'PENDING',
'backends': [
{
"site" : "azure-normal",
"status" : "PENDING",
"dataStoreVersionId" : ""
'site': 'azure-normal',
'status': 'PENDING',
'dataStoreVersionId': ''
}
],
"content" : [
"DATA",
"METADATA"
'content': [
'DATA',
'METADATA'
],
"destination" : "arn:aws:s3:::versioned",
"storageClass" : "azure-normal",
"role" : "arn:aws:iam::root:role/s3-replication-role",
"storageType" : "azure",
"dataStoreVersionId" : "",
"isNFS" : null
'destination': 'arn:aws:s3:::versioned',
'storageClass': 'azure-normal',
'role': 'arn:aws:iam::root:role/s3-replication-role',
'storageType': 'azure',
'dataStoreVersionId': '',
'isNFS': null
};
/* eslint-enable no-param-reassign */
return metadata.putObjectMD(bucketName, objectName, objMD, { versionId: decodeVersionId(versionId) },
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/api/apiUtils/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ describe('versioning helpers', () => {
'restoreRequestedDays': days,
'restoreRequestedAt': now,
archiveInfo
}
}
},
expectedRes: {
'creationTime': now,
Expand Down Expand Up @@ -694,15 +694,15 @@ describe('versioning helpers', () => {
taggingCopy: { 'testtag': 'testtag', 'testtag2': 'testtag2' },
archive: {
archiveInfo,
'restoreRequestedDays': 3,
'restoreRequestedDays': days,
'restoreRequestedAt': now,
'restoreCompletedAt': new Date(now),
'restoreWillExpireAt': new Date(now + (days * scaledMsPerDay)),
}
},
},
{
description: 'Should return nullVersionId',
description: 'Should not fail with a nullVersionId',
objMD: {
'creation-time': now,
'last-modified': now,
Expand Down

0 comments on commit e7730a4

Please sign in to comment.