protected async readPasswordAuthUserInfo()

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


  protected async readPasswordAuthUserInfo(userArn: string): Promise<{[key: string]: string}> {
    const data = await Secret.fromArn(userArn, this.secretsManagerClient).getValue();
    if (Buffer.isBuffer(data) || !data) {
      throw new Error(`Password-auth user credentials, in Secret ${userArn}, for MongoDB must be a JSON encoded string`);
    }
    let userCreds: { [key: string]: string };
    try {
      userCreds = 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 for password-auth user Secret (${userArn}). Please ensure that the Secret contains properly formatted JSON.`);
    }
    for (const key of ['username', 'password', 'roles']) {
      if (!(key in userCreds)) {
        // 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(`User credentials Secret '${userArn}' is missing: ${key}`);
      }
    }
    return userCreds;
  }