Skip to content

Commit

Permalink
FIX #788
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed Dec 13, 2024
1 parent 115d233 commit 423be05
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
4 changes: 3 additions & 1 deletion daikoku/app/domain/apikeyEntities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 12 additions & 2 deletions daikoku/app/domain/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 13 additions & 6 deletions daikoku/app/utils/ApiService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -262,15 +264,15 @@ class ApiService(
team = team.id,
api = api.id,
by = user.id,
customName = None,
customName = customName,
rotation = plan.autoRotation.map(rotation =>
ApiSubscriptionRotation(enabled = rotation)
),
integrationToken = integrationToken,
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,
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 9 additions & 7 deletions manual/docs/02-usages/09-producerusage/1-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 423be05

Please sign in to comment.