private def loadFromSecretsManagerImp()

in app/com/gu/itunes/SecretKeeper.scala [30:50]


  private def loadFromSecretsManagerImp(lookupKey: String): Try[String] = {
    for {
      identity <- getIdentity()
      result <- identity match {
        case AwsIdentity(app, stack, stage, region) =>
          //we'll just use a basic, blocking client here as it's only used in startup
          val client = SecretsManagerClient.builder().credentialsProvider(credentialsProviderChain).region(Region.of(region)).build()

          val ssmKey = s"/$stage/$stack/$app/$lookupKey"
          logger.info(s"Loading $lookupKey key from secrets manager at $ssmKey")
          Try { client.getSecretValue(GetSecretValueRequest.builder().secretId(ssmKey).build()) }
        case _ =>
          if (lookupKey == "capiKey") {
            logger.warn("When running locally you should set the API_KEY environment variable or apiKey in application.conf")
          } else {
            logger.warn(s"When running locally you should set $lookupKey in application.conf")
          }
          Failure(new RuntimeException("Not running in AWS"))
      }
    } yield result.secretString()
  }