-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move aws helpers to separate package
- Loading branch information
1 parent
5967f29
commit 668ef46
Showing
9 changed files
with
654 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@casimir/aws", | ||
"private": true, | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"build": "echo '@casimir/aws build not specified. Disregard this warning and any listed errors above if @casimir/aws is not needed for the current project build.' && exit 0", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-secrets-manager": "^3.204.0", | ||
"@aws-sdk/credential-providers": "^3.204.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.38" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { exec, execSync } from 'child_process' | ||
import { fromIni } from '@aws-sdk/credential-providers' | ||
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager' | ||
|
||
/** | ||
* Gets a secret from AWS Secrets Manager. | ||
* @param id secret id | ||
* @returns secret string | ||
*/ | ||
export async function getSecret(id: string) { | ||
const aws = new SecretsManagerClient({}) | ||
const { SecretString } = await aws.send( | ||
new GetSecretValueCommand( | ||
{ | ||
SecretId: id | ||
} | ||
) | ||
) | ||
return SecretString | ||
} | ||
|
||
/** | ||
* Ensures AWS credentials are available and returns them. | ||
* Checks for AWS credentials in the environment variables. | ||
* If not found, loads credentials from `AWS_PROFILE` or the default profile. | ||
* @returns AWS credentials | ||
*/ | ||
export async function loadCredentials() { | ||
const defaultProfile = 'consensus-networks-dev' | ||
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) { | ||
process.env.AWS_PROFILE = process.env.AWS_PROFILE || defaultProfile | ||
return await fromIni()() | ||
} | ||
return { | ||
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"strict": true, | ||
"preserveConstEnums": true, | ||
"noEmit": true, | ||
"sourceMap": false, | ||
"module": "CommonJS", | ||
"moduleResolution": "Node", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"include": [ | ||
"./src/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.