Skip to content

Commit d8eab4c

Browse files
authored
chore: update dependencies and bump to 1.0.0 (#11)
1 parent 08b008a commit d8eab4c

File tree

4 files changed

+49
-53
lines changed

4 files changed

+49
-53
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# deno_aws_sign_v4
22

33
![ci](https://github.com/lucacasonato/deno_aws_sign_v4/workflows/ci/badge.svg)
4-
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/aws_sign_v4@0.1.5/mod.ts)
4+
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/aws_sign_v4@1.0.0/mod.ts)
55

66
Generates AWS Signature V4 for AWS low-level REST APIs.
77

88
## Example
99

10-
The below example will generate signed headers based on the region and credentials in following ENV variables:
10+
The below example will generate signed headers based on the region and
11+
credentials in following ENV variables:
1112

1213
- AWS_ACCESS_KEY_ID
1314
- AWS_SECRET_ACCESS_KEY
1415
- AWS_SESSION_TOKEN
1516
- AWS_REGION
1617

1718
```typescript
18-
import { AWSSignerV4 } from "https://deno.land/x/aws_sign_v4@0.1.5/mod.ts";
19+
import { AWSSignerV4 } from "https://deno.land/x/aws_sign_v4@1.0.0/mod.ts";
1920

2021
const signer = new AWSSignerV4();
2122
const body = new TextEncoder().encode("Hello World!");
@@ -29,7 +30,8 @@ const req = await signer.sign("s3", request);
2930
const response = await fetch(req);
3031
```
3132

32-
You can also explicitly specify credentials and a region when constructing a new `AWSSignerV4`:
33+
You can also explicitly specify credentials and a region when constructing a new
34+
`AWSSignerV4`:
3335

