Skip to content
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

Add copyObject function to S3Client #53

Merged
merged 3 commits into from
Jul 28, 2023
Merged

Conversation

bendennis
Copy link
Contributor

This PR adds a copyObject function to the S3Client.

@CLAassistant
Copy link

CLAassistant commented Jun 29, 2023

CLA assistant check
All committers have signed the CLA.

@@ -48,10 +48,10 @@ export function s3TestSuite(data) {
// Assert
expect(gotFirstObject).to.be.an('object')
expect(gotFirstObject.key).to.equal(data.s3.testObjects[0].key)
expect(gotFirstObject.body).to.equal(data.s3.testObjects[0].data)
expect(gotFirstObject.data).to.equal(data.s3.testObjects[0].body)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These getObject tests were broken, but they were passing since both values were undefined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch indeed 👍🏻 Thanks for fixing it on the way 🙇🏻

{}
)

const res = http.request(method, signedRequest.url, signedRequest.body || null, {
Copy link
Contributor Author

@bendennis bendennis Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm interested to get some additional thoughts on this line. The other methods default the request body to an empty string instead of null. When I default to '', the unit tests pass but I see the following error when using the copyObject in a real k6 test:

ERRO[0002] Uncaught (in promise) S3ServiceError: A header you provided implies functionality that is not implemented

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: body || null should be the default from now on, so, you did good 👍🏻

The body || '' is legacy, we just didn't get to fix it yet unfortunately. We're gonna prioritize that. In general, a reason we should prefer to use null instead of '' is that it avoids getting in the way of the signature process (AWS verifies the signature partly based on the hash of the body, and explicitly setting the body was a way for us to make sure that if no body was present, we would calculate the same hash than AWS).

@oleiade
Copy link
Member

oleiade commented Jul 24, 2023

Hey @bendennis 🙇🏻

So sorry for coming back to you so late, this PR got completely off my radar, and my email notifications.

Thanks a lot for your contribution, I'll take a look now 👀

Copy link
Member

@oleiade oleiade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀 🚀

{}
)

const res = http.request(method, signedRequest.url, signedRequest.body || null, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: body || null should be the default from now on, so, you did good 👍🏻

The body || '' is legacy, we just didn't get to fix it yet unfortunately. We're gonna prioritize that. In general, a reason we should prefer to use null instead of '' is that it avoids getting in the way of the signature process (AWS verifies the signature partly based on the hash of the body, and explicitly setting the body was a way for us to make sure that if no body was present, we would calculate the same hash than AWS).

@@ -48,10 +48,10 @@ export function s3TestSuite(data) {
// Assert
expect(gotFirstObject).to.be.an('object')
expect(gotFirstObject.key).to.equal(data.s3.testObjects[0].key)
expect(gotFirstObject.body).to.equal(data.s3.testObjects[0].data)
expect(gotFirstObject.data).to.equal(data.s3.testObjects[0].body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch indeed 👍🏻 Thanks for fixing it on the way 🙇🏻

@oleiade
Copy link
Member

oleiade commented Jul 24, 2023

Again, great work! 🎉 Thanks a lot for your contribution @bendennis 🙇🏻

I'll merge this and we will release a 0.8.1 or 0.9.0 version as soon as possible. Will ping you in the documentation PR when I open it, so you can double check that my documentation is in line with your interpretation 👍🏻

@oleiade oleiade self-assigned this Jul 24, 2023
@oleiade oleiade added the enhancement New feature or request label Jul 24, 2023
@oleiade oleiade added this to the 0.9.0 milestone Jul 24, 2023
@bendennis
Copy link
Contributor Author

Sounds good! Thanks @oleiade!

@oleiade oleiade merged commit 6931817 into grafana:main Jul 28, 2023
@bendennis bendennis deleted the AddCopyObject branch July 28, 2023 13:08
@oleiade
Copy link
Member

oleiade commented Jul 31, 2023

Here is the documentation for the feature: grafana/k6-docs#1273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants