Skip to content

Commit 7038f47

Browse files
authored
Merge pull request #825 from MAIF/feat/no-backoffice-for-api
Feat/no backoffice for api
2 parents a97fcb4 + e6e0025 commit 7038f47

File tree

168 files changed

+12788
-15955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+12788
-15955
lines changed

.github/workflows/playwright.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ jobs:
6464
npx playwright test --project chromium
6565
env:
6666
CI: true
67+
EXPOSED_PORT: 13200

daikoku/app/audit/audit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class AuditActor(implicit
406406
Map(
407407
"apiName" -> JsString(api.name),
408408
"planName" -> JsString(
409-
plan.customName.getOrElse(plan.typeName)
409+
plan.customName
410410
),
411411
"api_data" -> api.asJson,
412412
"usagePlan_data" -> plan.asJson,

daikoku/app/controllers/ApiController.scala

Lines changed: 180 additions & 300 deletions
Large diffs are not rendered by default.

daikoku/app/controllers/AppError.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ object AppError {
161161
"conflict, Api have already setup apikey rotation"
162162
case EntityConflict(entityName) =>
163163
s"Conflict with $entityName"
164-
case ForbiddenAction => "You're not authorized to do this action"
164+
case ForbiddenAction => "This action is forbidden"
165165
case TeamForbidden => "You're not part of this team"
166166
case ApiKeyCustomMetadataNotPrivided =>
167167
"You need to provide custom metadata"

daikoku/app/controllers/ConsumptionController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class ConsumptionController(
433433
.getOrElse(c.clientId)
434434
val plan: String = plans
435435
.find(p => p.id == c.plan)
436-
.map(plan => plan.customName.getOrElse(plan.typeName))
436+
.map(plan => plan.customName)
437437
.getOrElse(c.plan.value)
438438

439439
c.asJson.as[JsObject] ++ Json.obj(

daikoku/app/controllers/EntitiesController.scala

Lines changed: 47 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class EntitiesController(
128128
DaikokuAction.async { ctx =>
129129
PublicUserAccess(
130130
AuditTrailEvent(
131-
s"@{user.name} has asked for a template entity of type ApiDocumentationr"
131+
s"@{user.name} has asked for a template entity of type ApiDocumentation"
132132
)
133133
)(ctx) {
134134
Ok(
@@ -142,6 +142,24 @@ class EntitiesController(
142142
}
143143
}
144144

145+
def newApiDocumentationPage() =
146+
DaikokuAction.async { ctx =>
147+
PublicUserAccess(
148+
AuditTrailEvent(
149+
s"@{user.name} has asked for a template entity of type ApiDocumentationPage"
150+
)
151+
)(ctx) {
152+
Ok(
153+
ApiDocumentationPage(
154+
id = ApiDocumentationPageId(IdGenerator.token(32)),
155+
tenant = ctx.tenant.id,
156+
title = "New page",
157+
lastModificationAt = DateTime.now(),
158+
content = "# New page").asJson
159+
)
160+
}
161+
}
162+
145163
def newApiGroup() =
146164
DaikokuAction.async { ctx =>
147165
PublicUserAccess(
@@ -232,134 +250,40 @@ class EntitiesController(
232250
}
233251
}
234252

235-
def newPlan(planType: String): Action[AnyContent] =
253+
def newPlan(): Action[AnyContent] =
236254
DaikokuAction.async { ctx =>
237255
PublicUserAccess(
238256
AuditTrailEvent(
239257
s"@{user.name} has asked for a template entity of type Plan"
240258
)
241259
)(ctx) {
242-
planType match {
243-
case "Admin" =>
244-
Ok(
245-
UsagePlan
246-
.Admin(
247-
id = UsagePlanId(IdGenerator.token(32)),
248-
tenant = ctx.tenant.id,
249-
otoroshiTarget = None
250-
)
251-
.asJson
252-
)
253-
case "PayPerUse" =>
254-
Ok(
255-
UsagePlan
256-
.PayPerUse(
257-
id = UsagePlanId(IdGenerator.token(32)),
258-
tenant = ctx.tenant.id,
259-
costPerRequest = BigDecimal(0),
260-
costPerMonth = BigDecimal(0),
261-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
262-
trialPeriod = None,
263-
currency = Currency("EUR"),
264-
customName = None,
265-
customDescription = None,
266-
otoroshiTarget = None,
267-
allowMultipleKeys = Some(false),
268-
visibility = Private,
269-
autoRotation = Some(false),
270-
subscriptionProcess = Seq.empty,
271-
integrationProcess = IntegrationProcess.ApiKey
272-
)
273-
.asJson
274-
)
275-
case "FreeWithQuotas" =>
276-
Ok(
277-
UsagePlan
278-
.FreeWithQuotas(
279-
id = UsagePlanId(IdGenerator.token(32)),
280-
tenant = ctx.tenant.id,
281-
maxPerSecond = 0,
282-
maxPerDay = 0,
283-
maxPerMonth = 0,
284-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
285-
currency = Currency("EUR"),
286-
customName = None,
287-
customDescription = None,
288-
otoroshiTarget = None,
289-
allowMultipleKeys = Some(false),
290-
subscriptionProcess = Seq.empty,
291-
integrationProcess = IntegrationProcess.ApiKey,
292-
autoRotation = Some(false)
293-
)
294-
.asJson
295-
)
296-
case "FreeWithoutQuotas" =>
297-
Ok(
298-
UsagePlan
299-
.FreeWithoutQuotas(
300-
id = UsagePlanId(IdGenerator.token(32)),
301-
tenant = ctx.tenant.id,
302-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
303-
currency = Currency("EUR"),
304-
customName = None,
305-
customDescription = None,
306-
otoroshiTarget = None,
307-
allowMultipleKeys = Some(false),
308-
subscriptionProcess = Seq.empty,
309-
integrationProcess = IntegrationProcess.ApiKey,
310-
autoRotation = Some(false)
311-
)
312-
.asJson
313-
)
314-
case "QuotasWithLimits" =>
315-
Ok(
316-
UsagePlan
317-
.QuotasWithLimits(
318-
id = UsagePlanId(IdGenerator.token(32)),
319-
tenant = ctx.tenant.id,
320-
maxPerSecond = 0,
321-
maxPerDay = 0,
322-
maxPerMonth = 0,
323-
costPerMonth = BigDecimal(0),
324-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
325-
trialPeriod = None,
326-
currency = Currency("EUR"),
327-
customName = None,
328-
customDescription = None,
329-
otoroshiTarget = None,
330-
allowMultipleKeys = Some(false),
331-
subscriptionProcess = Seq.empty,
332-
integrationProcess = IntegrationProcess.ApiKey,
333-
autoRotation = Some(false)
334-
)
335-
.asJson
336-
)
337-
case "QuotasWithoutLimits" =>
338-
Ok(
339-
UsagePlan
340-
.QuotasWithoutLimits(
341-
id = UsagePlanId(IdGenerator.token(32)),
342-
tenant = ctx.tenant.id,
343-
maxPerSecond = 0,
344-
maxPerDay = 0,
345-
maxPerMonth = 0,
346-
costPerMonth = BigDecimal(0),
347-
costPerAdditionalRequest = BigDecimal(0),
348-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
349-
trialPeriod = None,
350-
currency = Currency("EUR"),
351-
customName = None,
352-
customDescription = None,
353-
otoroshiTarget = None,
354-
allowMultipleKeys = Some(true),
355-
subscriptionProcess = Seq.empty,
356-
integrationProcess = IntegrationProcess.ApiKey,
357-
autoRotation = Some(false)
358-
)
359-
.asJson
360-
)
361-
case _ => BadRequest(Json.obj("error" -> "Unrecognized type of plan"))
362-
}
260+
Ok(UsagePlan(
261+
id = UsagePlanId(IdGenerator.token(32)),
262+
tenant = ctx.tenant.id,
263+
maxPerSecond = None,
264+
maxPerDay = None,
265+
maxPerMonth = None,
266+
costPerMonth = None,
267+
costPerRequest = None,
268+
billingDuration = None,
269+
trialPeriod = None,
270+
currency = None,
271+
customName = "new usage plan",
272+
customDescription = None,
273+
otoroshiTarget = None,
274+
allowMultipleKeys = Some(false),
275+
subscriptionProcess = Seq.empty,
276+
integrationProcess = IntegrationProcess.ApiKey,
277+
autoRotation = Some(false),
278+
documentation = if (ctx.tenant.display == TenantDisplay.Environment)
279+
ApiDocumentation(
280+
id = ApiDocumentationId(IdGenerator.token(32)),
281+
tenant = ctx.tenant.id,
282+
lastModificationAt = DateTime.now(),
283+
pages = Seq.empty
284+
).some
285+
else None
286+
).asJson)
363287
}
364288
}
365289
}

daikoku/app/controllers/MockController.scala

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ class MockController(
148148

149149
def samplePlans(tenantId: TenantId, linkToOtoroshi: Boolean = false) =
150150
Seq(
151-
FreeWithoutQuotas(
151+
UsagePlan(
152152
id = UsagePlanId(IdGenerator.token),
153153
tenant = tenantId,
154-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
155-
currency = Currency("EUR"),
156-
customName = None,
154+
billingDuration = BillingDuration(1, BillingTimeUnit.Month).some,
155+
currency = Currency("EUR").some,
156+
customName = "plan 1",
157157
customDescription = None,
158158
allowMultipleKeys = Some(false),
159159
autoRotation = None,
@@ -173,15 +173,15 @@ class MockController(
173173
)
174174
else None
175175
),
176-
FreeWithQuotas(
176+
UsagePlan(
177177
id = UsagePlanId(IdGenerator.token),
178178
tenant = tenantId,
179-
maxPerSecond = 2000,
180-
maxPerDay = 2000,
181-
maxPerMonth = 2000,
182-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
183-
currency = Currency("EUR"),
184-
customName = None,
179+
maxPerSecond = 2000L.some,
180+
maxPerDay = 2000L.some,
181+
maxPerMonth = 2000L.some,
182+
billingDuration = BillingDuration(1, BillingTimeUnit.Month).some,
183+
currency = Currency("EUR").some,
184+
customName = "plan 2",
185185
customDescription = None,
186186
allowMultipleKeys = Some(false),
187187
autoRotation = None,
@@ -201,17 +201,17 @@ class MockController(
201201
)
202202
else None
203203
),
204-
QuotasWithLimits(
204+
UsagePlan(
205205
id = UsagePlanId(IdGenerator.token),
206206
tenant = tenantId,
207-
maxPerSecond = 10000,
208-
maxPerDay = 10000,
209-
maxPerMonth = 10000,
210-
costPerMonth = BigDecimal(10.0),
211-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
207+
maxPerSecond = 10000L.some,
208+
maxPerDay = 10000L.some,
209+
maxPerMonth = 10000L.some,
210+
costPerMonth = BigDecimal(10.0).some,
211+
billingDuration = BillingDuration(1, BillingTimeUnit.Month).some,
212212
trialPeriod = None,
213-
currency = Currency("EUR"),
214-
customName = None,
213+
currency = Currency("EUR").some,
214+
customName = "plan 3",
215215
customDescription = None,
216216
allowMultipleKeys = Some(false),
217217
autoRotation = None,
@@ -231,18 +231,18 @@ class MockController(
231231
)
232232
else None
233233
),
234-
QuotasWithoutLimits(
234+
UsagePlan(
235235
id = UsagePlanId(IdGenerator.token),
236236
tenant = tenantId,
237-
maxPerSecond = 10000,
238-
maxPerDay = 10000,
239-
maxPerMonth = 10000,
240-
costPerAdditionalRequest = BigDecimal(0.015),
241-
costPerMonth = BigDecimal(10.0),
242-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
237+
maxPerSecond = 10000L.some,
238+
maxPerDay = 10000L.some,
239+
maxPerMonth = 10000L.some,
240+
costPerRequest = BigDecimal(0.015).some,
241+
costPerMonth = BigDecimal(10.0).some,
242+
billingDuration = BillingDuration(1, BillingTimeUnit.Month).some,
243243
trialPeriod = None,
244-
currency = Currency("EUR"),
245-
customName = None,
244+
currency = Currency("EUR").some,
245+
customName = "plan 4",
246246
customDescription = None,
247247
allowMultipleKeys = Some(false),
248248
autoRotation = None,
@@ -262,15 +262,15 @@ class MockController(
262262
)
263263
else None
264264
),
265-
PayPerUse(
265+
UsagePlan(
266266
id = UsagePlanId(IdGenerator.token),
267267
tenant = tenantId,
268-
costPerMonth = BigDecimal(10.0),
269-
costPerRequest = BigDecimal(0.02),
270-
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
268+
costPerMonth = BigDecimal(10.0).some,
269+
costPerRequest = BigDecimal(0.02).some,
270+
billingDuration = BillingDuration(1, BillingTimeUnit.Month).some,
271271
trialPeriod = None,
272-
currency = Currency("EUR"),
273-
customName = None,
272+
currency = Currency("EUR").some,
273+
customName = "plan 5",
274274
customDescription = None,
275275
allowMultipleKeys = Some(false),
276276
autoRotation = None,
@@ -634,28 +634,24 @@ class MockController(
634634
case None => NotFound(Json.obj("error" -> "plan not found"))
635635
case Some(pp) =>
636636
val callPerSec =
637-
r.nextInt(pp.maxRequestPerSecond.getOrElse(10L).toInt)
637+
r.nextLong(pp.maxPerSecond.getOrElse(Long.MaxValue))
638638
val callPerDay =
639-
r.nextInt(pp.maxRequestPerDay.getOrElse(100L).toInt)
639+
r.nextLong(pp.maxPerDay.getOrElse(Long.MaxValue))
640640
val callPerMonth =
641-
r.nextInt(pp.maxRequestPerMonth.getOrElse(1000L).toInt)
641+
r.nextLong(pp.maxPerMonth.getOrElse(Long.MaxValue))
642642

643643
Ok(
644644
ApiKeyQuotas(
645645
authorizedCallsPerSec =
646-
pp.maxRequestPerSecond.getOrElse(0),
646+
pp.maxPerSecond.getOrElse(Long.MaxValue),
647647
currentCallsPerSec = callPerSec,
648-
remainingCallsPerSec = pp.maxRequestPerSecond
649-
.getOrElse(0L) - callPerSec,
650-
authorizedCallsPerDay = pp.maxRequestPerDay.getOrElse(0),
648+
remainingCallsPerSec = pp.maxPerSecond.getOrElse(Long.MaxValue) - callPerSec,
649+
authorizedCallsPerDay = pp.maxPerDay.getOrElse(Long.MaxValue),
651650
currentCallsPerDay = callPerDay,
652-
remainingCallsPerDay = pp.maxRequestPerDay
653-
.getOrElse(0L) - callPerDay,
654-
authorizedCallsPerMonth =
655-
pp.maxRequestPerMonth.getOrElse(0),
651+
remainingCallsPerDay = pp.maxPerDay.getOrElse(Long.MaxValue) - callPerDay,
652+
authorizedCallsPerMonth = pp.maxPerMonth.getOrElse(Long.MaxValue),
656653
currentCallsPerMonth = callPerMonth,
657-
remainingCallsPerMonth = pp.maxRequestPerMonth
658-
.getOrElse(0L) - callPerMonth
654+
remainingCallsPerMonth = pp.maxPerMonth.getOrElse(Long.MaxValue) - callPerMonth
659655
).asJson
660656
)
661657
}

0 commit comments

Comments
 (0)