def getBucketEncryption()

in hq/app/aws/s3/S3.scala [33:57]


  def getBucketEncryption(client: S3Client, bucketName: String)(implicit ec: ExecutionContext): Attempt[BucketEncryptionResponse] = {
    val request = GetBucketEncryptionRequest.builder().bucket(bucketName).build()
    try {
      Attempt.Right {
        Option(
          client.getBucketEncryption(request).serverSideEncryptionConfiguration
        ).fold[BucketEncryptionResponse](NotEncrypted)(_ => Encrypted)
      }
    } catch {
      // If there is no bucket encryption, AWS returns an error...
      // Assume bucket is not encrypted if we receive the specific error
      case e: S3Exception if e.getMessage.contains("ServerSideEncryptionConfigurationNotFoundError") =>
        Attempt.Right(NotEncrypted)
      case e: S3Exception if e.getMessage.contains("NoSuchBucket") =>
        Attempt.Right(BucketNotFound)
      case NonFatal(e) =>
        Attempt.Left(FailedAttempt(Failure(
          s"unable to get S3 bucket encryption status for bucket $bucketName",
          "Encryption status for this bucket was not found.",
          500,
          context = Some(e.getMessage),
          throwable = Some(e)
        )))
    }
  }