Skip to content

Commit

Permalink
resources refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Aug 28, 2023
1 parent ad2f468 commit b5e45d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
28 changes: 15 additions & 13 deletions otoroshi/app/api/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,8 @@ case class GenericResourceAccessApiWithState[T <: EntityLocationSupport](
override def update(values: Seq[T]): Unit = stateUpdate(values)
}

class GenericApiController(ApiAction: ApiAction, cc: ControllerComponents)(implicit env: Env)
extends AbstractController(cc) {

private val sourceBodyParser = BodyParser("GenericApiController BodyParser") { _ =>
Accumulator.source[ByteString].map(Right.apply)(env.otoroshiExecutionContext)
}

private implicit val ec = env.otoroshiExecutionContext

private implicit val mat = env.otoroshiMaterializer

private lazy val resources = Seq(
class OtoroshiResources(env: Env) {
lazy val resources = Seq(
///////
Resource(
"Route",
Expand Down Expand Up @@ -578,6 +568,18 @@ class GenericApiController(ApiAction: ApiAction, cc: ControllerComponents)(impli
)
)
) ++ env.adminExtensions.resources()
}

class GenericApiController(ApiAction: ApiAction, cc: ControllerComponents)(implicit env: Env)
extends AbstractController(cc) {

private val sourceBodyParser = BodyParser("GenericApiController BodyParser") { _ =>
Accumulator.source[ByteString].map(Right.apply)(env.otoroshiExecutionContext)
}

private implicit val ec = env.otoroshiExecutionContext

private implicit val mat = env.otoroshiMaterializer

private def filterPrefix: Option[String] = "filter.".some

Expand Down Expand Up @@ -854,7 +856,7 @@ class GenericApiController(ApiAction: ApiAction, cc: ControllerComponents)(impli
request: RequestHeader,
bulk: Boolean = false
)(f: Resource => Future[Result]): Future[Result] = {
resources
env.allResources.resources
.filter(_.version.served)
.find(r =>
(group == "any" || r.group == group) && (version == "any" || r.version.name == version) && r.pluralName == entity
Expand Down
2 changes: 2 additions & 0 deletions otoroshi/app/env/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,8 @@ class Env(

val servers = TcpService.runServers(this)

lazy val allResources = new otoroshi.api.OtoroshiResources(this)

lazy val adminExtensionsConfig = AdminExtensionConfig(
enabled = configuration.getOptionalWithFileSupport[Boolean]("otoroshi.admin-extensions.enabled").getOrElse(true)
)
Expand Down
2 changes: 1 addition & 1 deletion otoroshi/app/storage/storage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ trait OptimizedRedisLike {
case _ if key.startsWith(ds.backendsDataStore.key("")) => "backend".some
case _ if key.startsWith(ds.wasmPluginsDataStore.key("")) => "wasm-plugin".some
case _ => {
env.adminExtensions.resources()
env.allResources.resources
.map { res =>
(key.startsWith(res.access.key("")), res.singularName)
}
Expand Down

0 comments on commit b5e45d8

Please sign in to comment.