< Summary - Envilder Node.js SDK

Information
Class: src/sdks/nodejs/src/infrastructure/aws/aws-ssm-secret-provider.ts
Assembly: Default
File(s): src/sdks/nodejs/src/infrastructure/aws/aws-ssm-secret-provider.ts
Tag: 299_25910610327
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 55
Line coverage: 100%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/sdks/nodejs/src/infrastructure/aws/aws-ssm-secret-provider.ts

#LineLine coverage
 1import { GetParametersCommand, type SSMClient } from '@aws-sdk/client-ssm';
 2import type { ISecretProvider } from '../../domain/ports/secret-provider.js';
 3
 24const SSM_BATCH_SIZE = 10;
 5
 6/**
 7 * {@link ISecretProvider} backed by AWS SSM Parameter Store.
 8 *
 9 * Parameters are retrieved with decryption enabled so that
 10 * SecureString values are returned in plain text.
 11 *
 12 * SSM supports fetching up to 10 parameters per request,
 13 * so names are chunked into batches automatically.
 14 */
 15export class AwsSsmSecretProvider implements ISecretProvider {
 16  private readonly ssmClient: SSMClient;
 17
 18  constructor(ssmClient: SSMClient) {
 1019    if (!ssmClient) {
 120      throw new Error('ssmClient cannot be null');
 21    }
 922    this.ssmClient = ssmClient;
 23  }
 24
 25  async getSecrets(names: string[]): Promise<Map<string, string>> {
 1026    const result = new Map<string, string>();
 1027    if (names.length === 0) {
 128      return result;
 29    }
 30
 931    for (const name of names) {
 2332      if (!name?.trim()) {
 133        throw new Error('Secret name cannot be null or whitespace');
 34      }
 35    }
 36
 837    for (let i = 0; i < names.length; i += SSM_BATCH_SIZE) {
 938      const batch = names.slice(i, i + SSM_BATCH_SIZE);
 939      const response = await this.ssmClient.send(
 40        new GetParametersCommand({
 41          Names: batch,
 42          WithDecryption: true,
 43        }),
 44      );
 45
 746      for (const param of response.Parameters ?? []) {
 547        if (param.Name && param.Value != null) {
 548          result.set(param.Name, param.Value);
 49        }
 50      }
 51    }
 52
 653    return result;
 54  }
 55}

Methods/Properties

(anonymous_0)
(anonymous_1)