From 423be054f4ac34ff20b868eb4d4c2eb7c89c2b18 Mon Sep 17 00:00:00 2001 From: Quentin AUBERT Date: Fri, 13 Dec 2024 15:56:04 +0100 Subject: [PATCH] FIX #788 --- daikoku/app/domain/apikeyEntities.scala | 4 +++- daikoku/app/domain/json.scala | 14 ++++++++++++-- daikoku/app/utils/ApiService.scala | 19 +++++++++++++------ .../docs/02-usages/09-producerusage/1-apis.md | 16 +++++++++------- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/daikoku/app/domain/apikeyEntities.scala b/daikoku/app/domain/apikeyEntities.scala index cca9d40ae..521b3d5a9 100644 --- a/daikoku/app/domain/apikeyEntities.scala +++ b/daikoku/app/domain/apikeyEntities.scala @@ -307,7 +307,9 @@ case class SubscriptionDemand( customMaxPerSecond: Option[Long] = None, customMaxPerDay: Option[Long] = None, customMaxPerMonth: Option[Long] = None, - adminCustomName: Option[String] = None + adminCustomName: Option[String] = None, + customName: Option[String] = None, + tags: Option[Set[String]] = None ) extends CanJson[SubscriptionDemand] { override def asJson: JsValue = json.SubscriptionDemandFormat.writes(this) } diff --git a/daikoku/app/domain/json.scala b/daikoku/app/domain/json.scala index d9c08646e..47f917e64 100644 --- a/daikoku/app/domain/json.scala +++ b/daikoku/app/domain/json.scala @@ -2920,7 +2920,15 @@ object json { "adminCustomName" -> o.adminCustomName .map(JsString.apply) .getOrElse(JsNull) - .as[JsValue] + .as[JsValue], + "customName" -> o.customName + .map(JsString.apply) + .getOrElse(JsNull) + .as[JsValue], + "tags" -> o.tags + .map(t => JsArray(t.toSeq.map(JsString.apply))) + .getOrElse(JsNull) + .as[JsValue], ) override def reads(json: JsValue): JsResult[SubscriptionDemand] = @@ -2948,7 +2956,9 @@ object json { customMaxPerDay = (json \ "customMaxPerDay").asOpt[Long], customMaxPerMonth = (json \ "customMaxPerMonth").asOpt[Long], customReadOnly = (json \ "customReadOnly").asOpt[Boolean], - adminCustomName = (json \ "adminCustomName").asOpt[String] + adminCustomName = (json \ "adminCustomName").asOpt[String], + customName = (json \ "customName").asOpt[String], + tags = (json \ "tags").asOpt[Set[String]] ) ) } recover { diff --git a/daikoku/app/utils/ApiService.scala b/daikoku/app/utils/ApiService.scala index f32cad227..a35460d76 100644 --- a/daikoku/app/utils/ApiService.scala +++ b/daikoku/app/utils/ApiService.scala @@ -199,7 +199,9 @@ class ApiService( adminCustomName: Option[String] = None, thirdPartySubscriptionInformations: Option[ ThirdPartySubscriptionInformations - ] + ], + customName: Option[String] = None, + tags: Option[Set[String]] = None ): Future[Either[AppError, ApiSubscription]] = { def createKey( api: Api, @@ -262,7 +264,7 @@ class ApiService( team = team.id, api = api.id, by = user.id, - customName = None, + customName = customName, rotation = plan.autoRotation.map(rotation => ApiSubscriptionRotation(enabled = rotation) ), @@ -270,7 +272,7 @@ class ApiService( metadata = Some( JsObject(automaticMetadata.view.mapValues(i => JsString(i)).toSeq) ), - tags = Some(tunedApiKey.tags), + tags = tags.map(_ ++ tunedApiKey.tags).orElse(tunedApiKey.tags.some), customMetadata = customMetadata, customMaxPerSecond = customMaxPerSecond, customMaxPerDay = customMaxPerDay, @@ -1758,6 +1760,8 @@ class ApiService( val customMaxPerMonth = (response \ "customMaxPerMonth").asOpt[Long] val customReadOnly = (response \ "customReadOnly").asOpt[Boolean] val adminCustomName = (response \ "adminCustomName").asOpt[String] + val customName = (response \ "customName").asOpt[String] + val tags = (response \ "tags").asOpt[Set[String]] for { _ <- _step.check() @@ -1774,7 +1778,9 @@ class ApiService( customMaxPerSecond = customMaxPerSecond, customMaxPerDay = customMaxPerDay, customMaxPerMonth = customMaxPerMonth, - customReadOnly = customReadOnly + customReadOnly = customReadOnly, + customName = customName, + tags = tags ) _ <- EitherT.liftF( env.dataStore.subscriptionDemandRepo @@ -2227,8 +2233,9 @@ class ApiService( customMaxPerMonth = demand.customMaxPerMonth, customReadOnly = demand.customReadOnly, adminCustomName = demand.adminCustomName, - thirdPartySubscriptionInformations = - maybeSubscriptionInformations + thirdPartySubscriptionInformations = maybeSubscriptionInformations, + customName = demand.customName, + tags = demand.tags ) ) administrators <- EitherT.liftF( diff --git a/manual/docs/02-usages/09-producerusage/1-apis.md b/manual/docs/02-usages/09-producerusage/1-apis.md index 0c017222d..b7ac9c96c 100644 --- a/manual/docs/02-usages/09-producerusage/1-apis.md +++ b/manual/docs/02-usages/09-producerusage/1-apis.md @@ -64,17 +64,19 @@ A JSON response is awaited with a precise format. > it totally possible to calculate and give some metadata or custom property for the subscription to created > ```json > { -> "accept": true, -> "customMaxPerDay": 42, -> "customMaxPerSecond": 42, -> "customMaxPerMonth": 42, -> "customMetadata": { +> "accept": true, //mendatory +> "customMaxPerDay": 42, //set quotas value for max request per day for API key +> "customMaxPerSecond": 42, //set Quotas value for max request per second for API key +> "customMaxPerMonth": 42, //set Quotas value for max request per Month for API key +> "customMetadata": { //set metadata (merge with automatic metadata) for API key > "value1": 2, > "value2": true, > "value3": "foo" > }, -> "adminCustomName": "foo-bar-apikey", -> "customReadOnly": true +> "adminCustomName": "foo-bar-apikey", //admin custom name is a subscription name only visible by api producer +> "customReadOnly": true, //set readonly property for APIkey +> "customName": "bar-foo-apikey", //custom name is the subscription name visible by consumer (it can be overwritten by him) +> "tags": ["tag 1", "tag 2"] //merge tags with automatic tags and set tags of API key. be aware of tags are displayed for consumer in UI > } > ``` > The body of the call contains a lot of data in the context: the subscription demand with the other step information, the API, the usage plan, the team and the aggregation in case of an aggregated apikey