Skip to content

Commit

Permalink
Add utils/aws for fetching the keyset from S3
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanoogian committed Jul 13, 2022
1 parent 8f5a2fa commit c3cda7d
Show file tree
Hide file tree
Showing 7 changed files with 5,413 additions and 2,295 deletions.
7,652 changes: 5,359 additions & 2,293 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"workspaces": [
"agent-core",
"rotators/*",
"apps/*"
"apps/*",
"utils/*"
],
"engines": {
"node": "16.x"
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"files": [],
"references": [{ "path": "agent-core" }, { "path": "rotators/postgres" }, { "path": "apps/http-postgres-rotator" }]
"references": [
{ "path": "agent-core" },
{ "path": "rotators/postgres" },
{ "path": "apps/http-postgres-rotator" },
{ "path": "utils/aws" }
]
}
1 change: 1 addition & 0 deletions utils/aws/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
18 changes: 18 additions & 0 deletions utils/aws/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Readable } from "stream";
import { S3 } from "@aws-sdk/client-s3";

async function streamToBuffer(stream: Readable) {
return new Promise<Buffer>((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on("data", (chunk) => chunks.push(chunk));
stream.once("end", () => resolve(Buffer.concat(chunks)));
stream.once("error", reject);
});
}

export async function fetchS3KeySet(bucket = "doppler-keys") {
const s3Client = new S3({ forcePathStyle: true });
const keyFile = await s3Client.getObject({ Bucket: bucket, Key: "secret-agents-jwks.json" });
const bodyBuffer = await streamToBuffer(keyFile.Body as Readable);
return JSON.parse(new TextDecoder().decode(bodyBuffer)) as Record<string, unknown>;
}
20 changes: 20 additions & 0 deletions utils/aws/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "aws-utils",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"engines": {
"node": "16.x"
},
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/client-s3": "^3.128.0"
}
}
7 changes: 7 additions & 0 deletions utils/aws/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "lib",
"outDir": "dist"
}
}

0 comments on commit c3cda7d

Please sign in to comment.