diff --git a/lib/api/apiUtils/object/createAndStoreObject.js b/lib/api/apiUtils/object/createAndStoreObject.js index 2c69a55ccf..24d915acd0 100644 --- a/lib/api/apiUtils/object/createAndStoreObject.js +++ b/lib/api/apiUtils/object/createAndStoreObject.js @@ -179,7 +179,14 @@ function createAndStoreObject( size, headers, isDeleteMarker, - replicationInfo: getReplicationInfo(config, objectKey, bucketMD, false, size, null, null, authInfo), + replicationInfo: getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD, + isMD: false, + objSize: size, + authInfo, + }), overheadField, log, }; diff --git a/lib/api/apiUtils/object/getReplicationInfo.js b/lib/api/apiUtils/object/getReplicationInfo.js index b88bf2ac36..92f1153223 100644 --- a/lib/api/apiUtils/object/getReplicationInfo.js +++ b/lib/api/apiUtils/object/getReplicationInfo.js @@ -56,30 +56,33 @@ function _canUserReplicate(authInfo) { * decides the `content` array based on the operation kind, and * stitches the result into a `replicationInfo` envelope. * - * @param {object} s3config - Cloudserver configuration object - * @param {object} s3config.locationConstraints - Configured map of location constraints - * @param {object[]} s3config.replicationEndpoints - Configured replication endpoints - * @param {string} objKey - The key of the object - * @param {object} bucketMD - The bucket metadata - * @param {boolean} isMD - Whether the operation is only updating metadata - * @param {boolean} objSize - The size, in bytes, of the object being PUT - * @param {string} operationType - The type of operation to replicate - * @param {object} objectMD - The object metadata - * @param {AuthInfo} [authInfo] - authentication info of object owner - * @param {string[]} [blockedSiteTypes=[]] - location types to exclude from the returned backends + * @param {object} params - Named parameters + * @param {object} params.s3config - Cloudserver configuration object + * @param {object} params.s3config.locationConstraints - Configured map of location constraints + * @param {object[]} params.s3config.replicationEndpoints - Configured replication endpoints + * @param {string} params.objKey - The key of the object + * @param {object} params.bucketMD - The bucket metadata + * @param {boolean} params.isMD - Whether the operation is only updating metadata + * @param {number} [params.objSize] - The size, in bytes, of the object being PUT (irrelevant when isMD is true) + * @param {string} [params.operationType] - The type of operation to replicate + * @param {object} [params.objectMD] - The object metadata + * @param {AuthInfo} [params.authInfo] - authentication info of object owner + * @param {string[]} [params.blockedSiteTypes=[]] - location types to exclude from the returned backends * @return {object|undefined} */ -function getReplicationInfo( - s3config, - objKey, - bucketMD, - isMD, - objSize, - operationType, - objectMD, - authInfo, - blockedSiteTypes = [], -) { +function getReplicationInfo(params) { + const { + s3config, + objKey, + bucketMD, + isMD, + objSize, + operationType, + objectMD, + authInfo, + blockedSiteTypes = [], + } = params; + const config = bucketMD.getReplicationConfiguration(); if (!config || !_canUserReplicate(authInfo)) { return undefined; diff --git a/lib/api/completeMultipartUpload.js b/lib/api/completeMultipartUpload.js index 044104d741..1f693d1f5a 100644 --- a/lib/api/completeMultipartUpload.js +++ b/lib/api/completeMultipartUpload.js @@ -803,14 +803,14 @@ function completeMultipartUpload(authInfo, request, log, callback) { size: calculatedSize, multipart: true, isDeleteMarker: false, - replicationInfo: getReplicationInfo( - config, - objectKey, - destBucket, - false, - calculatedSize, - REPLICATION_ACTION, - ), + replicationInfo: getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: destBucket, + isMD: false, + objSize: calculatedSize, + operationType: REPLICATION_ACTION, + }), originOp: 's3:ObjectCreated:CompleteMultipartUpload', overheadField: constants.overheadField, log, diff --git a/lib/api/objectCopy.js b/lib/api/objectCopy.js index fa0b237ebf..19d043181e 100644 --- a/lib/api/objectCopy.js +++ b/lib/api/objectCopy.js @@ -394,7 +394,13 @@ function _prepMetadata( lastModifiedDate: new Date().toJSON(), tagging, taggingCopy, - replicationInfo: getReplicationInfo(config, objectKey, destBucketMD, false, sourceObjMD['content-length']), + replicationInfo: getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: destBucketMD, + isMD: false, + objSize: sourceObjMD['content-length'], + }), locationMatch, originOp: 's3:ObjectCreated:Copy', }; diff --git a/lib/api/objectDeleteTagging.js b/lib/api/objectDeleteTagging.js index 9c8420c737..0a8fb834c7 100644 --- a/lib/api/objectDeleteTagging.js +++ b/lib/api/objectDeleteTagging.js @@ -82,15 +82,15 @@ function objectDeleteTagging(authInfo, request, log, callback) { // eslint-disable-next-line no-param-reassign objectMD.tags = {}; const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode); - const replicationInfo = getReplicationInfo( - config, - objectKey, - bucket, - true, - 0, - REPLICATION_ACTION, + const replicationInfo = getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: bucket, + isMD: true, + objSize: 0, + operationType: REPLICATION_ACTION, objectMD, - ); + }); if (replicationInfo) { // eslint-disable-next-line no-param-reassign objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo); diff --git a/lib/api/objectPutLegalHold.js b/lib/api/objectPutLegalHold.js index 5fe844a1e8..09db2d6ee2 100644 --- a/lib/api/objectPutLegalHold.js +++ b/lib/api/objectPutLegalHold.js @@ -94,15 +94,15 @@ function objectPutLegalHold(authInfo, request, log, callback) { // eslint-disable-next-line no-param-reassign objectMD.legalHold = legalHold; const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode); - const replicationInfo = getReplicationInfo( - config, - objectKey, - bucket, - true, - 0, - REPLICATION_ACTION, + const replicationInfo = getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: bucket, + isMD: true, + objSize: 0, + operationType: REPLICATION_ACTION, objectMD, - ); + }); if (replicationInfo) { // eslint-disable-next-line no-param-reassign objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo); diff --git a/lib/api/objectPutRetention.js b/lib/api/objectPutRetention.js index e281b71f91..f867587962 100644 --- a/lib/api/objectPutRetention.js +++ b/lib/api/objectPutRetention.js @@ -116,15 +116,15 @@ function objectPutRetention(authInfo, request, log, callback) { objectMD.retentionMode = retentionInfo.mode; objectMD.retentionDate = retentionInfo.date; const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode); - const replicationInfo = getReplicationInfo( - config, - objectKey, - bucket, - true, - 0, - REPLICATION_ACTION, + const replicationInfo = getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: bucket, + isMD: true, + objSize: 0, + operationType: REPLICATION_ACTION, objectMD, - ); + }); if (replicationInfo) { objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo); bumpMicroVersionId(objectMD); diff --git a/lib/api/objectPutTagging.js b/lib/api/objectPutTagging.js index cd5326bb98..ab2dfbc855 100644 --- a/lib/api/objectPutTagging.js +++ b/lib/api/objectPutTagging.js @@ -85,15 +85,15 @@ function objectPutTagging(authInfo, request, log, callback) { // eslint-disable-next-line no-param-reassign objectMD.tags = tags; const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode); - const replicationInfo = getReplicationInfo( - config, - objectKey, - bucket, - true, - 0, - REPLICATION_ACTION, + const replicationInfo = getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: bucket, + isMD: true, + objSize: 0, + operationType: REPLICATION_ACTION, objectMD, - ); + }); if (replicationInfo) { // eslint-disable-next-line no-param-reassign objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo); diff --git a/lib/metadata/acl.js b/lib/metadata/acl.js index 211bf47828..f649c27371 100644 --- a/lib/metadata/acl.js +++ b/lib/metadata/acl.js @@ -58,7 +58,12 @@ const acl = { const hasDestRole = b => !!b.role; const sameBackend = (a, b) => a.site === b.site && a.destination === b.destination && a.role === b.role; - const replicationInfo = getReplicationInfo(config, objectKey, bucket, true); + const replicationInfo = getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: bucket, + isMD: true, + }); if (replicationInfo && replicationInfo.backends.some(hasDestRole)) { const backends = replicationInfo.backends .map(b => { diff --git a/lib/routes/routeBackbeat.js b/lib/routes/routeBackbeat.js index 719478df9f..d61f59eebc 100644 --- a/lib/routes/routeBackbeat.js +++ b/lib/routes/routeBackbeat.js @@ -862,17 +862,14 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { const isMDOnly = headers['x-scal-replication-content'] === 'METADATA'; const objSize = omVal['content-length'] || 0; - const nextReplInfo = getReplicationInfo( - config, - objectKey, - bucketInfo, - isMDOnly, + const nextReplInfo = getReplicationInfo({ + s3config: config, + objKey: objectKey, + bucketMD: bucketInfo, + isMD: isMDOnly, objSize, - null, - null, - null, - constants.crrCascadeBlockedLocationTypes, - ); + blockedSiteTypes: constants.crrCascadeBlockedLocationTypes, + }); const hasNextHop = nextReplInfo && nextReplInfo.backends.length > 0; diff --git a/tests/unit/api/apiUtils/getReplicationInfo.js b/tests/unit/api/apiUtils/getReplicationInfo.js index e12b4b3bba..b2fe863cb4 100644 --- a/tests/unit/api/apiUtils/getReplicationInfo.js +++ b/tests/unit/api/apiUtils/getReplicationInfo.js @@ -21,7 +21,14 @@ function _getObjectReplicationInfo(s3config, replicationConfig, key, objectMD) { null, replicationConfig, ); - return getReplicationInfo(s3config, key || 'fookey', bucketInfo, true, 123, null, objectMD || null); + return getReplicationInfo({ + s3config, + objKey: key || 'fookey', + bucketMD: bucketInfo, + isMD: true, + objSize: 123, + objectMD: objectMD || null, + }); } const TEST_CONFIG = { @@ -238,16 +245,14 @@ describe('getReplicationInfo helper', () => { canonicalID: 'abcdef/lifecycle', accountDisplayName: 'Lifecycle Service Account', }); - const replicationInfo = getReplicationInfo( - TEST_CONFIG, - 'fookey', - bucketInfo, - true, - 123, - null, - null, + const replicationInfo = getReplicationInfo({ + s3config: TEST_CONFIG, + objKey: 'fookey', + bucketMD: bucketInfo, + isMD: true, + objSize: 123, authInfo, - ); + }); assert.deepStrictEqual(replicationInfo, undefined); }); @@ -283,16 +288,14 @@ describe('getReplicationInfo helper', () => { canonicalID: 'abcdef/md-ingestion', accountDisplayName: 'Metadata Ingestion Service Account', }); - const replicationInfo = getReplicationInfo( - TEST_CONFIG, - 'fookey', - bucketInfo, - true, - 123, - null, - null, + const replicationInfo = getReplicationInfo({ + s3config: TEST_CONFIG, + objKey: 'fookey', + bucketMD: bucketInfo, + isMD: true, + objSize: 123, authInfo, - ); + }); assert.deepStrictEqual(replicationInfo, { status: 'PENDING', backends: [ @@ -629,10 +632,10 @@ describe('getReplicationInfo helper', () => { ], destination: 'tosomewhere', }; - const info = getReplicationInfo( - configWithRing, - 'fookey', - new BucketInfo( + const info = getReplicationInfo({ + s3config: configWithRing, + objKey: 'fookey', + bucketMD: new BucketInfo( 'b', 'id', 'name', @@ -648,13 +651,10 @@ describe('getReplicationInfo helper', () => { null, replicationConfig, ), - true, - 123, - null, - null, - null, - [RING_TYPE], - ); + isMD: true, + objSize: 123, + blockedSiteTypes: [RING_TYPE], + }); assert.strictEqual(info.backends.length, 1); assert.strictEqual(info.backends[0].site, 'awsbackend'); }); @@ -665,10 +665,10 @@ describe('getReplicationInfo helper', () => { rules: [{ prefix: '', enabled: true, storageClass: 'ring-site' }], destination: 'tosomewhere', }; - const info = getReplicationInfo( - configWithRing, - 'fookey', - new BucketInfo( + const info = getReplicationInfo({ + s3config: configWithRing, + objKey: 'fookey', + bucketMD: new BucketInfo( 'b', 'id', 'name', @@ -684,13 +684,10 @@ describe('getReplicationInfo helper', () => { null, replicationConfig, ), - true, - 123, - null, - null, - null, - [RING_TYPE], - ); + isMD: true, + objSize: 123, + blockedSiteTypes: [RING_TYPE], + }); assert.strictEqual(info, undefined); }); });