Skip to content

Commit

Permalink
Merge pull request #4 from guardian/fix-broken-stuff
Browse files Browse the repository at this point in the history
Fix the THREE bugs I managed to introduce with #3
  • Loading branch information
rtyley authored Jun 22, 2018
2 parents 203b506 + c2af545 commit 9a1397e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/com/gu/play/secretrotation/Phase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ trait Phase[T] {

val alsoAccepted: Traversable[T]

final val onlyAcceptsActive = alsoAccepted.isEmpty
final def onlyAcceptsActive = alsoAccepted.isEmpty

final val accepted: Stream[T] = Stream(active) ++ alsoAccepted
final def accepted: Stream[T] = Stream(active) ++ alsoAccepted

def map[S](f: T => S): Phase[S] = {
val activeS = f(active)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ trait RotatingSecretComponents extends BuiltInComponentsFromContext {

val secretStateSupplier: SnapshotProvider

override def configuration: Configuration = super.configuration ++
Configuration("play.http.secret.key" -> secretStateSupplier.snapshot().secrets.active)
override def configuration: Configuration = {
val nonRotatingSecretOnlyUsedToSatisfyConfigChecks: String = secretStateSupplier.snapshot().secrets.active.secret

super.configuration ++ Configuration("play.http.secret.key" -> nonRotatingSecretOnlyUsedToSatisfyConfigChecks)
}

override lazy val requestFactory: RequestFactory =
RotatingSecretComponents.requestFactoryFor(secretStateSupplier, httpConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ trait SnapshotProvider {
trait CachingSnapshotProvider extends SnapshotProvider {
val transitionTiming: TransitionTiming

private val anyKey = new Object // would love to use Unit or something, it just wouldn't compile

// make sure we don't cache the secret state too long, we need to be ready to use a new secret when issued
private val cache = CacheBuilder.newBuilder
.expireAfterWrite(transitionTiming.usageDelay.dividedBy(2).getSeconds, SECONDS)
.build(new CacheLoader[Null, SnapshotProvider] { def load(key: Null): SnapshotProvider = loadState() })
.build(new CacheLoader[Object, SnapshotProvider] { def load(key: Object): SnapshotProvider = loadState() })

override def snapshot(): SecretsSnapshot = cache.get(null).snapshot()
override def snapshot(): SecretsSnapshot = cache.get(anyKey).snapshot()

def loadState(): SnapshotProvider
}
Expand Down

0 comments on commit 9a1397e

Please sign in to comment.