diff --git a/otoroshi/app/controllers/BackOfficeController.scala b/otoroshi/app/controllers/BackOfficeController.scala index 270d0e5e4..bca904a38 100644 --- a/otoroshi/app/controllers/BackOfficeController.scala +++ b/otoroshi/app/controllers/BackOfficeController.scala @@ -2138,7 +2138,9 @@ class BackOfficeController( identity = Identity( identityType = "APIKEY", identity = "client_id", - label = "client" + label = "client", + tags = Seq.empty, + metadata = Map.empty, ).some, responseChunked = false, `@serviceId` = s"route_${IdGenerator.uuid}", diff --git a/otoroshi/app/events/analytics.scala b/otoroshi/app/events/analytics.scala index 2bcf4b00f..3a614fd26 100644 --- a/otoroshi/app/events/analytics.scala +++ b/otoroshi/app/events/analytics.scala @@ -18,6 +18,7 @@ import otoroshi.tcp.TcpService import play.api.Logger import play.api.libs.json._ import otoroshi.utils.json.JsonImplicits._ +import otoroshi.utils.syntax.implicits.{BetterJsReadable, BetterJsValue} import scala.collection.mutable import scala.concurrent.duration.FiniteDuration @@ -236,10 +237,32 @@ trait AnalyticEvent extends OtoroshiEvent { } } -case class Identity(identityType: String, identity: String, label: String) +case class Identity(identityType: String, identity: String, label: String, tags: Seq[String], metadata: Map[String, String]) { + def json: JsValue = Identity.format.writes(this) +} object Identity { - implicit val format = Json.format[Identity] + implicit val format = new Format[Identity] { + override def writes(o: Identity): JsValue = Json.obj( + "identityType" -> o.identityType, + "identity" -> o.identity, + "label" -> o.label, + "metadata" -> o.metadata, + "tags" -> o.tags, + ) + override def reads(json: JsValue): JsResult[Identity] = scala.util.Try { + Identity( + identityType = json.select("identityType").asString, + identity = json.select("identity").asString, + label = json.select("label").asString, + metadata = json.select("metadata").asOpt[Map[String, String]].getOrElse(Map.empty), + tags = json.select("tags").asOpt[Seq[String]].getOrElse(Seq.empty), + ) + } match { + case Success(s) => JsSuccess(s) + case Failure(e) => JsError(e.getMessage) + } + } } case class Location(host: String, scheme: String, uri: String) diff --git a/otoroshi/app/gateway/http.scala b/otoroshi/app/gateway/http.scala index d5e2120f0..23261c883 100644 --- a/otoroshi/app/gateway/http.scala +++ b/otoroshi/app/gateway/http.scala @@ -343,7 +343,9 @@ class HttpHandler()(implicit env: Env) { Identity( identityType = "APIKEY", identity = k.clientId, - label = k.clientName + label = k.clientName, + tags = k.tags, + metadata = k.metadata, ) ) .orElse( @@ -351,7 +353,9 @@ class HttpHandler()(implicit env: Env) { Identity( identityType = "PRIVATEAPP", identity = k.email, - label = k.name + label = k.name, + tags = k.tags, + metadata = k.metadata, ) ) ), diff --git a/otoroshi/app/gateway/websockets.scala b/otoroshi/app/gateway/websockets.scala index a21dc2e4c..5d9d17f5f 100644 --- a/otoroshi/app/gateway/websockets.scala +++ b/otoroshi/app/gateway/websockets.scala @@ -268,7 +268,9 @@ class WebSocketHandler()(implicit env: Env) { Identity( identityType = "APIKEY", identity = k.clientId, - label = k.clientName + label = k.clientName, + tags = k.tags, + metadata = k.metadata, ) ) .orElse( @@ -276,7 +278,9 @@ class WebSocketHandler()(implicit env: Env) { Identity( identityType = "PRIVATEAPP", identity = k.email, - label = k.name + label = k.name, + tags = k.tags, + metadata = k.metadata, ) ) ), diff --git a/otoroshi/app/next/proxy/engine.scala b/otoroshi/app/next/proxy/engine.scala index b48937d92..15830e132 100644 --- a/otoroshi/app/next/proxy/engine.scala +++ b/otoroshi/app/next/proxy/engine.scala @@ -3457,7 +3457,9 @@ class ProxyEngine() extends RequestHandler { Identity( identityType = "APIKEY", identity = k.clientId, - label = k.clientName + label = k.clientName, + tags = k.tags, + metadata = k.metadata, ) ) .orElse( @@ -3465,7 +3467,9 @@ class ProxyEngine() extends RequestHandler { Identity( identityType = "PRIVATEAPP", identity = k.email, - label = k.name + label = k.name, + tags = k.tags, + metadata = k.metadata, ) ) ), @@ -3615,7 +3619,9 @@ class ProxyEngine() extends RequestHandler { Identity( identityType = "APIKEY", identity = k.clientId, - label = k.clientName + label = k.clientName, + tags = k.tags, + metadata = k.metadata, ) ) .orElse( @@ -3623,7 +3629,9 @@ class ProxyEngine() extends RequestHandler { Identity( identityType = "PRIVATEAPP", identity = k.email, - label = k.name + label = k.name, + tags = k.tags, + metadata = k.metadata, ) ) ),