Skip to content

Commit

Permalink
fix #1690
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Aug 28, 2023
1 parent bdbf356 commit ad2f468
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
12 changes: 12 additions & 0 deletions otoroshi/app/api/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ class GenericApiController(ApiAction: ApiAction, cc: ControllerComponents)(impli
env.datastores.tenantDataStore.extractId
)
),
Resource(
"Tenant",
"tenants",
"tenant",
"organize.otoroshi.io",
ResourceVersion("v1", true, false, true),
GenericResourceAccessApi[Tenant](
Tenant.format,
env.datastores.tenantDataStore.key,
env.datastores.tenantDataStore.extractId
)
),
Resource(
"Team",
"teams",
Expand Down
8 changes: 5 additions & 3 deletions otoroshi/app/storage/drivers/reactivepg/reactivepg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -898,27 +898,29 @@ class ReactivePgRedis(
.map(ttl => s", ttl = $ttl, ttl_starting_at = NOW()")
.getOrElse("")
matchesEntity(key, value) match {
case Some((kind, jsonValue)) =>
case Some((kind, _jsonValue)) =>
val jsonValue = _jsonValue.replace("'", "''")
queryOne(
s"""insert into $schemaDotTable (key, type, ttl, ttl_starting_at, value, kind, jvalue)
|values ($$1, 'string', $ttl, NOW(), $$2, '$kind', '$jsonValue'::jsonb)
|ON CONFLICT (key)
|DO
| update set type = 'string', value = $$2$maybeTtlUpdate, kind = $$3, jvalue = $$4::jsonb;
|""".stripMargin,
Seq(key, value.utf8String, kind, new JsonObject(jsonValue))
Seq(key, value.utf8String, kind, new JsonObject(jsonValue)),
) { _ =>
true.some
}.map(_.getOrElse(true))
case None =>
val sanitizedValue = value.utf8String.replace("'", "''")
queryOne(
s"""insert into $schemaDotTable (key, type, ttl, ttl_starting_at, value)
|values ($$1, 'string', $ttl, NOW(), $$2)
|ON CONFLICT (key)
|DO
| update set type = 'string', value = $$2${maybeTtlUpdate};
|""".stripMargin,
Seq(key, value.utf8String)
Seq(key, sanitizedValue),
) { _ =>
true.some
}.map(_.getOrElse(true))
Expand Down
13 changes: 12 additions & 1 deletion otoroshi/app/storage/storage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,18 @@ trait OptimizedRedisLike {
case _ if key.startsWith(ds.tenantDataStore.key("")) => "tenant".some
case _ if key.startsWith(ds.tcpServiceDataStore.key("")) => "tcp-service".some
case _ if key.startsWith(ds.globalConfigDataStore.key("")) => "global-config".some
case _ => None
case _ if key.startsWith(ds.routeDataStore.key("")) => "route".some
case _ if key.startsWith(ds.routeCompositionDataStore.key("")) => "route-composition".some
case _ if key.startsWith(ds.backendsDataStore.key("")) => "backend".some
case _ if key.startsWith(ds.wasmPluginsDataStore.key("")) => "wasm-plugin".some
case _ => {
env.adminExtensions.resources()
.map { res =>
(key.startsWith(res.access.key("")), res.singularName)
}
.find(_._1)
.map(_._2)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions otoroshi/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ reStart / javaOptions ++= Seq(
"-Dotoroshi.loggers.otoroshi-wasm-debug=INFO",
"-Dotoroshi.loggers.otoroshi-proxy-wasm=TRACE",
"-Dotoroshi.options.enable-json-media-type-with-open-charset=true",
"-Dotoroshi.next.state-sync-interval=1000"
"-Dotoroshi.next.state-sync-interval=1000",
// "-Dotoroshi.next.experimental.netty-server.native.driver=IOUring",
// "-Dotoroshi.storage=experimental-pg",
// "-Dotoroshi.storage=postgresql",
// "-Dotoroshi.storage=redis",
// "-Dotoroshi.storage=lettuce",
// "-Dotoroshi.redis.lettuce.uri=redis://localhost:6379/",
Expand Down

0 comments on commit ad2f468

Please sign in to comment.