Skip to content

Commit

Permalink
feat #728: add validUntil field to API key subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
helakaraa committed Sep 6, 2024
1 parent e56a1bd commit 20dd4bf
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 181 deletions.
1 change: 1 addition & 0 deletions daikoku/app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ class ApiController(
apiKey = data.apiKey,
plan = data.plan,
createdAt = DateTime.now(),
validUntil = DateTime.now(),
team = data.team,
api = data.api,
by = ctx.user.id,
Expand Down
1 change: 1 addition & 0 deletions daikoku/app/domain/SchemaDefinition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,7 @@ object SchemaDefinition {
)
),
Field("createdAt", DateTimeUnitype, resolve = _.value.createdAt),
Field("validUntil", DateTimeUnitype, resolve = _.value.validUntil),
Field(
"team",
OptionType(TeamObjectType),
Expand Down
2 changes: 2 additions & 0 deletions daikoku/app/domain/apikeyEntities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ case class ApiSubscription(
apiKey: OtoroshiApiKey, // TODO: add the actual plan at the time of the subscription
plan: UsagePlanId,
createdAt: DateTime,
validUntil: DateTime,
team: TeamId,
api: ApiId,
by: UserId,
Expand Down Expand Up @@ -108,6 +109,7 @@ case class ApiSubscription(
"team" -> json.TeamIdFormat.writes(team),
"api" -> json.ApiIdFormat.writes(api),
"createdAt" -> json.DateTimeFormat.writes(createdAt),
"validUntil" -> json.DateTimeFormat.writes(validUntil),
"customName" -> customName
.map(id => JsString(id))
.getOrElse(JsNull)
Expand Down
2 changes: 2 additions & 0 deletions daikoku/app/domain/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,7 @@ object json {
team = (json \ "team").as(TeamIdFormat),
api = (json \ "api").as(ApiIdFormat),
createdAt = (json \ "createdAt").as(DateTimeFormat),
validUntil = (json \ "validUntil").as(DateTimeFormat),
by = (json \ "by").as(UserIdFormat),
customName = (json \ "customName").asOpt[String],
adminCustomName = (json \ "adminCustomName").asOpt[String],
Expand Down Expand Up @@ -2779,6 +2780,7 @@ object json {
"team" -> TeamIdFormat.writes(o.team),
"api" -> ApiIdFormat.writes(o.api),
"createdAt" -> DateTimeFormat.writes(o.createdAt),
"validUntil"-> DateTimeFormat.writes(o.validUntil),
"by" -> UserIdFormat.writes(o.by),
"customName" -> o.customName
.map(id => JsString(id))
Expand Down
2 changes: 2 additions & 0 deletions daikoku/app/utils/ApiService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class ApiService(
apiKey = tunedApiKey.asOtoroshiApiKey,
plan = plan.id,
createdAt = DateTime.now(),
validUntil = DateTime.now(),
team = team.id,
api = api.id,
by = user.id,
Expand Down Expand Up @@ -359,6 +360,7 @@ class ApiService(
apiKey = OtoroshiApiKey(clientName, clientId, clientSecret),
plan = plan.id,
createdAt = DateTime.now(),
validUntil = DateTime.now(),
team = team.id,
api = api.id,
by = user.id,
Expand Down
Loading

0 comments on commit 20dd4bf

Please sign in to comment.