Conversation
Hello benzekrimaha,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
4555ab4 to
cf2aadd
Compare
This commit introduces a middleware to fix the PutObject warning that occurs when the content length is not provided. This middleware checks for the presence of the content length header and sets it to 0 if it is missing or appropriately handles it, ensuring that the PutObject operation can proceed without warnings. This ensures that the PutObject operation can proceed without warnings. Issue: ZENKO-5128
19ccb35 to
3fc5dc9
Compare
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
|
| }); | ||
|
|
||
| const scalityS3Client = new S3Client({ | ||
| function attachContentLengthMiddleware(client) { |
There was a problem hiding this comment.
not clear why we need this middleware : it would be required to automatically compute the ContentLength from Body.... but in uploadSetup() you systematically set the value already (and conversely: if we already add this middleware, no point doing it as well in uploadSetup)
There was a problem hiding this comment.
In uploadSetup it's setup when the body is empty only , this one is to avoid having to put the contentLength each time we call the method , the middleWare is called upon client creation
There was a problem hiding this comment.
after checking => UploadSetup runs only in the CLI cucumber steps, so it has to inject contentLength (including the zero-byte PutObject fallback). The middleware sits on the Node SDK clients used by the node test suite, which never call uploadSetup, so it fills ContentLength there. Two separate harnesses, two helpers; both are needed
There was a problem hiding this comment.
on second read : I understand we can't use the same "fix" as CTST, but I wonder if we have that many cases where adding the length is needed?
If it is only in a few places, would be much simpler to just update these few calls to make "correct" calls to the SDK v3. This may increase the length of the change (PutObjectCommand is used 36 times, though we may not need to fix them all), but it will have much lower cognitive complexity, and will avoid leaving incorrect code here which may be copy-pasted (to some other repo) and fail there. Especially since this is not seamless anyway, as the client must be created in some custom way.
| client.middlewareStack.add( | ||
| (next, context) => async args => { | ||
| const input = args.input || {}; | ||
| if (context?.commandName === 'PutObjectCommand' |
There was a problem hiding this comment.
- why only
PutObjectCommand? why not as well put part ? - is it not the same logic as below, and just another kind of
Body?
| if (context?.commandName === 'PutObjectCommand' | |
| if (input.ContentLength !== undefined || context?.commandName !== 'PutObjectCommand') { | |
| return next(args); | |
| } | |
| if (!input.Body) { | |
| input.Body = ''; | |
| input.ContentLength = 0; | |
| } else if (Buffer.isBuffer(input.Body)) { | |
| input.ContentLength = input.Body.length; | |
| } else [...] |
There was a problem hiding this comment.
The PutObject only guard is just for the case where a test creates an empty object without providing a body. In that situation the SDK can’t compute contentLength, so we synthesise both values before sending the command. Every other flow (including all UploadPart calls) already pass a real body, for which we calculate the payload's contentLength automatically.
There was a problem hiding this comment.
- ok-ish for first question (maybe we don't go into that path, but it would not harm to handle it as well?)
- suggestion for simplification still stands, code is nested and harder to read than it should...
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
The following reviewers are expecting changes from the author, or must review again: |
| const input = args.input || {}; | ||
| if (context?.commandName === 'PutObjectCommand' | ||
| && (input.Body === undefined || input.Body === null)) { | ||
| input.Body = ''; |
There was a problem hiding this comment.
are you sure you need to modify body, I think we just need to have content length set to a value
There was a problem hiding this comment.
we only do so when it's undefined or null as an additionnal safety gate
SylvainSenechal
left a comment
There was a problem hiding this comment.
Works for me but might be other less intrusive method than a global middleware, I think passing the value ContentLength: xx to all putObjectCommand could've fixed it. We have ~25 putObjectCommand in zenko test, but I think everytime, the content length is very well known in advance as an hardcoded value (or 0)
Issue: ZENKO-5128