Skip to content

Commit

Permalink
make private keys return a future
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Jan 23, 2025
1 parent 6a7e8b3 commit 32fd389
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions otoroshi/app/gateway/handlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,12 @@ class GatewayRequestHandler(

def jwks() =
actionBuilder.async { req =>
val extensionsPublicKeys = env.adminExtensions.publicKeys()
JWKSHelper.jwks(req, Seq.empty).map {
case Left(body) if extensionsPublicKeys.isEmpty => Results.NotFound(body)
case Left(_) if extensionsPublicKeys.isEmpty => Results.Ok(Json.obj("keys" -> JsArray(extensionsPublicKeys.map(_.raw))))
case Right(keys) => Results.Ok(JsArray(keys ++ extensionsPublicKeys.map(_.raw)))
env.adminExtensions.publicKeys().flatMap { extensionsPublicKeys =>
JWKSHelper.jwks(req, Seq.empty).map {
case Left(body) if extensionsPublicKeys.isEmpty => Results.NotFound(body)
case Left(_) if extensionsPublicKeys.isEmpty => Results.Ok(Json.obj("keys" -> JsArray(extensionsPublicKeys.map(_.raw))))
case Right(keys) => Results.Ok(JsArray(keys ++ extensionsPublicKeys.map(_.raw)))
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions otoroshi/app/next/extensions/example.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ class FooAdminExtension(val env: Env) extends AdminExtension {
}
}

override def publicKeys(): Seq[PublicKeyJwk] = {
override def publicKeys(): Future[Seq[PublicKeyJwk]] = {
val jwk = new OctetKeyPairGenerator(Curve.Ed25519).keyID("fake-key").generate
val publicJWK = jwk.toPublicJWK.toJSONString.parseJson
Seq(PublicKeyJwk(publicJWK))
Seq(PublicKeyJwk(publicJWK)).vfuture
// Seq(PublicKeyJwk(Json.obj(
// "kty" -> "OKP",
// "crv" -> "Ed25519",
Expand Down
6 changes: 3 additions & 3 deletions otoroshi/app/next/extensions/extension.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ trait AdminExtension {
def wellKnownRoutes(): Seq[AdminExtensionWellKnownRoute] = Seq.empty
def wellKnownOverridesRoutes(): Seq[AdminExtensionWellKnownRoute] = Seq.empty
def vaults(): Seq[AdminExtensionVault] = Seq.empty
def publicKeys(): Future[Seq[PublicKeyJwk]] = Future.successful(Seq.empty)
def publicKeys(): Future[Seq[PublicKeyJwk]] = Seq.empty.vfuture
def configuration: Configuration = env.configuration
.getOptional[Configuration](s"otoroshi.admin-extensions.configurations.${id.cleanup}")
.getOrElse(Configuration.empty)
Expand Down Expand Up @@ -538,11 +538,11 @@ class AdminExtensions(env: Env, _extensions: Seq[AdminExtension]) {

def publicKeys(): Future[Seq[PublicKeyJwk]] = {
if (hasExtensions) {
extensions.mapAsync { ext =>
extensions.flatmapAsync { ext =>
ext.publicKeys()
}
} else {
Seq.empty
Seq.empty.vfuture
}
}

Expand Down

0 comments on commit 32fd389

Please sign in to comment.