k6-jslib-aws icon indicating copy to clipboard operation
k6-jslib-aws copied to clipboard

Fix endpoint argument in `signature.sign` examples

Open oleiade opened this issue 1 year ago • 4 comments

We recently changed how the library handles endpoints to support third-party S3-compatible providers as per #21, #57, etc.

We have recently noticed that the example didn't reflect the usage of the new endpoint argument of the signature.sign, and signature.presign methods. We should update those, as well as the documentation to reflect it 👍🏻

oleiade avatar Oct 09 '23 13:10 oleiade

I'm trying to use these methods and am having difficulty parsing the new endpoint syntax - any help or intermediate links while you work on the docs would be much appreciated!

bd-g avatar Nov 29 '23 22:11 bd-g

Hey @bd-g thanks for pointing that out, we're gonna improve the documentation accordingly 🤝

Although it's not clearly documented, the Endpoint type is actually exported by the signature module, thus, in the meantime, something along the lines of the following should allow you to move forward:

import { Endpoint, SignatureV4 } from 'https://jslib.k6.io/aws/0.11.0/signature.js';  // or aws.js

// instantiate a signature object
const signer = new SignatureV4(...)

// and pass the endpoint here
signer.sign({
    method: 'POST',
    endpoint: new Endpoint('https://s3.us-west-1.amazonaws.com'),
    path: '/',
    headers: {
        host: 's3.us-west-1.amazonaws.com',
})

For more details, here's the Endpoint type definition: https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/endpoint.ts

Let me know if that unblocked you 🙇🏻

oleiade avatar Dec 12 '23 11:12 oleiade

I'll have to go and check, but that is similar to what I tried to do just from reading the code. I was getting errors with the host name being undefined, somehow my endpoint url wasn't being parsed properly so I'll go back and post my exact example.

bd-g avatar Dec 12 '23 12:12 bd-g

The documentation will be updated to cater to this change in: https://github.com/grafana/k6-docs/pull/1585

oleiade avatar May 13 '24 14:05 oleiade