Created
October 19, 2015 22:10
-
-
Save trane/15481680a611f87fbecf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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