mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:17:09 +00:00
Rate Limiting - added date range
This commit is contained in:
parent
ddabd8620d
commit
44250bb54e
@ -3011,6 +3011,8 @@ object SwaggerDefinitionsJSON {
|
||||
)
|
||||
|
||||
val callLimitPostJson = CallLimitPostJson(
|
||||
from_date = DateWithDayExampleObject,
|
||||
to_date = DateWithDayExampleObject,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "-1",
|
||||
@ -3031,6 +3033,8 @@ object SwaggerDefinitionsJSON {
|
||||
)
|
||||
|
||||
val callLimitJson = CallLimitJson(
|
||||
None,
|
||||
None,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "-1",
|
||||
|
||||
@ -613,6 +613,8 @@ trait APIMethods310 {
|
||||
_ <- NewStyle.function.getConsumerByConsumerId(consumerId, callContext)
|
||||
rateLimiting <- RateLimitingDI.rateLimiting.vend.createOrUpdateConsumerCallLimits(
|
||||
consumerId,
|
||||
postJson.from_date,
|
||||
postJson.to_date,
|
||||
Some(postJson.per_second_call_limit),
|
||||
Some(postJson.per_minute_call_limit),
|
||||
Some(postJson.per_hour_call_limit),
|
||||
@ -665,7 +667,7 @@ trait APIMethods310 {
|
||||
(Full(u), callContext) <- authorizedAccess(cc)
|
||||
_ <- NewStyle.function.hasEntitlement("", u.userId, canReadCallLimits, callContext)
|
||||
consumer <- NewStyle.function.getConsumerByConsumerId(consumerId, callContext)
|
||||
rateLimit <- Future(RateLimitingUtil.consumerRateLimitState(consumer.key.get).toList)
|
||||
rateLimit <- Future(RateLimitingUtil.consumerRateLimitState(consumer.consumerId.get).toList)
|
||||
} yield {
|
||||
(createCallLimitJson(consumer, rateLimit), HttpCode.`200`(callContext))
|
||||
}
|
||||
|
||||
@ -111,6 +111,8 @@ case class BadLoginStatusJson(
|
||||
)
|
||||
|
||||
case class CallLimitPostJson(
|
||||
from_date : Date,
|
||||
to_date : Date,
|
||||
per_second_call_limit : String,
|
||||
per_minute_call_limit : String,
|
||||
per_hour_call_limit : String,
|
||||
@ -128,6 +130,8 @@ case class RedisCallLimitJson(
|
||||
per_month : Option[RateLimit]
|
||||
)
|
||||
case class CallLimitJson(
|
||||
from_date : Option[Date],
|
||||
to_date : Option[Date],
|
||||
per_second_call_limit : String,
|
||||
per_minute_call_limit : String,
|
||||
per_hour_call_limit : String,
|
||||
@ -775,6 +779,8 @@ object JSONFactory310{
|
||||
}
|
||||
|
||||
CallLimitJson(
|
||||
None,
|
||||
None,
|
||||
consumer.perSecondCallLimit.get.toString,
|
||||
consumer.perMinuteCallLimit.get.toString,
|
||||
consumer.perHourCallLimit.get.toString,
|
||||
@ -787,6 +793,8 @@ object JSONFactory310{
|
||||
}
|
||||
def createCallsLimitJson(rateLimiting: ratelimiting.RateLimiting) : CallLimitJson = {
|
||||
CallLimitJson(
|
||||
Some(rateLimiting.fromDate),
|
||||
Some(rateLimiting.toDate),
|
||||
rateLimiting.perSecondCallLimit.toString,
|
||||
rateLimiting.perMinuteCallLimit.toString,
|
||||
rateLimiting.perHourCallLimit.toString,
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package code.ratelimiting
|
||||
|
||||
import java.util.Date
|
||||
|
||||
import code.util.{MappedUUID, UUIDString}
|
||||
import net.liftweb.common.{Box, Full}
|
||||
import net.liftweb.mapper._
|
||||
@ -19,6 +21,8 @@ object MappedRateLimitingProvider extends RateLimitingProviderTrait {
|
||||
)
|
||||
}
|
||||
def createOrUpdateConsumerCallLimits(consumerId: String,
|
||||
fromDate: Date,
|
||||
toDate: Date,
|
||||
perSecond: Option[String],
|
||||
perMinute: Option[String],
|
||||
perHour: Option[String],
|
||||
@ -28,6 +32,8 @@ object MappedRateLimitingProvider extends RateLimitingProviderTrait {
|
||||
|
||||
def createRateLimit(c: RateLimiting): Box[RateLimiting] = {
|
||||
tryo {
|
||||
c.FromDate(fromDate)
|
||||
c.ToDate(toDate)
|
||||
perSecond match {
|
||||
case Some(v) => c.PerSecondCallLimit(v.toLong)
|
||||
case None =>
|
||||
@ -98,6 +104,8 @@ class RateLimiting extends RateLimitingTrait with LongKeyedMapper[RateLimiting]
|
||||
object PerMonthCallLimit extends MappedLong(this) {
|
||||
override def defaultValue = -1
|
||||
}
|
||||
object FromDate extends MappedDateTime(this)
|
||||
object ToDate extends MappedDateTime(this)
|
||||
|
||||
def rateLimitingId: String = RateLimitingId.get
|
||||
def apiName: String = ApiName.get
|
||||
@ -110,6 +118,8 @@ class RateLimiting extends RateLimitingTrait with LongKeyedMapper[RateLimiting]
|
||||
def perDayCallLimit: Long = PerDayCallLimit.get
|
||||
def perWeekCallLimit: Long = PerWeekCallLimit.get
|
||||
def perMonthCallLimit: Long = PerMonthCallLimit.get
|
||||
def fromDate: Date = FromDate.get
|
||||
def toDate: Date = ToDate.get
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package code.ratelimiting
|
||||
|
||||
import java.util.Date
|
||||
|
||||
import code.api.util.APIUtil
|
||||
import net.liftweb.util.SimpleInjector
|
||||
import code.remotedata.RemotedataRateLimiting
|
||||
@ -19,6 +21,8 @@ trait RateLimitingProviderTrait {
|
||||
def getAll(): Future[List[RateLimiting]]
|
||||
def getByConsumerId(consumerId: String): Future[Box[RateLimiting]]
|
||||
def createOrUpdateConsumerCallLimits(consumerId: String,
|
||||
fromDate: Date,
|
||||
toDate: Date,
|
||||
perSecond: Option[String],
|
||||
perMinute: Option[String],
|
||||
perHour: Option[String],
|
||||
@ -39,6 +43,8 @@ trait RateLimitingTrait {
|
||||
def perDayCallLimit: Long
|
||||
def perWeekCallLimit: Long
|
||||
def perMonthCallLimit: Long
|
||||
def fromDate: Date
|
||||
def toDate: Date
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +52,8 @@ class RemotedataRateLimitingCaseClasses {
|
||||
case class getAll()
|
||||
case class getByConsumerId(consumerId: String)
|
||||
case class createOrUpdateConsumerCallLimits(consumerId: String,
|
||||
from_date: Date,
|
||||
to_date: Date,
|
||||
perSecond: Option[String],
|
||||
perMinute: Option[String],
|
||||
perHour: Option[String],
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package code.remotedata
|
||||
|
||||
import java.util.Date
|
||||
|
||||
import akka.pattern.ask
|
||||
import code.actorsystem.ObpActorInit
|
||||
import code.ratelimiting.{RateLimiting, RateLimitingProviderTrait, RemotedataRateLimitingCaseClasses}
|
||||
@ -22,13 +24,15 @@ object RemotedataRateLimiting extends ObpActorInit with RateLimitingProviderTrai
|
||||
}
|
||||
|
||||
def createOrUpdateConsumerCallLimits(id: String,
|
||||
from_date: Date,
|
||||
to_date: Date,
|
||||
perSecond: Option[String],
|
||||
perMinute: Option[String],
|
||||
perHour: Option[String],
|
||||
perDay: Option[String],
|
||||
perWeek: Option[String],
|
||||
perMonth: Option[String]): Future[Box[RateLimiting]] =
|
||||
(actor ? cc.createOrUpdateConsumerCallLimits(id, perSecond, perMinute, perHour, perDay, perWeek, perMonth)).mapTo[Box[RateLimiting]]
|
||||
(actor ? cc.createOrUpdateConsumerCallLimits(id, from_date, to_date, perSecond, perMinute, perHour, perDay, perWeek, perMonth)).mapTo[Box[RateLimiting]]
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package code.remotedata
|
||||
|
||||
import java.util.Date
|
||||
|
||||
import akka.actor.Actor
|
||||
import akka.pattern.pipe
|
||||
import code.actorsystem.ObpActorHelper
|
||||
@ -23,9 +25,9 @@ class RemotedataRateLimitingActor extends Actor with ObpActorHelper with MdcLogg
|
||||
logger.debug("getByConsumerId(" + consumerId + ")")
|
||||
mapper.getByConsumerId(consumerId) pipeTo sender
|
||||
|
||||
case cc.createOrUpdateConsumerCallLimits(id: String, perSecond: Option[String], perMinute: Option[String], perHour: Option[String], perDay: Option[String], perWeek: Option[String], perMonth: Option[String]) =>
|
||||
logger.debug("createOrUpdateConsumerCallLimits(" + id + ", " + perSecond.getOrElse("None")+ ", " + perMinute.getOrElse("None") + ", " + perHour.getOrElse("None") + ", " + perDay.getOrElse("None") + ", " + perWeek.getOrElse("None") + ", " + perMonth.getOrElse("None") + ")")
|
||||
mapper.createOrUpdateConsumerCallLimits(id, perSecond, perMinute, perHour, perDay, perWeek, perMonth) pipeTo sender
|
||||
case cc.createOrUpdateConsumerCallLimits(id: String, fromDate: Date, toDate: Date,perSecond: Option[String], perMinute: Option[String], perHour: Option[String], perDay: Option[String], perWeek: Option[String], perMonth: Option[String]) =>
|
||||
logger.debug("createOrUpdateConsumerCallLimits(" + id + ", " + fromDate+ ", " + toDate + ", " + perSecond.getOrElse("None") + ", " + perMinute.getOrElse("None") + ", " + perHour.getOrElse("None") + ", " + perDay.getOrElse("None") + ", " + perWeek.getOrElse("None") + ", " + perMonth.getOrElse("None") + ")")
|
||||
mapper.createOrUpdateConsumerCallLimits(id, fromDate, toDate, perSecond, perMinute, perHour, perDay, perWeek, perMonth) pipeTo sender
|
||||
|
||||
case message => logger.warn("[AKKA ACTOR ERROR - REQUEST NOT RECOGNIZED] " + message)
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ TESOBE (http://www.tesobe.com/)
|
||||
package code.api.v3_1_0
|
||||
|
||||
import code.api.ErrorMessage
|
||||
import code.api.util.APIUtil.DateWithDayFormat
|
||||
import code.api.util.APIUtil.OAuth._
|
||||
import code.api.util.ApiRole.{CanReadCallLimits, CanSetCallLimits}
|
||||
import code.api.util.ErrorMessages.{UserHasMissingRoles, UserNotLoggedIn}
|
||||
@ -50,7 +51,12 @@ class RateLimitTest extends V310ServerSetup {
|
||||
object ApiEndpoint extends Tag(nameOf(Implementations3_1_0.callsLimit))
|
||||
object ApiEndpoint2 extends Tag(nameOf(Implementations3_1_0.getCallsLimit))
|
||||
|
||||
val fromDate = DateWithDayFormat.parse("2019-09-19")
|
||||
val toDate = DateWithDayFormat.parse("2020-09-19")
|
||||
|
||||
val callLimitJson1 = CallLimitPostJson(
|
||||
fromDate,
|
||||
toDate,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "-1",
|
||||
@ -59,6 +65,8 @@ class RateLimitTest extends V310ServerSetup {
|
||||
per_month_call_limit = "-1"
|
||||
)
|
||||
val callLimitSecondJson = CallLimitPostJson(
|
||||
fromDate,
|
||||
toDate,
|
||||
per_second_call_limit = "1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "-1",
|
||||
@ -67,6 +75,8 @@ class RateLimitTest extends V310ServerSetup {
|
||||
per_month_call_limit = "-1"
|
||||
)
|
||||
val callLimitMinuteJson = CallLimitPostJson(
|
||||
fromDate,
|
||||
toDate,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "1",
|
||||
per_hour_call_limit = "-1",
|
||||
@ -75,6 +85,8 @@ class RateLimitTest extends V310ServerSetup {
|
||||
per_month_call_limit = "-1"
|
||||
)
|
||||
val callLimitHourJson = CallLimitPostJson(
|
||||
fromDate,
|
||||
toDate,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "1",
|
||||
@ -83,6 +95,8 @@ class RateLimitTest extends V310ServerSetup {
|
||||
per_month_call_limit = "-1"
|
||||
)
|
||||
val callLimitDayJson = CallLimitPostJson(
|
||||
fromDate,
|
||||
toDate,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "-1",
|
||||
@ -91,6 +105,8 @@ class RateLimitTest extends V310ServerSetup {
|
||||
per_month_call_limit = "-1"
|
||||
)
|
||||
val callLimitWeekJson = CallLimitPostJson(
|
||||
fromDate,
|
||||
toDate,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "-1",
|
||||
@ -99,6 +115,8 @@ class RateLimitTest extends V310ServerSetup {
|
||||
per_month_call_limit = "-1"
|
||||
)
|
||||
val callLimitMonthJson = CallLimitPostJson(
|
||||
fromDate,
|
||||
toDate,
|
||||
per_second_call_limit = "-1",
|
||||
per_minute_call_limit = "-1",
|
||||
per_hour_call_limit = "-1",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user