def lookupCredentialId()

in hq/app/logic/IamOutdatedCredentials.scala [169:190]


  def lookupCredentialId(badKeyCreationDate: DateTime, userCredentials: List[CredentialMetadata]): Attempt[CredentialMetadata] = {
    val username = userCredentials.map(_.username).headOption.getOrElse("unknown username")
    userCredentials.filter { credentialMetadata =>
      credentialMetadata.creationDate.withMillisOfSecond(0) == badKeyCreationDate.withMillisOfSecond(0)
    } match {
      case singleMatchingKey :: Nil => Attempt.Right(singleMatchingKey)
      case Nil =>
        Attempt.Left(FailedAttempt(Failure(
          "unable to identify matching access key in user's metadata",
          s"I've made a list-access-keys AWS API call for $username, but I have not found a matching key in the response.",
          500
        )))
      case _ =>
        // This is an edge case where both the user's access keys both have the same creation date.
        // This should be unlikely given the Credentials Reports creation dates are defined up to the second.
        Attempt.Left(FailedAttempt(Failure(
          s"both of $username's access keys have the exact same creation date - cannot decide which one to select for disablement",
          s"I've hit an edge case for $username's access keys where both have the same creation date, please investigate as I can't decide which one to disable.",
          500
        )))
    }
  }