Return user metadata in GetObjectAttributes API#6070
Return user metadata in GetObjectAttributes API#6070maeldonn wants to merge 5 commits intofeature/CLDSRV-817/get-object-attributesfrom
Conversation
2e7333e to
2b69771
Compare
❌ 4 Tests Failed:
View the full list of 4 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
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; | |
| }); |
4868753 to
c762cd8
Compare
e040894 to
63d9d12
Compare
c762cd8 to
bef8034
Compare
704c58d to
34f10d2
Compare
3ebd2ab to
e118699
Compare
34f10d2 to
74c8a30
Compare
tests/functional/aws-node-sdk/test/object/objectGetAttributes.js
Outdated
Show resolved
Hide resolved
benzekrimaha
left a comment
There was a problem hiding this comment.
couple comments but nothing blocking for me , approving
lib/api/bucketGet.js
Outdated
| userMetadata.add(attribute); | ||
| } | ||
|
|
||
| if (optionalAttributes.has('RestoreStatus')) { |
There was a problem hiding this comment.
the previous code was done purposely for efficiency to avoid repeatedly iterating through every attribute : not really an improvement here...
esp. ideally we want to reuse the whole logic (i.e. same single pass iteration), not just extractUserMetadata. Especially we don't really care if extra attributes are supported in this "generation" stage, as the "supported" attributes will be validated earlier when receiving the API (some the optionalAttributes should only contain the allowed parameters.
(but this requires following the same pattern as all APIs, and generate XML manually instead of using xml2js.Builder)
There was a problem hiding this comment.
Reverted to the listObjectV2 implementation and created an utility function for the two APIs.
ddde8bf to
fd17bad
Compare
7174c7d to
504d20e
Compare
Issue: CLDSRV-817