Skip to content

Commit

Permalink
Update sign and presign examples to reflect usage of Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed May 27, 2024
1 parent facad7d commit 3aba867
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
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

0 comments on commit 3aba867

Please sign in to comment.