All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gu.pandahmac.HmacSecrets.scala Maven / Gradle / Ivy

The newest version!
package com.gu.pandahmac

import com.gu.hmac.ValidateHMACHeader

import java.net.URI

trait HMACSecrets extends ValidateHMACHeader {
  @deprecated("In an upcoming release consumers will expected to provide a list of secrets to `secretKeys` to allow for secret rotation.")
  def secret: String = ""
  def secretKeys: List[String] = List.empty

  protected def gatherSecrets: List[String] =
    if(!secretKeys.isEmpty) secretKeys
    else if(!secret.isEmpty) List(secret)
    else throw new Exception(
      "Please set either 'secret' or 'secretKeys', no secret available for HMACAuthActions!"
    )
  
  def validateHMACHeaders(date: String, hmac: String, uri: URI): Boolean =
    gatherSecrets.exists(validateHMACHeadersWithSecret(_, date, hmac, uri))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy