Class SecretsReader

java.lang.Object
nva.commons.secrets.SecretsReader

public class SecretsReader extends Object
  • Field Details

  • Constructor Details

    • SecretsReader

      public SecretsReader()
    • SecretsReader

      public SecretsReader(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient awsSecretsManager)
  • Method Details

    • fetchSecret

      public String fetchSecret(String secretName, String secretKey)
      Fetches a secret String from AWS Secrets Manager.
      Parameters:
      secretName - the user-friendly id of the secret or the secret ARN
      secretKey - the key in the encrypted key-value map.
      Returns:
      the value for the specified key
      Throws:
      ErrorReadingSecretException - when any error occurs.
    • fetchPlainTextSecret

      public String fetchPlainTextSecret(String secretName)
      Fetches a plain-text secret from AWS Secrets Manager.
      Parameters:
      secretName - the user-friendly id of the secret or the secret ARN
      Returns:
      the plain text value for the specified secret name
      Throws:
      ErrorReadingSecretException - when any error occurs.
    • fetchClassSecret

      public <T> T fetchClassSecret(String secretName, Class<T> tclass)
      Fetches a json secret from AWS Secrets Manager as a class.
      Type Parameters:
      T - the type of the class or interface of the class to be returned
      Parameters:
      secretName - the user-friendly id of the secret or the secret ARN
      tclass - the class or interface of the class to be returned
      Returns:
      Class of the object we want to extract the secret to
      Throws:
      ErrorReadingSecretException - when any error occurs.
    • errorReadingSecretMessage

      public String errorReadingSecretMessage(String secretName)
    • defaultSecretsManagerClient

      public static software.amazon.awssdk.services.secretsmanager.SecretsManagerClient defaultSecretsManagerClient()