Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sqs-send-message-batch
Browse files Browse the repository at this point in the history
# Conflicts:
#	dist/aws.js
#	dist/aws.js.map
#	dist/index.js
#	dist/index.js.map
#	dist/sqs.js
#	dist/sqs.js.map
  • Loading branch information
Lorenz Junglas committed Jun 14, 2024
2 parents d263226 + f6b5dce commit 79b2bbc
Show file tree
Hide file tree
Showing 40 changed files with 45 additions and 105 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ jobs:
- name: Install npm packages
run: npm install

- name: Verify the build is up to date
run: |
npm run webpack -- --output-path="${RUNNER_TEMP}/dist"
if ! diff -r "${RUNNER_TEMP}/dist" dist > /dev/null; then
echo "Build is out of date, please run 'npm run webpack' and commit the changes"
exit 1
fi
- name: Install Go
uses: actions/setup-go@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules/
/volume
build/
dist/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { check } from 'k6'
import exec from 'k6/execution'
import http from 'k6/http'

import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.12.0/s3.js'
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.12.3/s3.js'

const awsConfig = new AWSConfig({
region: __ENV.AWS_REGION,
Expand Down
3 changes: 0 additions & 3 deletions dist/aws.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/aws.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/aws.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/event-bridge.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/event-bridge.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/event-bridge.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/kinesis.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/kinesis.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/kinesis.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/kms.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/kms.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/kms.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/lambda.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lambda.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/lambda.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/s3.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/s3.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/s3.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/secrets-manager.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/secrets-manager.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/secrets-manager.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions dist/signature.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/signature.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/sqs.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/sqs.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/sqs.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/ssm.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/ssm.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/ssm.js.map

This file was deleted.

22 changes: 8 additions & 14 deletions examples/signature-presign.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import http from 'k6/http'
import { check } from 'k6'

import {
AWSConfig,
SignatureV4,
AMZ_CONTENT_SHA256_HEADER,
} from '../dist/aws.js'
import { AWSConfig, Endpoint, SignatureV4, AMZ_CONTENT_SHA256_HEADER } from '../dist/aws.js'

const awsConfig = new AWSConfig({
region: __ENV.AWS_REGION,
Expand Down Expand Up @@ -39,19 +35,16 @@ export default function () {
method: 'GET',

/**
* The network protocol we will use to make the request.
*/
protocol: 'https',

/**
* The hostname of the service we will be making the request to.
* The endpoint of the service we will be making the request to.
*
* The endpoint is instantiated from a URL string, of the format: `{scheme}://{hostname}[:{port}]`
*/
hostname: 'test-jslib-aws.s3.us-east-1.amazonaws.com',
endpoint: new Endpoint('https://s3.us-east-1.amazonaws.com'),

/**
* The path of the request.
*/
path: '/bonjour.txt',
path: '/my-bucket/bonjour.txt',

/**
* The headers we will be sending in the request.
Expand All @@ -64,7 +57,8 @@ export default function () {
headers: { [AMZ_CONTENT_SHA256_HEADER]: 'UNSIGNED-PAYLOAD' },

/**
* Whether the URI should be escaped or not.
* Whether the path should be escaped or not (consult the AWS signature V4
* documentation for more details).
*/
uriEscapePath: false,

Expand Down
22 changes: 14 additions & 8 deletions examples/signature-sign.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import http from 'k6/http'

import { AWSConfig, SignatureV4 } from '../dist/signature.js'
import { AWSConfig, Endpoint, SignatureV4 } from '../dist/signature.js'

const awsConfig = new AWSConfig({
region: __ENV.AWS_REGION,
Expand Down Expand Up @@ -41,27 +41,33 @@ export default function () {
method: 'GET',

/**
* The network protocol we will use to make the request.
* The endpoint of the service we will be making the request to.
*
* The endpoint is instantiated from a URL string, of the format: `{scheme}://{hostname}[:{port}]`
*/
protocol: 'https',
endpoint: new Endpoint('https://s3.us-east-1.amazonaws.com'),

/**
* The hostname of the service we will be making the request to.
* The path of the request.
*/
hostname: 'test-jslib-aws.s3.us-east-1.amazonaws.com',
path: '/my-bucket/bonjour.txt',

/**
* The path of the request.
* The query parameters to include in the request.
*/
path: '/bonjour.txt',
query: {
abc: '123',
'easy as': ['do', 're', 'mi'],
},

/**
* The headers we will be sending in the request.
*/
headers: {},

/**
* Whether the URI should be escaped or not.
* Whether the path should be escaped or not (consult the
* AWS signature V4 documentation for more details).
*/
uriEscapePath: false,

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "k6-jslib-aws",
"repository": "https://github.com/grafana/k6-jslib-aws",
"version": "0.12.0",
"version": "0.12.3",
"description": "Create a distribution file for the aws jslib",
"main": "src/index.js",
"devDependencies": {
Expand Down
22 changes: 11 additions & 11 deletions src/internal/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class S3Client extends AWSClient {
},

// S3 requires the URI path to be escaped
uriEscapePath: true,
uriEscapePath: false,

// Signing S3 requests requires the payload to be hashed
// and the checksum to be included in the request headers.
Expand Down Expand Up @@ -109,7 +109,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: this.endpoint,
path: `/${bucketName}/`,
path: encodeURI(`/${bucketName}/`),
query: {
'list-type': '2',
prefix: prefix || '',
Expand Down Expand Up @@ -176,13 +176,13 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: this.endpoint,
path: `/${bucketName}/${objectKey}`,
path: encodeURI(`/${bucketName}/${objectKey}`),
headers: {},
},
{}
)

const res = await http.asyncRequest(method, signedRequest.url, signedRequest.body || null, {
const res = await http.asyncRequest(method, signedRequest.url, null, {
headers: signedRequest.headers,
})
this._handle_error('GetObject', res)
Expand Down Expand Up @@ -224,7 +224,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: this.endpoint,
path: `/${bucketName}/${objectKey}`,
path: encodeURI(`/${bucketName}/${objectKey}`),
headers: {
Host: this.endpoint.host,
...(params?.contentDisposition && {
Expand Down Expand Up @@ -263,7 +263,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: this.endpoint,
path: `/${bucketName}/${objectKey}`,
path: encodeURI(`/${bucketName}/${objectKey}`),
headers: {},
},
{}
Expand Down Expand Up @@ -300,7 +300,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: bucketEndpoint,
path: `/${destinationKey}`,
path: encodeURI(`/${destinationKey}`),
headers: {
'x-amz-copy-source': `${sourceBucket}/${sourceKey}`,
},
Expand Down Expand Up @@ -335,7 +335,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: bucketEndpoint,
path: `/${objectKey}`,
path: encodeURI(`/${objectKey}`),
headers: {},
query: { uploads: '' },
},
Expand Down Expand Up @@ -381,7 +381,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: bucketEndpoint,
path: `/${objectKey}`,
path: encodeURI(`/${objectKey}`),
headers: {},
body: data,
query: {
Expand Down Expand Up @@ -432,7 +432,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: bucketEndpoint,
path: `/${objectKey}`,
path: encodeURI(`/${objectKey}`),
headers: {},
body: body,
query: {
Expand Down Expand Up @@ -468,7 +468,7 @@ export class S3Client extends AWSClient {
{
method: method,
endpoint: bucketEndpoint,
path: `/${objectKey}`,
path: encodeURI(`/${objectKey}`),
headers: {},
query: {
uploadId: `${uploadId}`,
Expand Down
17 changes: 9 additions & 8 deletions src/internal/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ export class SignatureV4 {
// For HTTP/2 requests, you must include the :authority header instead of
// the host header. Different services might require other headers."
if (!request.headers[constants.HOST_HEADER]) {
request.headers[constants.HOST_HEADER] = request.endpoint.hostname
}

request.headers[constants.HOST_HEADER] = request.endpoint.hostname
}

// Filter out headers that will be generated and managed by the signing process.
// If the user provide any of those as part of the HTTPRequest's headers, they
Expand Down Expand Up @@ -163,9 +162,11 @@ export class SignatureV4 {
// If a request path was provided, add it to the URL
let url = request.endpoint.href
if (request.path) {
// Ensure there is a trailing slash at the end of the URL
// so that appending the path does not result in a malformed URL.
url = url.endsWith('/') ? url : url + '/'
// Ensure the URI and the request path are properly concatenated
// by adding a trailing slash to the URI if it's missing.
if (!url.endsWith('/') && !request.path.startsWith('/')) {
url += '/'
}

// Append the path to the URL
url += request.path
Expand Down Expand Up @@ -223,8 +224,8 @@ export class SignatureV4 {
// For HTTP/2 requests, you must include the :authority header instead of
// the host header. Different services might require other headers."
if (!request.headers[constants.HOST_HEADER]) {
request.headers[constants.HOST_HEADER] = originalRequest.endpoint.hostname
}
request.headers[constants.HOST_HEADER] = originalRequest.endpoint.hostname
}

// If the user provided a session token, include it in the signed url query string.
if (this.credentials.sessionToken) {
Expand Down

0 comments on commit 79b2bbc

Please sign in to comment.