Skip to content

Instantly share code, notes, and snippets.

@trane
Created October 19, 2015 22:10
Show Gist options
  • Select an option

  • Save trane/15481680a611f87fbecf to your computer and use it in GitHub Desktop.

Select an option

Save trane/15481680a611f87fbecf to your computer and use it in GitHub Desktop.
def secrets: Secrets ={
val s = cacheBuffer.last
if (s.current.expired) rotateSecrets.last
else s
}
/**
*Checks if the secret is knows. Rotates if the secret is the new secret.
**/
def find(f: Secret=>Boolean): Option[Secret] = {
val lastSecrets = cacheBuffer.last
if( f(lastSecrets.current)) Some(lastSecrets.current)
else if ( f(lastSecrets.previous)) Some(lastSecrets.previous)
else if ( f(rotateSecrets.current) Some(cacheBuffer.last.current)
else None
}
private def rotateSecrets: Secrets = {
if (cacheBuffer.last.current != newBuffer.last.current)
// take out a lock
mutex.lock {
if (cacheBuffer.last.current != newBuffer.last.current) {
val s = cacheBuffer.last.current
val n = newBuffer.last
val newSecrets = Secrets(n,s)
cacheBuffer.append(newSecrets)
}
}
cacheBuffer.last
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment