Skip to content

Commit

Permalink
chore: update for deno 1.9.x (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Apr 25, 2021
1 parent d8eab4c commit 2d22db2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ on:

jobs:
build:
name: build-${{ matrix.deno-version == 'nightly' && 'nightly' || 'release' }}-${{ matrix.unstable && 'unstable' || 'stable' }}-${{ matrix.no-check && 'nocheck' || 'tsc' }}
name: build-${{ matrix.deno-version == 'canary' && 'canary' || 'release' }}-${{ matrix.unstable && 'unstable' || 'stable' }}-${{ matrix.no-check && 'nocheck' || 'tsc' }}
runs-on: ubuntu-latest
strategy:
matrix:
deno-version: [v1.x, nightly]
deno-version: [v1.x, canary]
unstable: [false, true]
no-check: [false, true]
steps:
- name: Setup Deno environment
uses: denolib/setup-deno@v2.3.0
- name: Setup Deno
uses: denoland/setup-deno@main
with:
deno-version: ${{ matrix.deno-version }}
deno-version: ${{ matrix.deno }}

- uses: actions/checkout@v2

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# deno_aws_sign_v4

![ci](https://github.com/lucacasonato/deno_aws_sign_v4/workflows/ci/badge.svg)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/aws_sign_v4@1.0.0/mod.ts)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/aws_sign_v4@1.0.1/mod.ts)

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

Expand All @@ -16,7 +16,7 @@ credentials in following ENV variables:
- AWS_REGION

```typescript
import { AWSSignerV4 } from "https://deno.land/x/aws_sign_v4@1.0.0/mod.ts";
import { AWSSignerV4 } from "https://deno.land/x/aws_sign_v4@1.0.1/mod.ts";

const signer = new AWSSignerV4();
const body = new TextEncoder().encode("Hello World!");
Expand Down
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { hmac } from "https://deno.land/x/hmac@v2.0.1/mod.ts";

import { createHash } from "https://deno.land/std@0.84.0/hash/mod.ts";
import { createHash } from "https://deno.land/std@0.95.0/hash/mod.ts";
export function sha256Hex(data: string | Uint8Array): string {
const hasher = createHash("sha256");
hasher.update(data);
Expand Down
12 changes: 2 additions & 10 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export class AWSSignerV4 implements Signer {
signedHeaders = signedHeaders.substring(0, signedHeaders.length - 1);
const body = request.body
? new Uint8Array(await request.arrayBuffer())
: new Uint8Array();
const payloadHash = sha256Hex(body);
: null;
const payloadHash = sha256Hex(body ?? new Uint8Array());

const { awsAccessKeyId, awsSecretKey } = this.credentials;

Expand Down Expand Up @@ -128,15 +128,7 @@ export class AWSSignerV4 implements Signer {
headers,
method: request.method,
body,
cache: request.cache,
credentials: request.credentials,
integrity: request.integrity,
keepalive: request.keepalive,
mode: request.mode,
redirect: request.redirect,
referrer: request.referrer,
referrerPolicy: request.referrerPolicy,
signal: request.signal,
});
}

Expand Down
14 changes: 9 additions & 5 deletions mod_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AWSSignerV4 } from "./mod.ts";
import {
assertEquals,
assertStringIncludes,
} from "https://deno.land/std@0.84.0/testing/asserts.ts";
} from "https://deno.land/std@0.95.0/testing/asserts.ts";

Deno.test("construct from env vars", async () => {
Deno.env.set("AWS_ACCESS_KEY_ID", "examplekey");
Expand All @@ -14,7 +14,7 @@ Deno.test("construct from env vars", async () => {
const req = await signer.sign(
"dynamodb",
new Request("https://test.dynamodb.us-east-1.amazonaws.com", {
method: "GET",
method: "POST",
headers: { "x-hello": "world" },
body: "A dynamodb request!",
}),
Expand All @@ -25,6 +25,8 @@ Deno.test("construct from env vars", async () => {
.toString()
.padStart(2, "0")
}${now.getDate().toString().padStart(2, "0")}`;
assertEquals(req.method, "POST");
assertEquals(await req.text(), "A dynamodb request!");
assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`);
assertEquals(req.headers.get("x-amz-security-token"), "sessiontoken");
assertEquals(req.headers.get("x-hello"), "world");
Expand All @@ -34,7 +36,7 @@ Deno.test("construct from env vars", async () => {
);
assertStringIncludes(
req.headers.get("Authorization")!,
`AWS4-HMAC-SHA256 Credential=examplekey/${today}/us-east-1/dynamodb/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-hello, Signature=`,
`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=`,
);
});

Expand All @@ -47,7 +49,7 @@ Deno.test("construct manually", async () => {
const req = await signer.sign(
"dynamodb",
new Request("https://test.dynamodb.us-east-1.amazonaws.com", {
method: "GET",
method: "POST",
headers: { "x-hello": "world" },
body: "A dynamodb request!",
}),
Expand All @@ -58,6 +60,8 @@ Deno.test("construct manually", async () => {
.toString()
.padStart(2, "0")
}${now.getDate().toString().padStart(2, "0")}`;
assertEquals(req.method, "POST");
assertEquals(await req.text(), "A dynamodb request!");
assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`);
assertEquals(req.headers.get("x-amz-security-token"), "session_token");
assertEquals(req.headers.get("x-hello"), "world");
Expand All @@ -67,7 +71,7 @@ Deno.test("construct manually", async () => {
);
assertStringIncludes(
req.headers.get("Authorization")!,
`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=`,
`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=`,
);
});

Expand Down

0 comments on commit 2d22db2

Please sign in to comment.