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

Function objectPut

lib/api/objectPut.js:52–277  ·  view source on GitHub ↗

* PUT Object in the requested bucket. Steps include: * validating metadata for authorization, bucket and object existence etc. * store object data in datastore upon successful authorization * store object location returned by datastore and * object's (custom) headers in metadata * return the re

(authInfo, request, streamingV4Params, log, callback)

Source from the content-addressed store, hash-verified

50 * @return {undefined}
51 */
52function objectPut(authInfo, request, streamingV4Params, log, callback) {
53 log.debug('processing request', { method: 'objectPut' });
54
55 const putVersionId = request.headers['x-scal-s3-version-id'];
56 const isPutVersion = putVersionId || putVersionId === '';
57
58 let versionId;
59
60 if (putVersionId) {
61 const decodedVidResult = decodeVID(putVersionId);
62 if (decodedVidResult instanceof Error) {
63 log.trace('invalid x-scal-s3-version-id header', {
64 versionId: putVersionId,
65 error: decodedVidResult,
66 });
67 return process.nextTick(() => callback(decodedVidResult));
68 }
69 versionId = decodedVidResult;
70 }
71
72 const {
73 bucketName,
74 headers,
75 method,
76 objectKey,
77 parsedContentLength,
78 query,
79 } = request;
80 if (headers['x-amz-storage-class'] &&
81 !constants.validStorageClasses.includes(headers['x-amz-storage-class'])) {
82 log.trace('invalid storage-class header');
83 monitoring.promMetrics('PUT', request.bucketName,
84 errorInstances.InvalidStorageClass.code, 'putObject');
85 return callback(errors.InvalidStorageClass);
86 }
87 if (!aclUtils.checkGrantHeaderValidity(headers)) {
88 log.trace('invalid acl header');
89 monitoring.promMetrics('PUT', request.bucketName, 400,
90 'putObject');
91 return callback(errors.InvalidArgument);
92 }
93 const queryContainsVersionId = checkQueryVersionId(query);
94 if (queryContainsVersionId instanceof Error) {
95 return callback(queryContainsVersionId);
96 }
97
98 const keyLengthError = validateObjectKeyLength(objectKey, config.objectKeyByteLimit);
99 if (keyLengthError) {
100 return callback(keyLengthError);
101 }
102
103 const size = request.parsedContentLength;
104 if (Number.parseInt(size, 10) > constants.maximumAllowedUploadSize
105 && !config.bypassMaxPutObjectSize) {
106 log.debug('Upload size exceeds maximum allowed for a single PUT',
107 { size });
108 return callback(errors.EntityTooLarge);
109 }

Callers 15

routeBackbeat.jsFile · 0.85
putObjectAndCheckMDFunction · 0.85
copyObjectFunction · 0.85
objectRestore.jsFile · 0.85
testAuthFunction · 0.85
objectPut.jsFile · 0.85
bucketDelete.jsFile · 0.85
testAuthFunction · 0.85
objectDelete.jsFile · 0.85
objectPutACL.jsFile · 0.85

Calls 15

decodeVIDFunction · 0.85
checkQueryVersionIdFunction · 0.85
hasNonPrintablesFunction · 0.85
validateChecksumHeadersFunction · 0.85
updateEncryptionFunction · 0.85
collectCorsHeadersFunction · 0.85
validatePutVersionIdFunction · 0.85
cleanUpBucketFunction · 0.85
setSSEHeadersFunction · 0.85
validateHeadersFunction · 0.85

Tested by

no test coverage detected