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 May 21, 2024
2 parents 0acdab1 + 5073f0a commit 9412750
Show file tree
Hide file tree
Showing 30 changed files with 72 additions and 56 deletions.
54 changes: 27 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
name: Release

on:
push:
tags:
- v*
push:
tags:
- v*

jobs:
checks:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Install dependencies
run: npm install
- name: Build & archive
run: |
set -x
VERSION="${GITHUB_REF##*/}"
npm run webpack && tar -zcf "k6-jslib-aws-${VERSION}.tar.gz" -C dist .
- name: Create release with assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
VERSION="${GITHUB_REF##*/}"
gh release create "${VERSION}" "k6-jslib-aws-${VERSION}.tar.gz" "dist/*" --target "${GITHUB_SHA}" --title "${VERSION}"
checks:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Install dependencies
run: npm install
- name: Build & archive
run: |
set -x
VERSION="${GITHUB_REF##*/}"
npm run webpack && tar -zcf "k6-jslib-aws-${VERSION}.tar.gz" -C dist .
- name: Create release with assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
VERSION="${GITHUB_REF##*/}"
gh release create "${VERSION}" "k6-jslib-aws-${VERSION}.tar.gz" dist/* --target "${GITHUB_SHA}" --title "${VERSION}"
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If the jslib-aws does not support the service you need yet, the best way to get
2. The project files should be formatted using the [Prettier](https://prettier.io/) tool. The project has a `.prettierrc.json` file containing the tool's configuration.
3. The project uses webpack to produce build files. Because k6 does not have native support typescript, and its Javascript runtime does not support the `import` statement, the project uses webpack to produce a file containing all the code that k6 scripts can use. The project has a `webpack.config.js` file containing the tool's configuration. Each service is built into its dedicated file, and an overarching `aws.js` contains them for convenience.
4. To allow easier testing, files in the `src` directory are organized in a public/private structure. Files at the root of the folder are the public files; they import the content of the internal (private) directory and explicitly export the symbols that should be made available to the user. The internal files are the ones that contain the actual implementation of the service. The internal files are not exported and are not meant to be used directly by the user.
5. The project is tested in an end2end fashion using the [k6](https://k6.io/) tool. The tests live in the `tests` directory. The tests are written in Javascript and use the [k6 chai js](https://k6.io/docs/javascript-api/jslib/k6chaijs/) jslib to test the functionality of the library. The `npm test` command runs the test suites. The tests run in a docker container, and the `docker-compose.yml` file contains the configuration for the container. The docker-compose setup spins up a [localstack](https://https://github.com/localstack/localstack) setup, which emulates AWS locally, and the test script performs its assertions against it directly.
5. The project is tested in an end2end fashion using the [k6](https://k6.io/) tool. The tests live in the `tests` directory. The tests are written in Javascript and use the [k6 chai js](https://grafana.com/docs/k6/latest/javascript-api/jslib/k6chaijs) jslib to test the functionality of the library. The `npm test` command runs the test suites. The tests run in a docker container, and the `docker-compose.yml` file contains the configuration for the container. The docker-compose setup spins up a [localstack](https://github.com/localstack/localstack) setup, which emulates AWS locally, and the test script performs its assertions against it directly.

### Conventions

Expand All @@ -26,7 +26,7 @@ If the jslib-aws does not support the service you need yet, the best way to get
4. Most service operations require signing requests using the AWS V4 signature process. The `SignatureV4` construct exposed in the [`src/internal/signature.ts`](https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/signature.ts#L9) file allows signing requests to AWS services easily. Checkout the existing service implementations for examples of how to use it: [in S3Client](https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/s3.ts#L48), and [in SecretsManagerService](https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/secrets-manager.ts#L63) for instance.
5. Add a new [entry](https://webpack.js.org/concepts/entry-points/) in `webpack.config.js` to the service you created in Step 1.
6. Tests verifying that the service class works as expected should be added in the `tests/internal` directory. The dedicated test file should follow the same naming convention as the service class file, except it should have the `.js` extension. For example, if the service class file is named `systems-manager.ts`, the test file should be called `systems-manager.js`.
7. Test files should consists in a k6 script using the [k6 chai js](https://k6.io/docs/javascript-api/jslib/k6chaijs/) library, and exporting a single `{serviceName}TestSuite(data)` function. This function should consist of a set of `describe` statements containing the actual test assertions, as demonstrated in the [existing s3 test suite](https://github.com/grafana/k6-jslib-aws/blob/main/tests/internal/s3.js). The test suite should be imported and called in the [`tests/internal/index.js`](https://github.com/grafana/k6-jslib-aws/blob/main/tests/index.js) test script, which is the entry point for the test suite.
7. Test files should consists in a k6 script using the [k6 chai js](https://grafana.com/docs/k6/latest/javascript-api/jslib/k6chaijs) library, and exporting a single `{serviceName}TestSuite(data)` function. This function should consist of a set of `describe` statements containing the actual test assertions, as demonstrated in the [existing s3 test suite](https://github.com/grafana/k6-jslib-aws/blob/main/tests/internal/s3.js). The test suite should be imported and called in the [`tests/internal/index.js`](https://github.com/grafana/k6-jslib-aws/blob/main/tests/index.js) test script, which is the entry point for the test suite.
8. If the tests depend on a specific pre-existing state of the localstack setup, you can add a dedicated script in the `tests/internal/localstack_init` folder. Localstack will execute all the commands present in this script during its setup phase.
9. The `npm test` command runs the test suite. This command will build the project and run the tests against the spun-up localstack docker container. The `docker-compose.yml` file contains the configuration for the container.
10. Once the tests pass, the `src/index.ts` file should export the service class in the `src/index.ts` file so the user can use it.
Expand Down
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.11.2/s3.js'
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.12.0/s3.js'

const awsConfig = new AWSConfig({
region: __ENV.AWS_REGION,
Expand Down
2 changes: 1 addition & 1 deletion dist/aws.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aws.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/event-bridge.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/event-bridge.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kinesis.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kinesis.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kms.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lambda.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lambda.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/s3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/s3.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/secrets-manager.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/secrets-manager.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/signature.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/signature.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sqs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sqs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ssm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ssm.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.11.2",
"version": "0.12.0",
"description": "Create a distribution file for the aws jslib",
"main": "src/index.js",
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { InvalidSignatureError } from './internal/signature'
export { AWSConfig, InvalidAWSConfigError } from './internal/config'
export { AMZ_CONTENT_SHA256_HEADER, UNSIGNED_PAYLOAD } from './internal/constants'
export { KMSClient, KMSDataKey, KMSServiceError } from './internal/kms'
export { Endpoint } from './internal/endpoint'
export { SignatureV4 } from './internal/signature'
export { S3Bucket, S3Client, S3Object, S3ServiceError } from './internal/s3'
export {
Expand Down
7 changes: 6 additions & 1 deletion src/internal/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export class S3Client extends AWSClient {
secretAccessKey: this.awsConfig.secretAccessKey,
sessionToken: this.awsConfig.sessionToken,
},
uriEscapePath: false,

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

// Signing S3 requests requires the payload to be hashed
// and the checksum to be included in the request headers.
applyChecksum: true,
})
}
Expand Down
10 changes: 10 additions & 0 deletions src/internal/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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 + '/'

// Append the path to the URL
url += request.path
}

Expand Down Expand Up @@ -266,6 +271,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 + '/'

// Append the path to the URL
url += request.path
}

Expand Down

0 comments on commit 9412750

Please sign in to comment.