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

Function _prepMetadata

lib/api/objectCopy.js:56–203  ·  view source on GitHub ↗

* Preps metadata to be saved (based on copy or replace request header) * @param {object} request - request * @param {object} sourceObjMD - object md of source object * @param {object} headers - request headers * @param {boolean} sourceIsDestination - whether or not source is same as * destinati

(request, sourceObjMD, headers, sourceIsDestination,
    authInfo, objectKey, sourceBucketMD, destBucketMD, sourceVersionId, log)

Source from the content-addressed store, hash-verified

54 * - OR error
55 */
56function _prepMetadata(request, sourceObjMD, headers, sourceIsDestination,
57 authInfo, objectKey, sourceBucketMD, destBucketMD, sourceVersionId, log) {
58 let whichMetadata = headers['x-amz-metadata-directive'];
59 // Default is COPY
60 whichMetadata = whichMetadata === undefined ? 'COPY' : whichMetadata;
61 if (whichMetadata !== 'COPY' && whichMetadata !== 'REPLACE') {
62 return { error: errors.InvalidArgument };
63 }
64 let whichTagging = headers['x-amz-tagging-directive'];
65 // Default is COPY
66 whichTagging = whichTagging === undefined ? 'COPY' : whichTagging;
67 if (whichTagging !== 'COPY' && whichTagging !== 'REPLACE') {
68 return { error: errorInstances.InvalidArgument
69 .customizeDescription('Unknown tagging directive') };
70 }
71 const overrideMetadata = {};
72 if (headers['x-amz-server-side-encryption']) {
73 overrideMetadata['x-amz-server-side-encryption'] =
74 headers['x-amz-server-side-encryption'];
75 }
76 if (headers['x-amz-storage-class']) { // TODO: remove in CLDSRV-639
77 overrideMetadata['x-amz-storage-class'] =
78 headers['x-amz-storage-class'];
79 }
80 if (headers['x-amz-website-redirect-location']) {
81 overrideMetadata['x-amz-website-redirect-location'] =
82 headers['x-amz-website-redirect-location'];
83 }
84 const retentionHeaders = headers['x-amz-object-lock-mode']
85 && headers['x-amz-object-lock-retain-until-date'];
86 const legalHoldHeader = headers['x-amz-object-lock-legal-hold'];
87 if ((retentionHeaders || legalHoldHeader)
88 && !destBucketMD.isObjectLockEnabled()) {
89 return { error: errorInstances.InvalidRequest.customizeDescription(
90 'Bucket is missing ObjectLockConfiguration') };
91 }
92 // Cannot copy from same source and destination if no MD
93 // changed and no source version id
94 if (sourceIsDestination && whichMetadata === 'COPY' &&
95 Object.keys(overrideMetadata).length === 0 && !sourceVersionId) {
96 return { error: errorInstances.InvalidRequest.customizeDescription('This copy' +
97 ' request is illegal because it is trying to copy an ' +
98 'object to itself without changing the object\'s metadata, ' +
99 'storage class, website redirect location or encryption ' +
100 'attributes.') };
101 }
102 // If COPY, pull all x-amz-meta keys/values from source object
103 // Otherwise, pull all x-amz-meta keys/values from request headers
104 const userMetadata = whichMetadata === 'COPY' ?
105 getMetaHeaders(sourceObjMD) :
106 getMetaHeaders(headers);
107 if (userMetadata instanceof Error) {
108 log.debug('user metadata validation failed', {
109 error: userMetadata,
110 method: 'objectCopy',
111 });
112 return { error: userMetadata };
113 }

Callers 1

objectCopyFunction · 0.85

Calls 7

applyZenkoUserMDFunction · 0.85
locationConstraintCheckFunction · 0.85
removeAWSChunkedFunction · 0.85
getReplicationInfoFunction · 0.85
debugMethod · 0.80
getLocationConstraintMethod · 0.80
getOwnerMethod · 0.80

Tested by

no test coverage detected