-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pass AWS clients into handlers
- Loading branch information
1 parent
02fea3e
commit 1aa3dc8
Showing
4 changed files
with
57 additions
and
41 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
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,27 @@ | ||
import type { AuthSettings } from './model/AuthSettings' | ||
import { SecretsManagerClient, GetSecretValueCommand, GetSecretValueResponse } from '@aws-sdk/client-secrets-manager' | ||
|
||
export async function getAuthSettings(secretManagerClient: SecretsManagerClient): Promise<AuthSettings> { | ||
const secretName = process.env.SettingsSecretName | ||
if (!secretName) { | ||
throw new Error('Unable to retrieve secret. Error: unable to get secret name') | ||
} | ||
|
||
try { | ||
const command = new GetSecretValueCommand({ | ||
SecretId: secretName, | ||
}) | ||
|
||
const response: GetSecretValueResponse = await secretManagerClient.send(command) | ||
|
||
if (response.SecretBinary) { | ||
return JSON.parse(Buffer.from(response.SecretBinary).toString('utf8')) | ||
} else if (response.SecretString) { | ||
return JSON.parse(response.SecretString) | ||
} else { | ||
throw new Error('secret is empty') | ||
} | ||
} catch (error: any) { | ||
throw new Error(`Unable to retrieve secret. ${error}`) | ||
} | ||
} |
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