Skip to content

Commit 2d22db2

Browse files
authored
chore: update for deno 1.9.x (#14)
1 parent d8eab4c commit 2d22db2

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ on:
88

99
jobs:
1010
build:
11-
name: build-${{ matrix.deno-version == 'nightly' && 'nightly' || 'release' }}-${{ matrix.unstable && 'unstable' || 'stable' }}-${{ matrix.no-check && 'nocheck' || 'tsc' }}
11+
name: build-${{ matrix.deno-version == 'canary' && 'canary' || 'release' }}-${{ matrix.unstable && 'unstable' || 'stable' }}-${{ matrix.no-check && 'nocheck' || 'tsc' }}
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
deno-version: [v1.x, nightly]
15+
deno-version: [v1.x, canary]
1616
unstable: [false, true]
1717
no-check: [false, true]
1818
steps:
19-
- name: Setup Deno environment
20-
uses: denolib/setup-deno@v2.3.0
19+
- name: Setup Deno
20+
uses: denoland/setup-deno@main
2121
with:
22-
deno-version: ${{ matrix.deno-version }}
22+
deno-version: ${{ matrix.deno }}
2323

2424
- uses: actions/checkout@v2
2525

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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/[email protected].0/mod.ts)
4+
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/[email protected].1/mod.ts)
55

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

@@ -16,7 +16,7 @@ credentials in following ENV variables:
1616
- AWS_REGION
1717

1818
```typescript
19-
import { AWSSignerV4 } from "https://deno.land/x/[email protected].0/mod.ts";
19+
import { AWSSignerV4 } from "https://deno.land/x/[email protected].1/mod.ts";
2020

2121
const signer = new AWSSignerV4();
2222
const body = new TextEncoder().encode("Hello World!");

deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { hmac } from "https://deno.land/x/[email protected]/mod.ts";
22

3-
import { createHash } from "https://deno.land/std@0.84.0/hash/mod.ts";
3+
import { createHash } from "https://deno.land/std@0.95.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: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export class AWSSignerV4 implements Signer {
9595
signedHeaders = signedHeaders.substring(0, signedHeaders.length - 1);
9696
const body = request.body
9797
? new Uint8Array(await request.arrayBuffer())
98-
: new Uint8Array();
99-
const payloadHash = sha256Hex(body);
98+
: null;
99+
const payloadHash = sha256Hex(body ?? new Uint8Array());
100100

101101
const { awsAccessKeyId, awsSecretKey } = this.credentials;
102102

@@ -128,15 +128,7 @@ export class AWSSignerV4 implements Signer {
128128
headers,
129129
method: request.method,
130130
body,
131-
cache: request.cache,
132-
credentials: request.credentials,
133-
integrity: request.integrity,
134-
keepalive: request.keepalive,
135-
mode: request.mode,
136131
redirect: request.redirect,
137-
referrer: request.referrer,
138-
referrerPolicy: request.referrerPolicy,
139-
signal: request.signal,
140132
});
141133
}
142134

mod_test.ts

Lines changed: 9 additions & 5 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.84.0/testing/asserts.ts";
5+
} from "https://deno.land/std@0.95.0/testing/asserts.ts";
66

77
Deno.test("construct from env vars", async () => {
88
Deno.env.set("AWS_ACCESS_KEY_ID", "examplekey");
@@ -14,7 +14,7 @@ Deno.test("construct from env vars", async () => {
1414
const req = await signer.sign(
1515
"dynamodb",
1616
new Request("https://test.dynamodb.us-east-1.amazonaws.com", {
17-
method: "GET",
17+
method: "POST",
1818
headers: { "x-hello": "world" },
1919
body: "A dynamodb request!",
2020
}),
@@ -25,6 +25,8 @@ Deno.test("construct from env vars", async () => {
2525
.toString()
2626
.padStart(2, "0")
2727
}${now.getDate().toString().padStart(2, "0")}`;
28+
assertEquals(req.method, "POST");
29+
assertEquals(await req.text(), "A dynamodb request!");
2830
assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`);
2931
assertEquals(req.headers.get("x-amz-security-token"), "sessiontoken");
3032
assertEquals(req.headers.get("x-hello"), "world");
@@ -34,7 +36,7 @@ Deno.test("construct from env vars", async () => {
3436
);
3537
assertStringIncludes(
3638
req.headers.get("Authorization")!,
37-
`AWS4-HMAC-SHA256 Credential=examplekey/${today}/us-east-1/dynamodb/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-hello, Signature=`,
39+
`AWS4-HMAC-SHA256 Credential=examplekey/${today}/us-east-1/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-security-token;x-hello, Signature=`,
3840
);
3941
});
4042

@@ -47,7 +49,7 @@ Deno.test("construct manually", async () => {
4749
const req = await signer.sign(
4850
"dynamodb",
4951
new Request("https://test.dynamodb.us-east-1.amazonaws.com", {
50-
method: "GET",
52+
method: "POST",
5153
headers: { "x-hello": "world" },
5254
body: "A dynamodb request!",
5355
}),
@@ -58,6 +60,8 @@ Deno.test("construct manually", async () => {
5860
.toString()
5961
.padStart(2, "0")
6062
}${now.getDate().toString().padStart(2, "0")}`;
63+
assertEquals(req.method, "POST");
64+
assertEquals(await req.text(), "A dynamodb request!");
6165
assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`);
6266
assertEquals(req.headers.get("x-amz-security-token"), "session_token");
6367
assertEquals(req.headers.get("x-hello"), "world");
@@ -67,7 +71,7 @@ Deno.test("construct manually", async () => {
6771
);
6872
assertStringIncludes(
6973
req.headers.get("Authorization")!,
70-
`AWS4-HMAC-SHA256 Credential=example_key/${today}/us-east-2/dynamodb/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-hello, Signature=`,
74+
`AWS4-HMAC-SHA256 Credential=example_key/${today}/us-east-2/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-security-token;x-hello, Signature=`,
7175
);
7276
});
7377

0 commit comments

Comments
 (0)