UNPKG

@updating-secrets/aws-secrets-manager-adapter

Version:

AWS Secrets Manager adapter for the updating-secrets package.

40 lines (39 loc) 1.33 kB
import { assert } from '@augment-vir/assert'; import { GetSecretValueCommand, } from '@aws-sdk/client-secrets-manager'; /** * A mock implementation of `SecretsManagerClient` from the * [`@aws-sdk/client-secrets-manager`](https://www.npmjs.com/package/@aws-sdk/client-secrets-manager) * package. * * This only mocks the following: * * - The `.send()` method * - Sending a `GetSecretValueCommand` command * - Returning a `.SecretString` value from that command * * @category Mocks */ export class MockAwsSecretsManagerClient { mockSecrets; constructor(mockSecrets) { this.mockSecrets = mockSecrets; } /** * A mock implementation of `SecretsManagerClient.send()`. Only the first parameter (the * command) is used. */ send(command) { if (!(command instanceof GetSecretValueCommand)) { throw new TypeError(`AWS Secrets Manager command not mocked: '${command.constructor.name}'`); } assert.isDefined(command.input.SecretId, 'No SecretId given.'); const value = this.mockSecrets[command.input.SecretId]; return Promise.resolve({ SecretString: value ? value.preJson ? JSON.stringify(value.preJson) : value.rawString : undefined, }); } }