mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:37:00 +00:00
refactor/Tweak Call Context variable names
This commit is contained in:
parent
cc763e4ba0
commit
8d183b823d
@ -457,9 +457,9 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
|
||||
case (Some(x), true) =>
|
||||
CustomResponseHeaders(
|
||||
List(
|
||||
("X-Rate-Limit-Reset", x.`X-Rate-Limit-Reset`.toString),
|
||||
("X-Rate-Limit-Remaining", x.`X-Rate-Limit-Remaining`.toString),
|
||||
("X-Rate-Limit-Limit", x.`X-Rate-Limit-Limit`.toString)
|
||||
("X-Rate-Limit-Reset", x.xRateLimitReset.toString),
|
||||
("X-Rate-Limit-Remaining", x.xRateLimitRemaining.toString),
|
||||
("X-Rate-Limit-Limit", x.xRateLimitLimit.toString)
|
||||
)
|
||||
)
|
||||
case _ =>
|
||||
@ -468,9 +468,9 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
|
||||
}
|
||||
private def getPaginationHeadersNewStyle(cc: Option[CallContextLight]) = {
|
||||
cc match {
|
||||
case Some(x) if x.`Pagination-Limit`.isDefined && x.`Pagination-Offset`.isDefined =>
|
||||
case Some(x) if x.paginationLimit.isDefined && x.paginationOffset.isDefined =>
|
||||
CustomResponseHeaders(
|
||||
List(("Range", s"items=${x.`Pagination-Offset`.getOrElse("")}-${x.`Pagination-Limit`.getOrElse("")}"))
|
||||
List(("Range", s"items=${x.paginationOffset.getOrElse("")}-${x.paginationLimit.getOrElse("")}"))
|
||||
)
|
||||
case _ =>
|
||||
CustomResponseHeaders(Nil)
|
||||
@ -1058,7 +1058,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
|
||||
} map { unboxFull(_) } map { i =>
|
||||
val limit: Option[String] = i.collectFirst { case OBPLimit(value) => value.toString }
|
||||
val offset: Option[String] = i.collectFirst { case OBPOffset(value) => value.toString }
|
||||
(i, callContext.map(_.copy(`Pagination-Offset` = offset, `Pagination-Limit` = limit)))
|
||||
(i, callContext.map(_.copy(paginationOffset = offset, paginationLimit = limit)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,35 +24,35 @@ import net.liftweb.util.Helpers.tryo
|
||||
import scala.collection.immutable.List
|
||||
|
||||
case class CallContext(
|
||||
gatewayLoginRequestPayload: Option[PayloadOfJwtJSON] = None, //Never update these values inside the case class !!!
|
||||
gatewayLoginResponseHeader: Option[String] = None,
|
||||
dauthRequestPayload: Option[JSONFactoryDAuth.PayloadOfJwtJSON] = None, //Never update these values inside the case class !!!
|
||||
dauthResponseHeader: Option[String] = None,
|
||||
spelling: Option[String] = None,
|
||||
user: Box[User] = Empty,
|
||||
consumer: Box[Consumer] = Empty,
|
||||
ipAddress: String = "",
|
||||
resourceDocument: Option[ResourceDoc] = None,
|
||||
startTime: Option[Date] = Some(Helpers.now),
|
||||
endTime: Option[Date] = None,
|
||||
correlationId: String = "",
|
||||
sessionId: Option[String] = None, //Only this value must be used for cache key !!!
|
||||
url: String = "",
|
||||
verb: String = "",
|
||||
implementedInVersion: String = "",
|
||||
operationId: Option[String] = None, // Dynamic Endpoint Unique Identifier. Important for Rate Limiting.
|
||||
authReqHeaderField: Box[String] = Empty,
|
||||
directLoginParams: Map[String, String] = Map(),
|
||||
oAuthParams: Map[String, String] = Map(),
|
||||
httpCode: Option[Int] = None,
|
||||
httpBody: Option[String] = None,
|
||||
requestHeaders: List[HTTPParam] = Nil,
|
||||
rateLimiting: Option[CallLimit] = None,
|
||||
`X-Rate-Limit-Limit` : Long = -1,
|
||||
`X-Rate-Limit-Remaining` : Long = -1,
|
||||
`X-Rate-Limit-Reset` : Long = -1,
|
||||
`Pagination-Offset` : Option[String] = None,
|
||||
`Pagination-Limit` : Option[String] = None
|
||||
gatewayLoginRequestPayload: Option[PayloadOfJwtJSON] = None, //Never update these values inside the case class !!!
|
||||
gatewayLoginResponseHeader: Option[String] = None,
|
||||
dauthRequestPayload: Option[JSONFactoryDAuth.PayloadOfJwtJSON] = None, //Never update these values inside the case class !!!
|
||||
dauthResponseHeader: Option[String] = None,
|
||||
spelling: Option[String] = None,
|
||||
user: Box[User] = Empty,
|
||||
consumer: Box[Consumer] = Empty,
|
||||
ipAddress: String = "",
|
||||
resourceDocument: Option[ResourceDoc] = None,
|
||||
startTime: Option[Date] = Some(Helpers.now),
|
||||
endTime: Option[Date] = None,
|
||||
correlationId: String = "",
|
||||
sessionId: Option[String] = None, //Only this value must be used for cache key !!!
|
||||
url: String = "",
|
||||
verb: String = "",
|
||||
implementedInVersion: String = "",
|
||||
operationId: Option[String] = None, // Dynamic Endpoint Unique Identifier. Important for Rate Limiting.
|
||||
authReqHeaderField: Box[String] = Empty,
|
||||
directLoginParams: Map[String, String] = Map(),
|
||||
oAuthParams: Map[String, String] = Map(),
|
||||
httpCode: Option[Int] = None,
|
||||
httpBody: Option[String] = None,
|
||||
requestHeaders: List[HTTPParam] = Nil,
|
||||
rateLimiting: Option[CallLimit] = None,
|
||||
xRateLimitLimit : Long = -1,
|
||||
xRateLimitRemaining : Long = -1,
|
||||
xRateLimitReset : Long = -1,
|
||||
paginationOffset : Option[String] = None,
|
||||
paginationLimit : Option[String] = None
|
||||
) extends MdcLoggable {
|
||||
|
||||
//This is only used to connect the back adapter. not useful for sandbox mode.
|
||||
@ -126,11 +126,11 @@ case class CallContext(
|
||||
partialFunctionName = this.resourceDocument.map(_.partialFunctionName).getOrElse(""),
|
||||
directLoginToken = this.directLoginParams.get("token").getOrElse(""),
|
||||
oAuthToken = this.oAuthParams.get(TokenName).getOrElse(""),
|
||||
`X-Rate-Limit-Limit` = this.`X-Rate-Limit-Limit`,
|
||||
`X-Rate-Limit-Remaining` = this.`X-Rate-Limit-Remaining`,
|
||||
`X-Rate-Limit-Reset` = this.`X-Rate-Limit-Reset`,
|
||||
`Pagination-Offset` = this.`Pagination-Offset`,
|
||||
`Pagination-Limit` = this.`Pagination-Limit`
|
||||
xRateLimitLimit = this.xRateLimitLimit,
|
||||
xRateLimitRemaining = this.xRateLimitRemaining,
|
||||
xRateLimitReset = this.xRateLimitReset,
|
||||
paginationOffset = this.paginationOffset,
|
||||
paginationLimit = this.paginationLimit
|
||||
)
|
||||
}
|
||||
|
||||
@ -198,11 +198,11 @@ case class CallContextLight(gatewayLoginRequestPayload: Option[PayloadOfJwtJSON]
|
||||
partialFunctionName: String,
|
||||
directLoginToken: String,
|
||||
oAuthToken: String,
|
||||
`X-Rate-Limit-Limit` : Long = -1,
|
||||
`X-Rate-Limit-Remaining` : Long = -1,
|
||||
`X-Rate-Limit-Reset` : Long = -1,
|
||||
`Pagination-Offset` : Option[String] = None,
|
||||
`Pagination-Limit` : Option[String] = None
|
||||
xRateLimitLimit : Long = -1,
|
||||
xRateLimitRemaining : Long = -1,
|
||||
xRateLimitReset : Long = -1,
|
||||
paginationOffset : Option[String] = None,
|
||||
paginationLimit : Option[String] = None
|
||||
)
|
||||
|
||||
trait LoginParam
|
||||
|
||||
@ -254,18 +254,18 @@ object RateLimitingUtil extends MdcLoggable {
|
||||
case PER_MONTH => c.per_month
|
||||
case PER_YEAR => -1
|
||||
}
|
||||
userAndCallContext._2.map(_.copy(`X-Rate-Limit-Limit` = limit))
|
||||
.map(_.copy(`X-Rate-Limit-Reset` = z._1))
|
||||
.map(_.copy(`X-Rate-Limit-Remaining` = limit - z._2))
|
||||
userAndCallContext._2.map(_.copy(xRateLimitLimit = limit))
|
||||
.map(_.copy(xRateLimitReset = z._1))
|
||||
.map(_.copy(xRateLimitRemaining = limit - z._2))
|
||||
}
|
||||
def setXRateLimitsAnonymous(id: String, z: (Long, Long), period: LimitCallPeriod): Option[CallContext] = {
|
||||
val limit = period match {
|
||||
case PER_HOUR => perHourLimitAnonymous
|
||||
case _ => -1
|
||||
}
|
||||
userAndCallContext._2.map(_.copy(`X-Rate-Limit-Limit` = limit))
|
||||
.map(_.copy(`X-Rate-Limit-Reset` = z._1))
|
||||
.map(_.copy(`X-Rate-Limit-Remaining` = limit - z._2))
|
||||
userAndCallContext._2.map(_.copy(xRateLimitLimit = limit))
|
||||
.map(_.copy(xRateLimitReset = z._1))
|
||||
.map(_.copy(xRateLimitRemaining = limit - z._2))
|
||||
}
|
||||
|
||||
def exceededRateLimit(c: CallLimit, period: LimitCallPeriod): Option[CallContextLight] = {
|
||||
@ -279,9 +279,9 @@ object RateLimitingUtil extends MdcLoggable {
|
||||
case PER_MONTH => c.per_month
|
||||
case PER_YEAR => -1
|
||||
}
|
||||
userAndCallContext._2.map(_.copy(`X-Rate-Limit-Limit` = limit))
|
||||
.map(_.copy(`X-Rate-Limit-Reset` = remain))
|
||||
.map(_.copy(`X-Rate-Limit-Remaining` = 0)).map(_.toLight)
|
||||
userAndCallContext._2.map(_.copy(xRateLimitLimit = limit))
|
||||
.map(_.copy(xRateLimitReset = remain))
|
||||
.map(_.copy(xRateLimitRemaining = 0)).map(_.toLight)
|
||||
}
|
||||
|
||||
def exceededRateLimitAnonymous(id: String, period: LimitCallPeriod): Option[CallContextLight] = {
|
||||
@ -290,9 +290,9 @@ object RateLimitingUtil extends MdcLoggable {
|
||||
case PER_HOUR => perHourLimitAnonymous
|
||||
case _ => -1
|
||||
}
|
||||
userAndCallContext._2.map(_.copy(`X-Rate-Limit-Limit` = limit))
|
||||
.map(_.copy(`X-Rate-Limit-Reset` = remain))
|
||||
.map(_.copy(`X-Rate-Limit-Remaining` = 0)).map(_.toLight)
|
||||
userAndCallContext._2.map(_.copy(xRateLimitLimit = limit))
|
||||
.map(_.copy(xRateLimitReset = remain))
|
||||
.map(_.copy(xRateLimitRemaining = 0)).map(_.toLight)
|
||||
}
|
||||
|
||||
userAndCallContext._2 match {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user