3436
```typescript
3537
const signer = new AWSSignerV4("us-east-1", {
@@ -48,4 +50,6 @@ const signer = new AWSSignerV4("us-east-1", {
4850

4951
The module is licenced under GPL-3.0. For more see the LICENCE file.
5052

51-
This module is forked from @silver-xu's work in [https://github.com/silver-xu/deno-aws-sign-v4]. Many thanks to them. This fork has some large feature improvements and bug fixes, and has tests.
53+
This module is forked from @silver-xu's work in
54+
[https://github.com/silver-xu/deno-aws-sign-v4]. Many thanks to them. This fork
55+
has some large feature improvements and bug fixes, and has tests.

deps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export { hmac } from "https://denopkg.com/chiefbiiko/hmac@v1.0.2/mod.ts";
1+
export { hmac } from "https://deno.land/x/hmac@v2.0.1/mod.ts";
22

3-
import { createHash } from "https://deno.land/std@0.79.0/hash/mod.ts";
3+
import { createHash } from "https://deno.land/std@0.84.0/hash/mod.ts";
44
export function sha256Hex(data: string | Uint8Array): string {
55
const hasher = createHash("sha256");
66
hasher.update(data);

mod.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export interface Credentials {
2525
* credentials for this API using the options in the
2626
* constructor, or let them be aquired automatically
2727
* through environment variables.
28-
*
28+
*
2929
* Example usage:
30-
*
31-
* ```ts
30+
*
31+
* ```ts
3232
* const signer = new AWSSignerV4();
3333
* const body = new TextEncoder().encode("Hello World!")
3434
* const request = new Request("https://test-bucket.s3.amazonaws.com/test", {
@@ -47,7 +47,7 @@ export class AWSSignerV4 implements Signer {
4747
/**
4848
* If no region or credentials are specified, they will
4949
* automatically be aquired from environment variables.
50-
*
50+
*
5151
* Region is aquired from `AWS_REGION`. The credentials
5252
* are acquired from `AWS_ACCESS_KEY_ID`,
5353
* `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN`.
@@ -60,18 +60,15 @@ export class AWSSignerV4 implements Signer {
6060
/**
6161
* Use this to create the signed headers required to
6262
* make a call to an AWS API.
63-
*
64-
* @param service This is the AWS service, e.g. `s3` for s3, `dynamodb` for DynamoDB
63+
*
64+
* @param service This is the AWS service, e.g. `s3` for s3, `dynamodb` for DynamoDB
6565
* @param url The URL for the request to sign.
6666
* @param request The request method of the request to sign.
6767
* @param headers Other headers to include while signing.
6868
* @param body The body for PUT/POST methods.
6969
* @returns {RequestHeaders} - the signed request headers
7070
*/
71-
public async sign(
72-
service: string,
73-
request: Request,
74-
): Promise<Request> {
71+
public async sign(service: string, request: Request): Promise<Request> {
7572
const date = new Date();
7673
const amzdate = toAmz(date);
7774
const datestamp = toDateStamp(date);
@@ -127,23 +124,20 @@ export class AWSSignerV4 implements Signer {
127124

128125
headers.set("Authorization", authHeader);
129126

130-
return new Request(
131-
request.url,
132-
{
133-
headers,
134-
method: request.method,
135-
body,
136-
cache: request.cache,
137-
credentials: request.credentials,
138-
integrity: request.integrity,
139-
keepalive: request.keepalive,
140-
mode: request.mode,
141-
redirect: request.redirect,
142-
referrer: request.referrer,
143-
referrerPolicy: request.referrerPolicy,
144-
signal: request.signal,
145-
},
146-
);
127+
return new Request(request.url, {
128+
headers,
129+
method: request.method,
130+
body,
131+
cache: request.cache,
132+
credentials: request.credentials,
133+
integrity: request.integrity,
134+
keepalive: request.keepalive,
135+
mode: request.mode,
136+
redirect: request.redirect,
137+
referrer: request.referrer,
138+
referrerPolicy: request.referrerPolicy,
139+
signal: request.signal,
140+
});
147141
}
148142

149143
#getDefaultCredentials = (): Credentials => {

mod_test.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AWSSignerV4 } from "./mod.ts";
22
import {
33
assertEquals,
44
assertStringIncludes,
5-
} from "https://deno.land/std@0.79.0/testing/asserts.ts";
5+
} from "https://deno.land/std@0.84.0/testing/asserts.ts";
66

77
Deno.test("construct from env vars", async () => {
88
Deno.env.set("AWS_ACCESS_KEY_ID", "examplekey");
@@ -13,18 +13,17 @@ Deno.test("construct from env vars", async () => {
1313
const signer = new AWSSignerV4();
1414
const req = await signer.sign(
1515
"dynamodb",
16-
new Request(
17-
"https://test.dynamodb.us-east-1.amazonaws.com",
18-
{
19-
method: "GET",
20-
headers: { "x-hello": "world" },
21-
body: "A dynamodb request!",
22-
},
23-
),
16+
new Request("https://test.dynamodb.us-east-1.amazonaws.com", {
17+
method: "GET",
18+
headers: { "x-hello": "world" },
19+
body: "A dynamodb request!",
20+
}),
2421
);
2522
const now = new Date();
2623
const today = `${now.getFullYear()}${
27-
(now.getMonth() + 1).toString().padStart(2, "0")
24+
(now.getMonth() + 1)
25+
.toString()
26+
.padStart(2, "0")
2827
}${now.getDate().toString().padStart(2, "0")}`;
2928
assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`);
3029
assertEquals(req.headers.get("x-amz-security-token"), "sessiontoken");
@@ -47,18 +46,17 @@ Deno.test("construct manually", async () => {
4746
});
4847
const req = await signer.sign(
4948
"dynamodb",
50-
new Request(
51-
"https://test.dynamodb.us-east-1.amazonaws.com",
52-
{
53-
method: "GET",
54-
headers: { "x-hello": "world" },
55-
body: "A dynamodb request!",
56-
},
57-
),
49+
new Request("https://test.dynamodb.us-east-1.amazonaws.com", {
50+
method: "GET",
51+
headers: { "x-hello": "world" },
52+
body: "A dynamodb request!",
53+
}),
5854
);
5955
const now = new Date();
6056
const today = `${now.getFullYear()}${
61-
(now.getMonth() + 1).toString().padStart(2, "0")
57+
(now.getMonth() + 1)
58+
.toString()
59+
.padStart(2, "0")
6260
}${now.getDate().toString().padStart(2, "0")}`;
6361
assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`);
6462
assertEquals(req.headers.get("x-amz-security-token"), "session_token");

0 commit comments

Comments
 (0)