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 14, 2022
1 parent b752f45 commit fdf56ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion otoroshi/app/next/models/route.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ object NgRoute {
}
}
)
)/*.debug { route =>
) /*.debug { route =>
if (route.id == "service_dev_4357b93e-f952-4de8-9d30-4c69650b22c4") {
route.json.prettify.debugPrintln
}
Expand Down
31 changes: 18 additions & 13 deletions otoroshi/app/next/plugins/auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

case class NgLegacyAuthModuleCallConfig(
publicPatterns: Seq[String] = Seq.empty,
privatePatterns: Seq[String] = Seq.empty,
config: NgAuthModuleConfig
) extends NgPluginConfig {
publicPatterns: Seq[String] = Seq.empty,
privatePatterns: Seq[String] = Seq.empty,
config: NgAuthModuleConfig
) extends NgPluginConfig {
override def json: JsValue = NgLegacyAuthModuleCallConfig.format.writes(this)
}
object NgLegacyAuthModuleCallConfig {
Expand Down Expand Up @@ -50,34 +50,39 @@ class NgLegacyAuthModuleCall extends NgAccessValidator {
override def multiInstance: Boolean = true
override def core: Boolean = true
override def name: String = "Legacy Authentication"
override def description: Option[String] = "This plugin applies an authentication module the same way service descriptor does".some
override def description: Option[String] =
"This plugin applies an authentication module the same way service descriptor does".some
override def defaultConfigObject: Option[NgPluginConfig] = NgLegacyAuthModuleCallConfig.default.some

override def isAccessAsync: Boolean = true

override def access(ctx: NgAccessContext)(implicit env: Env, ec: ExecutionContext): Future[NgAccess] = {
val authPlugin = env.scriptManager
val authPlugin = env.scriptManager
.getAnyScript[NgAccessValidator](NgPluginHelper.pluginId[AuthModule])(env.otoroshiExecutionContext)
.right
.get
val apikeyPlugin = env.scriptManager
.getAnyScript[NgAccessValidator](NgPluginHelper.pluginId[NgLegacyApikeyCall])(env.otoroshiExecutionContext)
.right
.get
val config = ctx.cachedConfig(internalName)(configReads).getOrElse(NgLegacyAuthModuleCallConfig.default)
val apikeyConfig = NgLegacyApikeyCallConfig(config.publicPatterns, config.privatePatterns, NgApikeyCallsConfig.fromLegacy(ctx.route.legacy.apiKeyConstraints))
val descriptor =
val config = ctx.cachedConfig(internalName)(configReads).getOrElse(NgLegacyAuthModuleCallConfig.default)
val apikeyConfig = NgLegacyApikeyCallConfig(
config.publicPatterns,
config.privatePatterns,
NgApikeyCallsConfig.fromLegacy(ctx.route.legacy.apiKeyConstraints)
)
val descriptor =
ctx.route.legacy.copy(publicPatterns = config.publicPatterns, privatePatterns = config.privatePatterns)
val req = ctx.request
val req = ctx.request
if (descriptor.isUriPublic(req.path)) {
authPlugin.access(ctx)(env, ec)
} else {
PrivateAppsUserHelper.isPrivateAppsSessionValid(req, descriptor, ctx.attrs).flatMap {
case Some(_) if descriptor.strictlyPrivate => apikeyPlugin.access(ctx.copy(config = apikeyConfig.json))
case Some(user) =>
case Some(_) if descriptor.strictlyPrivate => apikeyPlugin.access(ctx.copy(config = apikeyConfig.json))
case Some(user) =>
ctx.attrs.put(otoroshi.plugins.Keys.UserKey -> user)
NgAccess.NgAllowed.vfuture
case None =>
case None =>
apikeyPlugin.access(ctx.copy(config = apikeyConfig.json))
}
}
Expand Down

0 comments on commit fdf56ea

Please sign in to comment.