mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:06:50 +00:00
rate-limits current usage endpoint
This commit is contained in:
parent
42fc8226c9
commit
47d6f97d89
@ -4086,6 +4086,17 @@ object SwaggerDefinitionsJSON {
|
||||
Some(rateLimit)
|
||||
)
|
||||
|
||||
lazy val rateLimitV600 = RateLimitV600(Some(42), Some(15), "ACTIVE")
|
||||
|
||||
lazy val redisCallLimitJsonV600 = RedisCallLimitJsonV600(
|
||||
Some(rateLimitV600),
|
||||
Some(rateLimitV600),
|
||||
Some(rateLimitV600),
|
||||
Some(rateLimitV600),
|
||||
Some(rateLimitV600),
|
||||
Some(rateLimitV600)
|
||||
)
|
||||
|
||||
lazy val callLimitJson = CallLimitJson(
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
|
||||
@ -222,7 +222,22 @@ trait APIMethods600 {
|
||||
"/management/consumers/CONSUMER_ID/consumer/current-usage",
|
||||
"Get Rate Limits for a Consumer Usage",
|
||||
s"""
|
||||
|Get Rate Limits for a Consumer Usage.
|
||||
|Get the current rate limit usage for a specific consumer.
|
||||
|
|
||||
|This endpoint returns the current state of API rate limits across all time periods (per second, per minute, per hour, per day, per week, per month).
|
||||
|
|
||||
|**Response Structure:**
|
||||
|The response always contains a consistent structure with all six time periods, regardless of whether rate limits are configured or active.
|
||||
|
|
||||
|Each time period contains:
|
||||
|- `calls_made`: Number of API calls made in the current period (null if no data available)
|
||||
|- `reset_in_seconds`: Seconds until the counter resets (null if no data available)
|
||||
|- `status`: Current state of the rate limit for this period
|
||||
|
|
||||
|**Status Values:**
|
||||
|- `ACTIVE`: Rate limit counter is active and tracking calls. Both `calls_made` and `reset_in_seconds` will have numeric values.
|
||||
|- `UNKNOWN`: Data is not available. This could mean the rate limit period has expired, no rate limit is configured, or the data cannot be retrieved. Both `calls_made` and `reset_in_seconds` will be null.
|
||||
|
|
||||
|${userAuthenticationMessage(true)}
|
||||
|
|
||||
|""".stripMargin,
|
||||
|
||||
@ -402,33 +402,26 @@ object JSONFactory600 extends CustomJsonFormats with MdcLoggable {
|
||||
|
||||
def createCurrentUsageJson(
|
||||
rateLimits: List[((Option[Long], Option[Long]), LimitCallPeriod)]
|
||||
): Option[RedisCallLimitJsonV600] = {
|
||||
if (rateLimits.isEmpty) None
|
||||
else {
|
||||
val grouped: Map[LimitCallPeriod, (Option[Long], Option[Long])] =
|
||||
rateLimits.map { case (limits, period) => period -> limits }.toMap
|
||||
): RedisCallLimitJsonV600 = {
|
||||
val grouped: Map[LimitCallPeriod, (Option[Long], Option[Long])] =
|
||||
rateLimits.map { case (limits, period) => period -> limits }.toMap
|
||||
|
||||
def getInfo(period: RateLimitingPeriod.Value): Option[RateLimitV600] =
|
||||
grouped.get(period) match {
|
||||
case Some((Some(calls), Some(ttl))) =>
|
||||
Some(RateLimitV600(Some(calls), Some(ttl), "ACTIVE"))
|
||||
case Some((None, None)) =>
|
||||
Some(RateLimitV600(None, None, "EXPIRED"))
|
||||
case _ =>
|
||||
Some(RateLimitV600(None, None, "NO_DATA"))
|
||||
def getInfo(period: RateLimitingPeriod.Value): RateLimitV600 =
|
||||
grouped.get(period) match {
|
||||
case Some((Some(calls), Some(ttl))) =>
|
||||
RateLimitV600(Some(calls), Some(ttl), "ACTIVE")
|
||||
case _ =>
|
||||
RateLimitV600(None, None, "UNKNOWN")
|
||||
}
|
||||
|
||||
Some(
|
||||
RedisCallLimitJsonV600(
|
||||
getInfo(RateLimitingPeriod.PER_SECOND),
|
||||
getInfo(RateLimitingPeriod.PER_MINUTE),
|
||||
getInfo(RateLimitingPeriod.PER_HOUR),
|
||||
getInfo(RateLimitingPeriod.PER_DAY),
|
||||
getInfo(RateLimitingPeriod.PER_WEEK),
|
||||
getInfo(RateLimitingPeriod.PER_MONTH)
|
||||
)
|
||||
)
|
||||
}
|
||||
RedisCallLimitJsonV600(
|
||||
Some(getInfo(RateLimitingPeriod.PER_SECOND)),
|
||||
Some(getInfo(RateLimitingPeriod.PER_MINUTE)),
|
||||
Some(getInfo(RateLimitingPeriod.PER_HOUR)),
|
||||
Some(getInfo(RateLimitingPeriod.PER_DAY)),
|
||||
Some(getInfo(RateLimitingPeriod.PER_WEEK)),
|
||||
Some(getInfo(RateLimitingPeriod.PER_MONTH))
|
||||
)
|
||||
}
|
||||
|
||||
def createUserInfoJSON(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user