MCPcopy
hub / github.com/scality/cloudserver / getReplicationInfo

Function getReplicationInfo

lib/api/apiUtils/object/getReplicationInfo.js:83–124  ·  view source on GitHub ↗

* Get the object replicationInfo to replicate data and metadata, or only * metadata if the operation only changes metadata or the object is 0 bytes * @param {object} s3config - Cloudserver configuration object * @param {object} s3config.locationConstraints - Configured map of location constraints

(
    s3config, objKey, bucketMD, isMD, objSize, operationType, objectMD, authInfo)

Source from the content-addressed store, hash-verified

81 * @return {undefined}
82 */
83function getReplicationInfo(
84 s3config, objKey, bucketMD, isMD, objSize, operationType, objectMD, authInfo) {
85 const content = isMD || objSize === 0 ? ['METADATA'] : ['DATA', 'METADATA'];
86 const config = bucketMD.getReplicationConfiguration();
87
88 // Do not replicate object in the following cases:
89 //
90 // - bucket does not have a replication configuration
91 //
92 // - replication configuration does not apply to the object
93 // (i.e. no rule matches object prefix)
94 //
95 // - replication configuration applies to the object (i.e. a rule matches
96 // object prefix) but the status is disabled
97 //
98 // - object owner is an internal service account like Lifecycle,
99 // unless the account properties explicitly allow it to
100 // replicate like MD ingestion (because we do not want to
101 // replicate objects created from actions triggered by internal
102 // services, by design)
103
104 if (config) {
105 let doReplicate = false;
106 if (!authInfo || !isServiceAccount(authInfo.getCanonicalID())) {
107 doReplicate = true;
108 } else {
109 const serviceAccountProps = getServiceAccountProperties(
110 authInfo.getCanonicalID());
111 doReplicate = serviceAccountProps.canReplicate;
112 }
113 if (doReplicate) {
114 const rule = config.rules.find(
115 rule => (objKey.startsWith(rule.prefix) && rule.enabled));
116 if (rule) {
117 // TODO CLDSRV-646 : should "merge" the replicationInfo for different rules
118 return _getReplicationInfo(
119 s3config, rule, config, content, operationType, objectMD, bucketMD);
120 }
121 }
122 }
123 return undefined;
124}
125
126module.exports = getReplicationInfo;

Callers 10

addObjectACLFunction · 0.85
objectPutLegalHoldFunction · 0.85
objectPutRetentionFunction · 0.85
_prepMetadataFunction · 0.85
completeMultipartUploadFunction · 0.85
objectDeleteTaggingFunction · 0.85
objectPutTaggingFunction · 0.85
createAndStoreObjectFunction · 0.85

Calls 3

isServiceAccountFunction · 0.85
_getReplicationInfoFunction · 0.85

Tested by

no test coverage detected