From 3aba86766fa1e6f3a81d025629b1bc06fed72457 Mon Sep 17 00:00:00 2001 From: oleiade Date: Mon, 27 May 2024 11:34:42 +0200 Subject: [PATCH] Update sign and presign examples to reflect usage of Endpoint --- examples/signature-presign.js | 22 ++++++++-------------- examples/signature-sign.js | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/signature-presign.js b/examples/signature-presign.js index 61c5c02..822be58 100644 --- a/examples/signature-presign.js +++ b/examples/signature-presign.js @@ -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, @@ -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. @@ -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, diff --git a/examples/signature-sign.js b/examples/signature-sign.js index 6135000..8da6d67 100644 --- a/examples/signature-sign.js +++ b/examples/signature-sign.js @@ -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, @@ -41,19 +41,24 @@ 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. @@ -61,7 +66,8 @@ export default function () { 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,