private[logic] def identifyMostRecentActivity()

in hq/app/logic/IamOutdatedCredentials.scala [95:115]


  private[logic] def identifyMostRecentActivity(remediationHistory: IamUserRemediationHistory, vulnerableKey: AccessKey): Option[IamRemediationActivity] = {
    //TODO lastRotatedDate should not be an Option, because every IAM access key has a last rotated date. Change SHQ's model.
    vulnerableKey.lastRotated match {
      case Some(lastRotatedDate) =>
        // filter activity list to find matching db records for given access key
        val keyPreviousActivities = remediationHistory.activityHistory.filter(_.problemCreationDate.isEqual(lastRotatedDate))
        keyPreviousActivities match {
          case Nil =>
            // there is no recent activity for the given access key, so return None.
            None
          case remediationActivities =>
            // get the most recent remediation activity
            Some(remediationActivities.maxBy(_.dateNotificationSent.getMillis))
        }
      case None =>
        val name = remediationHistory.iamUser.username
        val account = remediationHistory.awsAccount.name
        logger.warn(s"$name in $account has an access key without a lastRotatedDate. Please investigate.")
        None
    }
  }