From ad2f4684b42e7ca40e90539afd85ef7639af9883 Mon Sep 17 00:00:00 2001 From: Mathieu Ancelin Date: Mon, 28 Aug 2023 14:03:38 +0200 Subject: [PATCH] fix #1690 --- otoroshi/app/api/api.scala | 12 ++++++++++++ .../app/storage/drivers/reactivepg/reactivepg.scala | 8 +++++--- otoroshi/app/storage/storage.scala | 13 ++++++++++++- otoroshi/build.sbt | 4 ++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/otoroshi/app/api/api.scala b/otoroshi/app/api/api.scala index 4f275c8b91..c8b417a9e1 100644 --- a/otoroshi/app/api/api.scala +++ b/otoroshi/app/api/api.scala @@ -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", diff --git a/otoroshi/app/storage/drivers/reactivepg/reactivepg.scala b/otoroshi/app/storage/drivers/reactivepg/reactivepg.scala index fe688f383e..98c4a63017 100644 --- a/otoroshi/app/storage/drivers/reactivepg/reactivepg.scala +++ b/otoroshi/app/storage/drivers/reactivepg/reactivepg.scala @@ -898,7 +898,8 @@ 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) @@ -906,11 +907,12 @@ class ReactivePgRedis( |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) @@ -918,7 +920,7 @@ class ReactivePgRedis( |DO | update set type = 'string', value = $$2${maybeTtlUpdate}; |""".stripMargin, - Seq(key, value.utf8String) + Seq(key, sanitizedValue), ) { _ => true.some }.map(_.getOrElse(true)) diff --git a/otoroshi/app/storage/storage.scala b/otoroshi/app/storage/storage.scala index 4e4b802930..32781bca1f 100644 --- a/otoroshi/app/storage/storage.scala +++ b/otoroshi/app/storage/storage.scala @@ -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) + } } } } diff --git a/otoroshi/build.sbt b/otoroshi/build.sbt index 2af6048dad..3a3603b24f 100644 --- a/otoroshi/build.sbt +++ b/otoroshi/build.sbt @@ -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/",