mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:27:01 +00:00
commit
f3f155d507
@ -47,6 +47,8 @@ import net.liftweb.json.Extraction
|
||||
import net.liftweb.json.JsonAST.JValue
|
||||
import net.liftweb.util.Helpers
|
||||
|
||||
import scala.collection.immutable.List
|
||||
|
||||
trait APIFailure{
|
||||
val msg : String
|
||||
val responseCode : Int
|
||||
@ -202,6 +204,8 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
|
||||
ApiVersion.v2_2_0.toString
|
||||
).exists(_ == e.implementedInApiVersion.toString()) =>
|
||||
false
|
||||
case Some(e) if APIMethods300.oldStyleEndpoints.exists(_ == e.partialFunctionName) =>
|
||||
false
|
||||
case _ =>
|
||||
true
|
||||
}
|
||||
@ -209,6 +213,7 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
|
||||
|
||||
def failIfBadAuthorizationHeader(rd: Option[ResourceDoc])(fn: CallContext => Box[JsonResponse]) : JsonResponse = {
|
||||
val authorization = S.request.map(_.header("Authorization")).flatten
|
||||
val body: Box[String] = getRequestBody(S.request)
|
||||
val implementedInVersion = S.request.openOrThrowException(attemptedToOpenAnEmptyBox).view
|
||||
val verb = S.request.openOrThrowException(attemptedToOpenAnEmptyBox).requestType.method
|
||||
val url = URLDecoder.decode(S.uriAndQueryString.getOrElse(""),"UTF-8")
|
||||
@ -220,6 +225,7 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
|
||||
authReqHeaderField = authorization,
|
||||
implementedInVersion = implementedInVersion,
|
||||
verb = verb,
|
||||
httpBody = body,
|
||||
correlationId = correlationId,
|
||||
url = url,
|
||||
ipAddress = getRemoteIpAddress(),
|
||||
|
||||
@ -40,7 +40,7 @@ import code.api.builder.OBP_APIBuilder
|
||||
import code.api.oauth1a.Arithmetics
|
||||
import code.api.oauth1a.OauthParams._
|
||||
import code.api.sandbox.SandboxApiCalls
|
||||
import code.api.util.ApiTag.{ResourceDocTag, apiTagBank}
|
||||
import code.api.util.ApiTag.{ResourceDocTag, apiTagBank, apiTagNewStyle}
|
||||
import code.api.util.Glossary.GlossaryItem
|
||||
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA
|
||||
import code.api.v1_2.ErrorMessage
|
||||
@ -1462,6 +1462,12 @@ Returns a string showed to the developer
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* The POST or PUT body. This will be empty if the content
|
||||
* type is application/x-www-form-urlencoded or a multipart mime.
|
||||
* It will also be empty if rawInputStream is accessed
|
||||
*/
|
||||
def getRequestBody(req: Box[Req]) = req.flatMap(_.body).map(_.map(_.toChar)).map(_.mkString)
|
||||
/**
|
||||
* @return - the HTTP session ID
|
||||
*/
|
||||
@ -1700,7 +1706,7 @@ Returns a string showed to the developer
|
||||
// Only allow Resource Doc if it matches one of the pre selected endpoints from the version list.
|
||||
// i.e. this function may recieve more Resource Docs than version endpoints
|
||||
endpoints.exists(_ == item.partialFunction) &&
|
||||
(NewStyle.endpoints.exists(x => x == (item.partialFunctionName, item.implementedInApiVersion.toString())) || !onlyNewStyle)
|
||||
(item.tags.exists(_ == apiTagNewStyle) || !onlyNewStyle)
|
||||
)
|
||||
yield item.partialFunction
|
||||
routes.toList
|
||||
@ -1873,6 +1879,7 @@ Returns a string showed to the developer
|
||||
def getUserAndSessionContextFuture(cc: CallContext): OBPReturnType[Box[User]] = {
|
||||
val s = S
|
||||
val spelling = getSpellingParam()
|
||||
val body: Box[String] = getRequestBody(S.request)
|
||||
val implementedInVersion = S.request.openOrThrowException(attemptedToOpenAnEmptyBox).view
|
||||
val verb = S.request.openOrThrowException(attemptedToOpenAnEmptyBox).requestType.method
|
||||
val url = URLDecoder.decode(S.uriAndQueryString.getOrElse(""),"UTF-8")
|
||||
@ -1951,6 +1958,8 @@ Returns a string showed to the developer
|
||||
x => (x._1, x._2.map(_.copy(requestHeaders = reqHeaders)))
|
||||
} map {
|
||||
x => (x._1, x._2.map(_.copy(ipAddress = getRemoteIpAddress())))
|
||||
} map {
|
||||
x => (x._1, x._2.map(_.copy(httpBody = body.toOption)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ case class CallContext(
|
||||
directLoginParams: Map[String, String] = Map(),
|
||||
oAuthParams: Map[String, String] = Map(),
|
||||
httpCode: Option[Int] = None,
|
||||
httpBody: Option[String] = None,
|
||||
requestHeaders: List[HTTPParam] = Nil,
|
||||
`X-Rate-Limit-Limit` : Long = -1,
|
||||
`X-Rate-Limit-Remaining` : Long = -1,
|
||||
@ -108,6 +109,7 @@ case class CallContext(
|
||||
verb = this.verb,
|
||||
implementedInVersion = this.implementedInVersion,
|
||||
httpCode = this.httpCode,
|
||||
httpBody = this.httpBody,
|
||||
authReqHeaderField = this.authReqHeaderField.toOption,
|
||||
partialFunctionName = this.resourceDocument.map(_.partialFunctionName).getOrElse(""),
|
||||
directLoginToken = this.directLoginParams.get("token").getOrElse(""),
|
||||
@ -145,6 +147,7 @@ case class CallContextLight(gatewayLoginRequestPayload: Option[PayloadOfJwtJSON]
|
||||
verb: String = "",
|
||||
implementedInVersion: String = "",
|
||||
httpCode: Option[Int] = None,
|
||||
httpBody: Option[String] = None,
|
||||
authReqHeaderField: Option[String] = None,
|
||||
partialFunctionName: String,
|
||||
directLoginToken: String,
|
||||
|
||||
@ -51,7 +51,6 @@ object NewStyle {
|
||||
(nameOf(Implementations2_0_0.getKycMedia), ApiVersion.v2_0_0.toString),
|
||||
(nameOf(Implementations2_0_0.getKycStatuses), ApiVersion.v2_0_0.toString),
|
||||
(nameOf(Implementations2_0_0.getKycChecks), ApiVersion.v2_0_0.toString),
|
||||
(nameOf(Implementations2_0_0.getSocialMediaHandles), ApiVersion.v2_0_0.toString),
|
||||
(nameOf(Implementations2_0_0.addKycDocument), ApiVersion.v2_0_0.toString),
|
||||
(nameOf(Implementations2_0_0.addKycMedia), ApiVersion.v2_0_0.toString),
|
||||
(nameOf(Implementations2_0_0.addKycStatus), ApiVersion.v2_0_0.toString),
|
||||
|
||||
@ -2369,14 +2369,15 @@ trait APIMethods300 {
|
||||
}
|
||||
}
|
||||
object APIMethods300 extends RestHelper with APIMethods300 {
|
||||
lazy val oldStyleEndpoints = List(
|
||||
nameOf(Implementations3_0_0.createBranch),
|
||||
nameOf(Implementations3_0_0.updateBranch),
|
||||
nameOf(Implementations3_0_0.createAtm)
|
||||
)
|
||||
lazy val newStyleEndpoints: List[(String, String)] = Implementations3_0_0.resourceDocs.map {
|
||||
rd => (rd.partialFunctionName, rd.implementedInApiVersion.toString())
|
||||
}.toList.filterNot{
|
||||
rd =>
|
||||
List(
|
||||
nameOf(Implementations3_0_0.createBranch),
|
||||
nameOf(Implementations3_0_0.updateBranch),
|
||||
nameOf(Implementations3_0_0.createAtm)
|
||||
).contains(rd._1)
|
||||
rd =>
|
||||
oldStyleEndpoints.contains(rd._1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1942,7 +1942,7 @@ trait APIMethods310 {
|
||||
(_, callContext) <- anonymousAccess(cc)
|
||||
connectorVersion = APIUtil.getPropsValue("connector").openOrThrowException("connector props filed `connector` not set")
|
||||
obpApiLoopback <- connectorVersion.contains("kafka") match {
|
||||
case false => Future{ObpApiLoopback("mapped",gitCommit,"0")}
|
||||
case false => throw new IllegalStateException(s"${NotImplemented}for connector ${connectorVersion}")
|
||||
case true => KafkaHelper.echoKafkaServer.recover {
|
||||
case e: Throwable => throw new IllegalStateException(s"${KafkaServerUnavailable} Timeout error, because kafka do not return message to OBP-API. ${e.getMessage}")
|
||||
}
|
||||
|
||||
@ -9261,6 +9261,9 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
|
||||
* @tparam T
|
||||
* @return result of future
|
||||
*/
|
||||
// This result is accessed synchronously (blocking)
|
||||
// TODO 1. Consider can be the result accessed asynchronously (non-blocking)
|
||||
// TODO 2. Consider making the duration tweakable via props file at least
|
||||
private[this] implicit def convertFuture[T](future: Future[T]): T = Await.result(future, 1.minute)
|
||||
|
||||
/**
|
||||
|
||||
@ -25,7 +25,9 @@ TESOBE (http://www.tesobe.com/)
|
||||
*/
|
||||
package code.api.v3_1_0
|
||||
|
||||
import code.api.util.ApiVersion
|
||||
import code.api.ErrorMessage
|
||||
import code.api.util.ErrorMessages.NotImplemented
|
||||
import code.api.util.{APIUtil, ApiVersion, ErrorMessages}
|
||||
import code.api.v3_1_0.OBPAPI3_1_0.Implementations3_1_0
|
||||
import com.github.dwickern.macros.NameOf.nameOf
|
||||
import org.scalatest.Tag
|
||||
@ -47,9 +49,12 @@ class ObpApiLoopbackTest extends V310ServerSetup {
|
||||
When("We make a request v3.1.0")
|
||||
val request310 = (v3_1_0_Request / "connector" / "loopback").GET
|
||||
val response310 = makeGetRequest(request310)
|
||||
Then("We should get a 200")
|
||||
response310.code should equal(200)
|
||||
response310.body.extract[ObpApiLoopbackJson]
|
||||
Then("We should get a 400")
|
||||
response310.code should equal(400)
|
||||
val connectorVersion = APIUtil.getPropsValue("connector").openOrThrowException("connector props filed `connector` not set")
|
||||
val errorMessage = s"${NotImplemented}for connector ${connectorVersion}"
|
||||
And("error should be " + errorMessage)
|
||||
response310.body.extract[ErrorMessage].message should equal (errorMessage)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user