Skip to content

Commit 6aaea8c

Browse files
authored
Merge pull request #2610 from MAIF/no-more-ace
No more ace
2 parents 501e17d + 513071d commit 6aaea8c

22 files changed

Lines changed: 412 additions & 202 deletions

File tree

otoroshi/app/controllers/adminapi/ApiKeysController.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,7 @@ class ApiKeysController(val ApiAction: ApiAction, val cc: ControllerComponents)(
853853
TypedMap.empty,
854854
apiKey.throttlingStrategy
855855
)
856-
strategy.quotas(clientId, env.throttlingWindow).map(rq => Ok(rq.legacy().toJson))
857-
// apiKey.remainingQuotas().map(rq => Ok(rq.toJson))
856+
strategy.quotas(clientId, apiKey.allowedQuota, env.throttlingWindow).map(rq => Ok(rq.legacy().toJson))
858857
}
859858
}
860859
}
@@ -876,8 +875,7 @@ class ApiKeysController(val ApiAction: ApiAction, val cc: ControllerComponents)(
876875
TypedMap.empty,
877876
apiKey.throttlingStrategy
878877
)
879-
strategy.reset(clientId, env.throttlingWindow).map(rq => Ok(rq.legacy().toJson))
880-
// env.datastores.apiKeyDataStore.resetQuotas(apiKey).map(rq => Ok(rq.toJson))
878+
strategy.reset(clientId, apiKey.allowedQuota, env.throttlingWindow).map(rq => Ok(rq.legacy().toJson))
881879
}
882880
}
883881
}

otoroshi/app/models/apikey.scala

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ case class ApiKey(
317317
"tags" -> tags
318318
)
319319

320+
def allowedQuota: AllowedQuota =
321+
throttlingStrategy
322+
.map(_.quota)
323+
.getOrElse(AllowedQuota(window = throttlingQuota, daily = dailyQuota, monthly = monthlyQuota))
324+
320325
def matchRouting(sr: ServiceDescriptor): Boolean = matchRouting(sr.apiKeyConstraints)
321326

