protected async readLoginCredentials()

in packages/aws-rfdk/lib/lambdas/nodejs/mongodb/handler.ts [155:173]


  protected async readLoginCredentials(credentialsArn: string): Promise<{ [key: string]: string}> {
    const data = await Secret.fromArn(credentialsArn, this.secretsManagerClient).getValue();
    if (Buffer.isBuffer(data) || !data) {
      throw new Error(`Login credentials, in Secret ${credentialsArn}, for MongoDB must be a JSON encoded string`);
    }
    let credentials: { [key: string]: string };
    try {
      credentials = JSON.parse(data);
    } catch (e) {
      // Note: Intentionally not including the data as part of this error message. It may contain secrets, and including it will leak those secrets.
      throw new Error(`Failed to parse JSON in MongoDB login credentials Secret (${credentialsArn}). Please ensure that the Secret contains properly formatted JSON.`);
    }
    for (const key of ['username', 'password']) {
      if (!(key in credentials)) {
        throw new Error(`Login credentials Secret (${credentialsArn}) is missing: ${key}`);
      }
    }
    return credentials;
  }