This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
-
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.
- Loading branch information
1 parent
a5d751c
commit 2f4c09c
Showing
10 changed files
with
2,068 additions
and
36 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,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
LOCALSTACK_HOST=localhost | ||
AWS_REGION=us-east-1 | ||
|
||
echo "Configuring KMS" | ||
echo "===========================" | ||
echo "######### Creating kms key and alias ###########" | ||
kmsKey=$(awslocal kms create-key --description "local kms key" --key-usage ENCRYPT_DECRYPT) | ||
keyId=$(echo ${kmsKey} | python3 -c "import sys, json; print(json.load(sys.stdin)['KeyMetadata']['KeyId'])") | ||
|
||
echo "Configuring Secrets Manager" | ||
echo "===========================" | ||
|
||
# aws local is a dependency | ||
echo "######### Creating secrets ###########" | ||
awslocal secretsmanager create-secret \ | ||
--name local-api \ | ||
--description "Default secrets" \ | ||
--secret-string "{\"DEFAULT_SECRET\":\"I love dogs\", \"API_KMS_KEY_ID\": \"${keyId}\"}" |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,29 @@ | ||
import { | ||
SecretsManagerClient, | ||
SecretsManagerClientConfig, | ||
GetSecretValueCommand, | ||
GetSecretValueRequest | ||
} from '@aws-sdk/client-secrets-manager'; | ||
|
||
export class SecretsManager { | ||
private static NON_PROD_ENVS = ['local', 'test']; | ||
|
||
private client: SecretsManagerClient; | ||
|
||
constructor() { | ||
const config: SecretsManagerClientConfig = {}; | ||
|
||
if (SecretsManager.NON_PROD_ENVS.includes(process.env.DEMO_ENVIRONMENT)) { | ||
config.endpoint = 'http://localstack:4566'; | ||
} | ||
|
||
this.client = new SecretsManagerClient(config); | ||
} | ||
|
||
async getSecret(secretId: string) { | ||
const input: GetSecretValueRequest = { SecretId: secretId }; | ||
const command = new GetSecretValueCommand(input); | ||
const { SecretString } = await this.client.send(command); | ||
return JSON.parse(SecretString); | ||
} | ||
} |
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
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