Return user metadata in GetObjectAttributes API#6070
Return user metadata in GetObjectAttributes API#6070maeldonn wants to merge 10 commits intofeature/CLDSRV-817/get-object-attributesfrom
Conversation
2e7333e to
2b69771
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files
@@ Coverage Diff @@
## feature/CLDSRV-817/get-object-attributes #6070 +/- ##
============================================================================
+ Coverage 84.17% 84.20% +0.03%
============================================================================
Files 206 207 +1
Lines 13233 13253 +20
============================================================================
+ Hits 11139 11160 +21
+ Misses 2094 2093 -1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
95b17ef to
ab4f29a
Compare
64cd8a1 to
4a72a6d
Compare
ab4f29a to
fc3441c
Compare
4a72a6d to
92bd9be
Compare
4b757aa to
78dd47a
Compare
78dd47a to
1a3d966
Compare
| headers[headerName] | ||
| ?.split(',') | ||
| .map(attr => attr.trim()) | ||
| .map(attr => (supportedAttributes.has(attr) ? attr : attr.toLowerCase())) ?? []; |
There was a problem hiding this comment.
wait so it means even if the attribute is not in supportedAttribute, it will be returned as lower cased ?
Shouldn't this be a filter instead ?
I mean, ok I guess the overall function works because later there is the attributes.some() and has() thing, but could it be clearer
There was a problem hiding this comment.
Anyways, maybe the funciton is good enough as it is, but if you're able to make it a bit clearer it's nice, cause it's doing multiple thing that aren't completely obvious from the function name, it looks like it's gonna do some generic parsing, then ends up doing lowercasing and having a special case for x-amz-meta. Maybe renaming function name and intermediates variables help
There was a problem hiding this comment.
If it's not a supported attribute:
- It's user metadata so it's ok
- It's something else -> will throw an exception
There was a problem hiding this comment.
this seems uselessly innefficient: we traverse the list 3 times to do the same thing...
- trim() can be done in the same iteration, no need to the extra strings/list allocation
- isn't user metadata already mandated (by spec) to be lower case? do we do the same lower case conversion in other APIs? if not, not need to be more accommodating here
- if an attribute is in the
supportedAttributes, there is no point making another check for the prefix (and rechecking later it is a supported attribute, if there is no prefix)
| .map(attr => (supportedAttributes.has(attr) ? attr : attr.toLowerCase())) ?? []; | |
| const attributes = | |
| headers[headerName]?.split(',').map(attr => { | |
| const res = attr.trim()) | |
| if (!supportedAttributes.has(res) && !res.startsWith('x-amz-meta-')) { | |
| throw errorInstances.InvalidArgument.customizeDescription('Invalid attribute name specified.'); | |
| } | |
| return res; | |
| }); |
tests/functional/aws-node-sdk/test/object/objectGetAttributes.js
Outdated
Show resolved
Hide resolved
SylvainSenechal
left a comment
There was a problem hiding this comment.
some comments to address, 2 tests to add
| headers[headerName] | ||
| ?.split(',') | ||
| .map(attr => attr.trim()) | ||
| .map(attr => (supportedAttributes.has(attr) ? attr : attr.toLowerCase())) ?? []; |
There was a problem hiding this comment.
this seems uselessly innefficient: we traverse the list 3 times to do the same thing...
- trim() can be done in the same iteration, no need to the extra strings/list allocation
- isn't user metadata already mandated (by spec) to be lower case? do we do the same lower case conversion in other APIs? if not, not need to be more accommodating here
- if an attribute is in the
supportedAttributes, there is no point making another check for the prefix (and rechecking later it is a supported attribute, if there is no prefix)
| .map(attr => (supportedAttributes.has(attr) ? attr : attr.toLowerCase())) ?? []; | |
| const attributes = | |
| headers[headerName]?.split(',').map(attr => { | |
| const res = attr.trim()) | |
| if (!supportedAttributes.has(res) && !res.startsWith('x-amz-meta-')) { | |
| throw errorInstances.InvalidArgument.customizeDescription('Invalid attribute name specified.'); | |
| } | |
| return res; | |
| }); |
lib/api/bucketGet.js
Outdated
| let optionalAttributes; | ||
| try { | ||
| const headerName = 'x-amz-optional-object-attributes'; | ||
| optionalAttributes = parseAttributesHeaders(request.headers, headerName, new Set(['RestoreStatus'])); |
There was a problem hiding this comment.
The Set should not be allocated on every call, should be a constant
lib/api/objectGetAttributes.js
Outdated
| * @param {string[]} attributes - requested attributes | ||
| * @returns {object} - object containing requested user metadata key-value pairs | ||
| */ | ||
| function extractUserMetadata(objMD, attributes) { |
There was a problem hiding this comment.
there is already this logic in ListObjectv2, must be factorized...
lib/api/objectGetAttributes.js
Outdated
| } | ||
|
|
||
| const attributes = parseAttributesHeaders(headers); | ||
| const attributes = parseAttributesHeaders(headers, 'x-amz-object-attributes', supportedGetObjectAttributes, true); |
There was a problem hiding this comment.
this true here makes it hard to understand what is happening, and it can just as well be done here (it does not add any value to have a conditional behavior inside the parseAttributesHeaders function):
| const attributes = parseAttributesHeaders(headers, 'x-amz-object-attributes', supportedGetObjectAttributes, true); | |
| const attributes = parseAttributesHeaders(headers, 'x-amz-object-attributes', supportedGetObjectAttributes); | |
| if (attributes.length === 0) { | |
| throw .... | |
| } |
4868753 to
c762cd8
Compare
e040894 to
63d9d12
Compare
c762cd8 to
bef8034
Compare
704c58d to
34f10d2
Compare
3ebd2ab to
e118699
Compare
34f10d2 to
74c8a30
Compare
Issue: CLDSRV-817