Skip to content

Commit

Permalink
Format code before release
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Nov 10, 2022
1 parent 8ec78c8 commit b9f6c83
Show file tree
Hide file tree
Showing 52 changed files with 3,104 additions and 2,614 deletions.
2 changes: 1 addition & 1 deletion otoroshi/app/models/descriptor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ object LoadBalancing {
case Some("BestResponseTime") => JsSuccess(BestResponseTime)
case Some("WeightedBestResponseTime") =>
JsSuccess(WeightedBestResponseTime((json \ "ratio").asOpt[Double].getOrElse(0.5)))
case _ => JsSuccess(RoundRobin)
case _ => JsSuccess(RoundRobin)
}
}
}
Expand Down
29 changes: 19 additions & 10 deletions otoroshi/app/next/controllers/entities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,25 @@ class EntitiesController(ApiAction: ApiAction, cc: ControllerComponents)(implici
ApiAction.async { ctx =>
entity match {
case "jwt-verifiers" =>
Ok(Json.obj(
"routes" -> env.proxyState
.allRoutes()
.filter(route => ctx.canUserRead(route))
.filter(route => Json.stringify(Json.arr(route.plugins.slots
.map(p => p.config.raw))).contains(id)
)
.map(_.json)
)).as("application/json").vfuture
case _ =>
Ok(
Json.obj(
"routes" -> env.proxyState
.allRoutes()
.filter(route => ctx.canUserRead(route))
.filter(route =>
Json
.stringify(
Json.arr(
route.plugins.slots
.map(p => p.config.raw)
)
)
.contains(id)
)
.map(_.json)
)
).as("application/json").vfuture
case _ =>
Ok(Json.obj()).as("application/json").vfuture
}
}
Expand Down
15 changes: 9 additions & 6 deletions otoroshi/app/next/models/route.scala
Original file line number Diff line number Diff line change
Expand Up @@ -958,11 +958,13 @@ object NgRoute {
.applyOn { seq =>
seq :+ NgPluginInstance(
plugin = pluginId[NgLegacyApikeyCall],
config = NgPluginInstanceConfig(NgLegacyApikeyCallConfig(
publicPatterns = service.publicPatterns,
privatePatterns = service.privatePatterns,
config = NgApikeyCallsConfig.fromLegacy(service.apiKeyConstraints)
).json.asObject)
config = NgPluginInstanceConfig(
NgLegacyApikeyCallConfig(
publicPatterns = service.publicPatterns,
privatePatterns = service.privatePatterns,
config = NgApikeyCallsConfig.fromLegacy(service.apiKeyConstraints)
).json.asObject
)
)
}
//.applyOnIf(
Expand Down Expand Up @@ -1022,7 +1024,8 @@ object NgRoute {
seq :+ NgPluginInstance(
plugin = pluginId[AuthModule],
include = if (service.publicPatterns.nonEmpty) {
if (service.publicPatterns.size == 1 && service.publicPatterns.contains("/.*")) Seq.empty else service.publicPatterns
if (service.publicPatterns.size == 1 && service.publicPatterns.contains("/.*")) Seq.empty
else service.publicPatterns
} else {
Seq.empty
},
Expand Down
46 changes: 32 additions & 14 deletions otoroshi/app/next/plugins/apikey.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

case class NgLegacyApikeyCallConfig(publicPatterns: Seq[String] = Seq.empty, privatePatterns: Seq[String] = Seq.empty, config: NgApikeyCallsConfig) extends NgPluginConfig {
case class NgLegacyApikeyCallConfig(
publicPatterns: Seq[String] = Seq.empty,
privatePatterns: Seq[String] = Seq.empty,
config: NgApikeyCallsConfig
) extends NgPluginConfig {
override def json: JsValue = NgLegacyApikeyCallConfig.format.writes(this)
}
object NgLegacyApikeyCallConfig {
val default = NgLegacyApikeyCallConfig(Seq.empty, Seq.empty, NgApikeyCallsConfig())
val format = new Format[NgLegacyApikeyCallConfig] {
override def writes(o: NgLegacyApikeyCallConfig): JsValue = Json.obj(
"public_patterns" -> o.publicPatterns,
"private_patterns" -> o.privatePatterns,
val format = new Format[NgLegacyApikeyCallConfig] {
override def writes(o: NgLegacyApikeyCallConfig): JsValue = Json.obj(
"public_patterns" -> o.publicPatterns,
"private_patterns" -> o.privatePatterns
) ++ o.config.json.asObject
override def reads(json: JsValue): JsResult[NgLegacyApikeyCallConfig] = Try {
NgLegacyApikeyCallConfig(
Expand All @@ -31,7 +35,7 @@ object NgLegacyApikeyCallConfig {
config = NgApikeyCallsConfig.format.reads(json).asOpt.getOrElse(NgApikeyCallsConfig())
)
} match {
case Failure(e) => JsError(e.getMessage)
case Failure(e) => JsError(e.getMessage)
case Success(value) => JsSuccess(value)
}
}
Expand Down Expand Up @@ -60,24 +64,38 @@ class NgLegacyApikeyCall extends NgAccessValidator with NgRequestTransformer wit
override def isTransformResponseAsync: Boolean = false
override def isAccessAsync: Boolean = true
override def name: String = "Legacy apikeys"
override def description: Option[String] = "This plugin expects to find an apikey to allow the request to pass. This plugin behaves exactly like the service descriptor does".some
override def description: Option[String] =
"This plugin expects to find an apikey to allow the request to pass. This plugin behaves exactly like the service descriptor does".some
override def defaultConfigObject: Option[NgPluginConfig] = NgLegacyApikeyCallConfig.default.some

override def matches(ctx: NgRouteMatcherContext)(implicit env: Env): Boolean = {
val plugin = env.scriptManager.getAnyScript[NgRouteMatcher](NgPluginHelper.pluginId[ApikeyCalls])(env.otoroshiExecutionContext).right.get
val plugin = env.scriptManager
.getAnyScript[NgRouteMatcher](NgPluginHelper.pluginId[ApikeyCalls])(env.otoroshiExecutionContext)
.right
.get
plugin.matches(ctx)(env)
}
override def transformRequestSync(
ctx: NgTransformerRequestContext
ctx: NgTransformerRequestContext
)(implicit env: Env, ec: ExecutionContext, mat: Materializer): Either[Result, NgPluginHttpRequest] = {
val plugin = env.scriptManager.getAnyScript[NgRequestTransformer](NgPluginHelper.pluginId[ApikeyCalls])(env.otoroshiExecutionContext).right.get
val plugin = env.scriptManager
.getAnyScript[NgRequestTransformer](NgPluginHelper.pluginId[ApikeyCalls])(env.otoroshiExecutionContext)
.right
.get
plugin.transformRequestSync(ctx)(env, ec, mat)
}
override def access(ctx: NgAccessContext)(implicit env: Env, ec: ExecutionContext): Future[NgAccess] = {
val plugin = env.scriptManager.getAnyScript[NgAccessValidator](NgPluginHelper.pluginId[ApikeyCalls])(env.otoroshiExecutionContext).right.get
val config = configCache.get(ctx.route.cacheableId, _ => configReads.reads(ctx.config).getOrElse(NgLegacyApikeyCallConfig.default))
val descriptor = ctx.route.legacy.copy(publicPatterns = config.publicPatterns, privatePatterns = config.privatePatterns)
val req = ctx.request
val plugin = env.scriptManager
.getAnyScript[NgAccessValidator](NgPluginHelper.pluginId[ApikeyCalls])(env.otoroshiExecutionContext)
.right
.get
val config = configCache.get(
ctx.route.cacheableId,
_ => configReads.reads(ctx.config).getOrElse(NgLegacyApikeyCallConfig.default)
)
val descriptor =
ctx.route.legacy.copy(publicPatterns = config.publicPatterns, privatePatterns = config.privatePatterns)
val req = ctx.request
if (descriptor.isUriPublic(req.path)) {
if (
env.detectApiKeySooner && descriptor.detectApiKeySooner && ApiKeyHelper
Expand Down
Loading

0 comments on commit b9f6c83

Please sign in to comment.