322327
def matchRouting(apiKeyConstraints: ApiKeyConstraints): Boolean = matchRouting(apiKeyConstraints.routing)
@@ -2409,15 +2414,7 @@ object ApiKeyHelper {
24092414
.checkAndIncrement(
24102415
apikey.clientId,
24112416
1,
2412-
apikey.throttlingStrategy
2413-
.map(_.quota)
2414-
.getOrElse(
2415-
AllowedQuota(
2416-
window = apikey.throttlingQuota,
2417-
daily = apikey.dailyQuota,
2418-
monthly = apikey.monthlyQuota
2419-
)
2420-
),
2417+
apikey.allowedQuota,
24212418
env.throttlingWindow
24222419
)
24232420
.flatMap {
@@ -2442,14 +2439,8 @@ object ApiKeyHelper {
24422439
strategy
24432440
.check(
24442441
apikey.clientId,
2445-
AllowedQuota(
2446-
window = apikey.throttlingQuota,
2447-
daily = apikey.dailyQuota,
2448-
monthly = apikey.monthlyQuota
2449-
)
2442+
apikey.allowedQuota
24502443
)
2451-
// env.datastores.apiKeyDataStore
2452-
// .remainingQuotas(apikey)
24532444
.flatMap { result =>
24542445
if (result.allowed) {
24552446
attrs.put(otoroshi.plugins.Keys.ApiKeyRemainingQuotasKey -> result.quotas.legacy())

otoroshi/app/next/plugins/rateLimiting.scala

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ case class LocalTokensBucketStrategy(bucketId: String, config: LocalTokensBucket
197197
}
198198
}
199199

200-
override def reset(key: String, expirationSeconds: Int)(implicit
200+
override def reset(key: String, allowedQuotas: AllowedQuota, expirationSeconds: Int)(implicit
201201
env: Env,
202202
ec: ExecutionContext
203203
): Future[QuotaState] = {
@@ -218,9 +218,9 @@ case class LocalTokensBucketStrategy(bucketId: String, config: LocalTokensBucket
218218
redisCli.expire(monthlyQuotaKey(key), (toMonthEnd / 1000).toInt)
219219
}
220220
} yield QuotaState(
221-
window = Quota(limit = config.quota.window, consumed = 0, resetsAt = 0),
222-
daily = Quota(limit = config.quota.daily, consumed = 0, resetsAt = dayEnd.getMillis),
223-
monthly = Quota(limit = config.quota.monthly, consumed = 0, resetsAt = monthEnd.getMillis)
221+
window = Quota(limit = allowedQuotas.window, consumed = 0, resetsAt = 0),
222+
daily = Quota(limit = allowedQuotas.daily, consumed = 0, resetsAt = dayEnd.getMillis),
223+
monthly = Quota(limit = allowedQuotas.monthly, consumed = 0, resetsAt = monthEnd.getMillis)
224224
)
225225
}
226226
}
@@ -582,7 +582,7 @@ case class FixedWindowStrategy(bucketId: String, config: FixedWindowStrategyConf
582582
)
583583
}
584584
} else {
585-
quotas(key, expirationSeconds)
585+
quotas(key, config.quota, expirationSeconds)
586586
.map(quotas =>
587587
ThrottlingResult(
588588
allowed = false,
@@ -1037,7 +1037,10 @@ trait ThrottlingStrategy {
10371037
}
10381038
}
10391039

1040-
def quotas(key: String, expirationSeconds: Int)(implicit ec: ExecutionContext, env: Env): Future[QuotaState] = {
1040+
def quotas(key: String, allowedQuotas: AllowedQuota, expirationSeconds: Int)(implicit
1041+
ec: ExecutionContext,
1042+
env: Env
1043+
): Future[QuotaState] = {
10411044
val redisCli = client()
10421045

10431046
val dayEnd = DateTime.now().secondOfDay().withMaximumValue()
@@ -1056,17 +1059,17 @@ trait ThrottlingStrategy {
10561059
} yield {
10571060
QuotaState(
10581061
window = Quota(
1059-
limit = config.quota.window,
1062+
limit = allowedQuotas.window,
10601063
consumed = throttlingCallsPerWindow,
10611064
resetsAt = now + windowTTL
10621065
),
10631066
daily = Quota(
1064-
limit = config.quota.daily,
1067+
limit = allowedQuotas.daily,
10651068
consumed = dailyCalls,
10661069
resetsAt = dayEnd.getMillis
10671070
),
10681071
monthly = Quota(
1069-
limit = config.quota.monthly,
1072+
limit = allowedQuotas.monthly,
10701073
consumed = monthlyCalls,
10711074
resetsAt = monthEnd.getMillis
10721075
)
@@ -1116,7 +1119,10 @@ trait ThrottlingStrategy {
11161119
}
11171120
}
11181121

1119-
def reset(key: String, expirationSeconds: Int)(implicit env: Env, ec: ExecutionContext): Future[QuotaState] = {
1122+
def reset(key: String, allowedQuotas: AllowedQuota, expirationSeconds: Int)(implicit
1123+
env: Env,
1124+
ec: ExecutionContext
1125+
): Future[QuotaState] = {
11201126
val redisCli = client()
11211127

11221128
val now = System.currentTimeMillis()
@@ -1144,9 +1150,9 @@ trait ThrottlingStrategy {
11441150
redisCli.expire(monthlyQuotaKey(key), (toMonthEnd / 1000).toInt)
11451151
}
11461152
} yield QuotaState(
1147-
window = Quota(limit = config.quota.window, consumed = 0, resetsAt = now + windowTTL),
1148-
daily = Quota(limit = config.quota.daily, consumed = 0, resetsAt = dayEnd.getMillis),
1149-
monthly = Quota(limit = config.quota.monthly, consumed = 0, resetsAt = monthEnd.getMillis)
1153+
window = Quota(limit = allowedQuotas.window, consumed = 0, resetsAt = now + windowTTL),
1154+
daily = Quota(limit = allowedQuotas.daily, consumed = 0, resetsAt = dayEnd.getMillis),
1155+
monthly = Quota(limit = allowedQuotas.monthly, consumed = 0, resetsAt = monthEnd.getMillis)
11501156
)
11511157
}
11521158

otoroshi/javascript/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"dependencies": {
2929
"@fortawesome/fontawesome-free": "^6.2.0",
3030
"@xyflow/react": "12.10.0",
31-
"ace-builds": "1.43.5",
3231
"antd": "^4.21.4",
3332
"bcryptjs": "2.4.3",
3433
"browser-update": "3.3.63",
@@ -48,7 +47,6 @@
4847
"moment": "2.30.1",
4948
"query-string": "9.1.1",
5049
"react": "17.0.2",
51-
"react-ace": "12.0.0",
5250
"react-color": "^2.19.3",
5351
"react-dom": "17.0.2",
5452
"react-query": "^3.39.3",

otoroshi/javascript/src/apps/BackOfficeApp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ class BackOfficeAppContainer extends Component {
402402
)}
403403
<div
404404
id="otoroshi-container"
405+
className={sidebarMode === 'expanded' ? 'sidebar--expanded' : ''}
405406
style={{ height: 'calc(100vh - 52px)' /*, overflow: 'hidden'*/ }}
406407
>
407408
<div className="d-flex" style={{ position: 'relative' }}>

0 commit comments

Comments
 (0)