Skip to content

Commit

Permalink
Instantiate SSMClient in the AWSParameterStoreSecretsVault constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaab committed Aug 6, 2024
1 parent 947b2db commit 446c62f
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions infra/core/src/lib/adapters/aws-param-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ import {
import type { SecretKey, SecretMap, SecretValue, SecretsVault } from '../types';

export class AWSParameterStoreSecretsVault implements SecretsVault {
client: SSMClient;

constructor() {
this.client = new SSMClient();
}

async deleteSecret(key: SecretKey) {
const client = new SSMClient();
try {
await client.send(
await this.client.send(
new DeleteParameterCommand({
Name: key,
})
Expand All @@ -27,10 +32,8 @@ export class AWSParameterStoreSecretsVault implements SecretsVault {
}

async getSecret(key: SecretKey) {
const client = new SSMClient();

try {
const response = await client.send(
const response = await this.client.send(
new GetParameterCommand({
Name: key,
WithDecryption: true,
Expand All @@ -47,9 +50,8 @@ export class AWSParameterStoreSecretsVault implements SecretsVault {
}

async getSecrets(keys: SecretKey[]) {
const client = new SSMClient();
try {
const response = await client.send(
const response = await this.client.send(
new GetParametersCommand({
Names: keys,
WithDecryption: true,
Expand All @@ -71,9 +73,8 @@ export class AWSParameterStoreSecretsVault implements SecretsVault {
}

async setSecret(key: SecretKey, value: SecretValue) {
const client = new SSMClient();
try {
await client.send(
await this.client.send(
new PutParameterCommand({
Name: key,
Value: value,
Expand All @@ -96,18 +97,17 @@ export class AWSParameterStoreSecretsVault implements SecretsVault {
}

async getSecretKeys() {
const client = new SSMClient();

let keys: string[] = [];
let nextToken: string | undefined;
do {
try {
const response: DescribeParametersCommandOutput = await client.send(
new DescribeParametersCommand({
NextToken: nextToken,
MaxResults: 50,
})
);
const response: DescribeParametersCommandOutput =
await this.client.send(
new DescribeParametersCommand({
NextToken: nextToken,
MaxResults: 50,
})
);
if (response.Parameters) {
keys.push(...response.Parameters.map(param => param.Name!));
}
Expand Down

0 comments on commit 446c62f

Please sign in to comment.