-
Notifications
You must be signed in to change notification settings - Fork 255
Support the new API GetObjectAttributes #6060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development/9.1
Are you sure you want to change the base?
Changes from all commits
b5ba3a4
15650ee
c7a132b
392ad9b
6e342f3
92bd9be
1f928b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| const { errorInstances } = require('arsenal'); | ||
| const { allowedObjectAttributes } = require('../../../../constants'); | ||
|
|
||
| /** | ||
| * parseAttributesHeaders - Parse and validate the x-amz-object-attributes header | ||
| * @param {object} headers - request headers | ||
| * @returns {string[]} - array of valid attribute names | ||
| * @throws {Error} - InvalidRequest if header is missing/empty, InvalidArgument if attribute is invalid | ||
| */ | ||
| function parseAttributesHeaders(headers) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is already a very similar function in @DarkIsDude PR, which efficiently handles validation & parsing: should we not "merge" both code (i.e. typically make your code extend his) ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be updated in another PR (process user metadata in GetObjectAttributes).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? it means we are duplicating the code now instead of just rebasing this PR on top of the other and handling it just once...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because user metadata is already handled in the listObjectV2 API. That's not the case here. That would take me to an intermediate step where I should add unnecessary complexity.... Edit: Done here |
||
| const attributes = headers['x-amz-object-attributes']?.split(',').map(attr => attr.trim()) ?? []; | ||
| if (attributes.length === 0) { | ||
| throw errorInstances.InvalidRequest.customizeDescription( | ||
| 'The x-amz-object-attributes header specifying the attributes to be retrieved is either missing or empty', | ||
maeldonn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
|
|
||
| if (attributes.some(attr => !allowedObjectAttributes.has(attr))) { | ||
| throw errorInstances.InvalidArgument.customizeDescription('Invalid attribute name specified.'); | ||
| } | ||
|
|
||
| return attributes; | ||
| } | ||
|
|
||
| module.exports = parseAttributesHeaders; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| const { promisify } = require('util'); | ||
| const xml2js = require('xml2js'); | ||
| const { errors } = require('arsenal'); | ||
| const { standardMetadataValidateBucketAndObj } = require('../metadata/metadataUtils'); | ||
| const collectCorsHeaders = require('../utilities/collectCorsHeaders'); | ||
| const parseAttributesHeaders = require('./apiUtils/object/parseAttributesHeader'); | ||
| const { decodeVersionId, getVersionIdResHeader } = require('./apiUtils/object/versioning'); | ||
| const { checkExpectedBucketOwner } = require('./apiUtils/authorization/bucketOwner'); | ||
| const { pushMetric } = require('../utapi/utilities'); | ||
| const { getPartCountFromMd5 } = require('./apiUtils/object/partInfo'); | ||
|
|
||
| const OBJECT_GET_ATTRIBUTES = 'objectGetAttributes'; | ||
|
|
||
| const checkExpectedBucketOwnerPromise = promisify(checkExpectedBucketOwner); | ||
| const validateBucketAndObj = promisify(standardMetadataValidateBucketAndObj); | ||
|
|
||
| /** | ||
| * buildXmlResponse - Build XML response for GetObjectAttributes | ||
| * @param {object} objMD - object metadata | ||
| * @param {array} attributes - requested attributes | ||
| * @returns {string} XML response | ||
| */ | ||
| function buildXmlResponse(objMD, attributes) { | ||
| const attrResp = {}; | ||
|
|
||
| if (attributes.includes('ETag')) { | ||
| attrResp.ETag = objMD['content-md5']; | ||
| } | ||
|
|
||
| // NOTE: Checksum is not implemented | ||
| if (attributes.includes('Checksum')) { | ||
| attrResp.Checksum = {}; | ||
maeldonn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (attributes.includes('ObjectParts')) { | ||
| const partCount = getPartCountFromMd5(objMD); | ||
| if (partCount) { | ||
| attrResp.ObjectParts = { PartsCount: partCount }; | ||
| } | ||
| } | ||
|
|
||
| if (attributes.includes('StorageClass')) { | ||
| attrResp.StorageClass = objMD['x-amz-storage-class']; | ||
maeldonn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (attributes.includes('ObjectSize')) { | ||
| attrResp.ObjectSize = objMD['content-length']; | ||
| } | ||
|
|
||
| const builder = new xml2js.Builder(); | ||
| return builder.buildObject({ GetObjectAttributesResponse: attrResp }); | ||
| } | ||
|
|
||
| /** | ||
| * objectGetAttributes - Retrieves all metadata from an object without returning the object itself | ||
| * @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info | ||
| * @param {object} request - http request object | ||
| * @param {object} log - Werelogs logger | ||
| * @param {function} callback - callback optional to keep backward compatibility | ||
| * @returns {Promise<object>} - { xml, responseHeaders } | ||
| * @throws {ArsenalError} NoSuchVersion - if versionId specified but not found | ||
| * @throws {ArsenalError} NoSuchKey - if object not found | ||
| * @throws {ArsenalError} MethodNotAllowed - if object is a delete marker | ||
| */ | ||
| async function objectGetAttributes(authInfo, request, log, callback) { | ||
| if (callback) { | ||
| return objectGetAttributes(authInfo, request, log) | ||
| .then(result => callback(null, result.xml, result.responseHeaders)) | ||
| .catch(err => callback(err, null, err.responseHeaders ?? {})); | ||
| } | ||
|
|
||
| log.trace('processing request', { method: OBJECT_GET_ATTRIBUTES }); | ||
| const { bucketName, objectKey, headers, actionImplicitDenies } = request; | ||
|
|
||
| const versionId = decodeVersionId(request.query); | ||
| if (versionId instanceof Error) { | ||
| log.debug('invalid versionId query', { | ||
| method: OBJECT_GET_ATTRIBUTES, | ||
| versionId: request.query.versionId, | ||
| error: versionId, | ||
| }); | ||
| throw versionId; | ||
maeldonn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const metadataValParams = { | ||
| authInfo, | ||
| bucketName, | ||
| objectKey, | ||
| versionId, | ||
| getDeleteMarker: true, | ||
| requestType: request.apiMethods || OBJECT_GET_ATTRIBUTES, | ||
| request, | ||
| }; | ||
|
|
||
| let bucket, objMD; | ||
| try { | ||
| ({ bucket, objMD } = await validateBucketAndObj(metadataValParams, actionImplicitDenies, log)); | ||
| await checkExpectedBucketOwnerPromise(headers, bucket, log); | ||
| } catch (err) { | ||
| log.debug('error validating bucket and object', { | ||
| method: OBJECT_GET_ATTRIBUTES, | ||
| bucket: bucketName, | ||
| key: objectKey, | ||
| versionId, | ||
| error: err, | ||
| }); | ||
| throw err; | ||
| } | ||
|
|
||
| const responseHeaders = collectCorsHeaders(headers.origin, request.method, bucket); | ||
|
|
||
| if (!objMD) { | ||
| log.debug('object not found', { | ||
| method: OBJECT_GET_ATTRIBUTES, | ||
| bucket: bucketName, | ||
| key: objectKey, | ||
| versionId, | ||
| }); | ||
| const err = versionId ? errors.NoSuchVersion : errors.NoSuchKey; | ||
| err.responseHeaders = responseHeaders; | ||
| throw err; | ||
| } | ||
|
|
||
| responseHeaders['x-amz-version-id'] = getVersionIdResHeader(bucket.getVersioningConfiguration(), objMD); | ||
| responseHeaders['Last-Modified'] = objMD['last-modified'] && new Date(objMD['last-modified']).toUTCString(); | ||
|
|
||
| if (objMD.isDeleteMarker) { | ||
| log.debug('attempt to get attributes of a delete marker', { | ||
| method: OBJECT_GET_ATTRIBUTES, | ||
| bucket: bucketName, | ||
| key: objectKey, | ||
| versionId, | ||
| }); | ||
| responseHeaders['x-amz-delete-marker'] = true; | ||
| const err = errors.MethodNotAllowed; | ||
| err.responseHeaders = responseHeaders; | ||
| throw err; | ||
| } | ||
|
|
||
| const attributes = parseAttributesHeaders(headers); | ||
|
|
||
| pushMetric(OBJECT_GET_ATTRIBUTES, log, { | ||
| authInfo, | ||
| bucket: bucketName, | ||
| keys: [objectKey], | ||
| versionId: objMD?.versionId, | ||
| location: objMD?.dataStoreName, | ||
| }); | ||
|
|
||
| const xml = buildXmlResponse(objMD, attributes); | ||
| return { xml, responseHeaders }; | ||
| } | ||
|
|
||
| module.exports = objectGetAttributes; | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |||||
| "dependencies": { | ||||||
| "@azure/storage-blob": "^12.28.0", | ||||||
| "@hapi/joi": "^17.1.1", | ||||||
| "arsenal": "git+https://github.com/scality/arsenal#8.2.44", | ||||||
| "arsenal": "git+https://github.com/scality/Arsenal#feature/ARSN-549/get-object-attributes", | ||||||
|
||||||
| "arsenal": "git+https://github.com/scality/Arsenal#feature/ARSN-549/get-object-attributes", | |
| "arsenal": "git+https://github.com/scality/Arsenal#8.2.0", |
Uh oh!
There was an error while loading. Please reload this page.