Skip to content

Commit 7269cea

Browse files
committed
feat: add aws secrets manager plugin
1 parent 22d0f46 commit 7269cea

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@lcdev/eslint-config/cwd')(__dirname);

app-config-aws-secrets-manager/README.md

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@app-config/aws-secrets-manager",
3+
"description": "AWS Secrets Manager support for App Config",
4+
"version": "2.9.0-beta.1",
5+
"license": "MPL-2.0",
6+
"author": {
7+
"name": "Launchcode",
8+
"email": "admin@lc.dev",
9+
"url": "https://lc.dev"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/launchcodedev/app-config.git"
14+
},
15+
"main": "dist/index.js",
16+
"module": "dist/es/index.js",
17+
"types": "dist/index.d.ts",
18+
"files": [
19+
"/dist",
20+
"!**/*.tsbuildinfo",
21+
"!**/*.test.*"
22+
],
23+
"scripts": {
24+
"build": "tsc -b",
25+
"build:es": "tsc -b tsconfig.es.json",
26+
"clean": "rm -rf dist *.tsbuildinfo",
27+
"lint": "eslint src",
28+
"fix": "eslint --fix src",
29+
"test": "jest",
30+
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
31+
},
32+
"dependencies": {
33+
"@app-config/extension-utils": "^2.9.0-beta.1",
34+
"@aws-sdk/client-secrets-manager": "3.810.0"
35+
},
36+
"peerDependencies": {
37+
"@app-config/main": "^2.9.0-beta.1"
38+
},
39+
"devDependencies": {
40+
"@app-config/main": "^2.9.0-beta.1"
41+
},
42+
"prettier": "@lcdev/prettier",
43+
"jest": {
44+
"preset": "@lcdev/jest"
45+
}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { ParsingExtension, Json } from '@app-config/main';
2+
import { named, forKey, validateOptions } from '@app-config/extension-utils';
3+
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
4+
5+
function awsSecretsManagerParsingExtension(): ParsingExtension {
6+
return named(
7+
'$awsSecretsManager',
8+
forKey(
9+
'$awsSecretsManager',
10+
validateOptions(
11+
(SchemaBuilder) =>
12+
SchemaBuilder.emptySchema().addString('secretId').addString('select', {}, false),
13+
({ secretId, select }) =>
14+
async (parse) => {
15+
const client = new SecretsManager();
16+
const secret = await client.getSecretValue({ SecretId: secretId });
17+
18+
if (!secret.SecretString) {
19+
throw new Error(`Secret ID ${secretId} not found in AWS Secrets Manager`);
20+
}
21+
22+
let value = secret.SecretString as Json;
23+
24+
if (select) {
25+
const json = JSON.parse(secret.SecretString) as Record<string, Json>;
26+
value = json[select];
27+
28+
if (!value) {
29+
throw new Error(
30+
`Could not select ${select} JSON key from Secret ID ${secretId} in AWS Secrets Manager`,
31+
);
32+
}
33+
}
34+
35+
return parse(value, { shouldFlatten: true });
36+
},
37+
),
38+
),
39+
);
40+
}
41+
42+
export default awsSecretsManagerParsingExtension;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"target": "es2019",
5+
"module": "es2020",
6+
"outDir": "./dist/es"
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "@lcdev/tsconfig",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./dist"
6+
},
7+
"include": ["src"],
8+
"exclude": ["node_modules"],
9+
"references": [
10+
{ "path": "../app-config-test-utils" }
11+
]
12+
}

0 commit comments

Comments
 (0)