Skip to content

Commit

Permalink
Merge pull request #2253 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Metric regarding Request Timeout
  • Loading branch information
simonredfern committed Aug 25, 2023
2 parents 3d9e7d0 + 9456178 commit fa38f30
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import code.api.util.APIUtil._
import code.api.util.ApiTag
import code.api.util.ApiTag._
import code.api.util.ErrorMessages._
import code.api.util.FutureUtil.EndpointContext
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.ExecutionContext.Implicits.global
import net.liftweb.common.Full
Expand Down Expand Up @@ -98,7 +99,7 @@ object APIMethods_EventNotificationApi extends RestHelper {

lazy val eventNotificationsPost : OBPEndpoint = {
case "event-notifications" :: Nil JsonPost _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc, UserNotLoggedIn)
} yield {
Expand Down
96 changes: 49 additions & 47 deletions obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._
import code.api.util.APIUtil._
import code.api.util.ApiTag._
import code.api.util.ErrorMessages._
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util.{ErrorMessages, NewStyle}
import code.bankconnectors.Connector
Expand Down Expand Up @@ -45,6 +46,7 @@ trait APIMethods130 {
lazy val getCards : OBPEndpoint = {
case "cards" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(cards,callContext) <- NewStyle.function.getPhysicalCardsForUser(u, callContext)
Expand Down
4 changes: 3 additions & 1 deletion obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package code.api.v1_4_0

import code.api.util.ApiRole._
import code.api.util.ApiTag._
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util._
import code.api.v1_4_0.JSONFactory1_4_0._
Expand Down Expand Up @@ -148,6 +149,7 @@ trait APIMethods140 extends MdcLoggable with APIMethods130 with APIMethods121{
lazy val addCustomerMessage : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "customer" :: customerId :: "messages" :: Nil JsonPost json -> _ => {
cc =>{
implicit val ec = EndpointContext(Some(cc))
for {
(Full(user), callContext) <- authenticatedAccess(cc)
failMsg = s"$InvalidJsonFormat The Json body should be the $AddCustomerMessageJson "
Expand Down Expand Up @@ -414,7 +416,7 @@ trait APIMethods140 extends MdcLoggable with APIMethods130 with APIMethods121{
lazy val getTransactionRequestTypes: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" ::
Nil JsonGet _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.isEnabledTransactionRequests(callContext)
Expand Down
33 changes: 22 additions & 11 deletions obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package code.api.v2_0_0

import java.util.{Calendar, Date}

import code.api.Constant._
import code.TransactionTypes.TransactionType
import code.api.{APIFailure, APIFailureNewStyle}
Expand All @@ -9,6 +10,7 @@ import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._
import code.api.util.APIUtil._
import code.api.util.ApiTag._
import code.api.util.ErrorMessages.UserNotLoggedIn
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util._
import code.api.v1_2_1.OBPAPI1_2_1._
Expand Down Expand Up @@ -232,7 +234,7 @@ trait APIMethods200 {
lazy val publicAccountsAllBanks : OBPEndpoint = {
//get public accounts for all banks
case "accounts" :: "public" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(publicViews, publicAccountAccess) <- Future(Views.views.vend.publicViews)
publicAccountsJson <- NewStyle.function.tryons(CannotGetAccounts, 400, Some(cc)){
Expand Down Expand Up @@ -273,7 +275,7 @@ trait APIMethods200 {
lazy val getPrivateAccountsAtOneBank : OBPEndpoint = {

case "banks" :: BankId(bankId) :: "accounts" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for{
(Full(u), callContext) <- authenticatedAccess(cc)
(bank, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand Down Expand Up @@ -320,7 +322,7 @@ trait APIMethods200 {
lazy val corePrivateAccountsAtOneBank : OBPEndpoint = {
// get private accounts for a single bank
case "my" :: "banks" :: BankId(bankId) :: "accounts" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(bank, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand All @@ -333,7 +335,7 @@ trait APIMethods200 {
}
// Also we support accounts/private to maintain compatibility with 1.4.0
case "my" :: "banks" :: BankId(bankId) :: "accounts" :: "private" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(bank, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand All @@ -346,7 +348,7 @@ trait APIMethods200 {
}
// Supports idea of default bank
case "bank" :: "accounts" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(bank, callContext) <- NewStyle.function.getBank(BankId(defaultBankId), callContext)
Expand Down Expand Up @@ -387,7 +389,7 @@ trait APIMethods200 {
lazy val privateAccountsAtOneBank : OBPEndpoint = {
//get private accounts for a single bank
case "banks" :: BankId(bankId) :: "accounts" :: "private" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(bank, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand Down Expand Up @@ -424,7 +426,7 @@ trait APIMethods200 {
lazy val publicAccountsAtOneBank : OBPEndpoint = {
//get public accounts for a single bank
case "banks" :: BankId(bankId) :: "accounts" :: "public" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(_, callContext) <- anonymousAccess(cc)
(bank, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand Down Expand Up @@ -459,6 +461,7 @@ trait APIMethods200 {
lazy val getKycDocuments : OBPEndpoint = {
case "customers" :: customerId :: "kyc_documents" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycDocuments, callContext)
Expand Down Expand Up @@ -492,6 +495,7 @@ trait APIMethods200 {
lazy val getKycMedia : OBPEndpoint = {
case "customers" :: customerId :: "kyc_media" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycMedia, callContext)
Expand Down Expand Up @@ -525,6 +529,7 @@ trait APIMethods200 {
lazy val getKycChecks : OBPEndpoint = {
case "customers" :: customerId :: "kyc_checks" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycChecks, callContext)
Expand Down Expand Up @@ -557,6 +562,7 @@ trait APIMethods200 {
lazy val getKycStatuses : OBPEndpoint = {
case "customers" :: customerId :: "kyc_statuses" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyKycStatuses, callContext)
Expand Down Expand Up @@ -627,6 +633,7 @@ trait APIMethods200 {
case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_documents" :: documentId :: Nil JsonPut json -> _ => {
// customerNumber is duplicated in postedData. remove from that?
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycDocument, callContext)
Expand Down Expand Up @@ -676,6 +683,7 @@ trait APIMethods200 {
case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_media" :: mediaId :: Nil JsonPut json -> _ => {
// customerNumber is in url and duplicated in postedData. remove from that?
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycMedia, callContext)
Expand Down Expand Up @@ -725,6 +733,7 @@ trait APIMethods200 {
case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_check" :: checkId :: Nil JsonPut json -> _ => {
// customerNumber is in url and duplicated in postedData. remove from that?
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycCheck, callContext)
Expand Down Expand Up @@ -775,6 +784,7 @@ trait APIMethods200 {
case "banks" :: BankId(bankId) :: "customers" :: customerId :: "kyc_statuses" :: Nil JsonPut json -> _ => {
// customerNumber is in url and duplicated in postedData. remove from that?
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canAddKycStatus, callContext)
Expand Down Expand Up @@ -1006,7 +1016,7 @@ trait APIMethods200 {

lazy val getPermissionsForBankAccount : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "permissions" :: Nil JsonGet req => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(_, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand Down Expand Up @@ -1199,6 +1209,7 @@ trait APIMethods200 {
lazy val getTransactionTypes : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "transaction-types" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
// Get Transaction Types from the active provider
(_, callContext) <- getTransactionTypesIsPublic match {
Expand Down Expand Up @@ -1967,7 +1978,7 @@ trait APIMethods200 {
lazy val addEntitlement : OBPEndpoint = {
//add access for specific user to a list of views
case "users" :: userId :: "entitlements" :: Nil JsonPost json -> _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(_, callContext) <- NewStyle.function.findByUserId(userId, callContext)
Expand Down Expand Up @@ -2066,7 +2077,7 @@ trait APIMethods200 {

lazy val deleteEntitlement: OBPEndpoint = {
case "users" :: userId :: "entitlement" :: entitlementId :: Nil JsonDelete _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, canDeleteEntitlementAtAnyBank, cc.callContext)
Expand Down Expand Up @@ -2104,7 +2115,7 @@ trait APIMethods200 {

lazy val getAllEntitlements: OBPEndpoint = {
case "entitlements" :: Nil JsonGet _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, canGetEntitlementsForAnyUserAtAnyBank,callContext)
Expand Down
19 changes: 12 additions & 7 deletions obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package code.api.v2_1_0

import java.util.Date

import code.TransactionTypes.TransactionType
import code.api.util
import code.api.util.ApiTag._
import code.api.util.ErrorMessages.TransactionDisabled
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util.{APIUtil, ApiRole, ErrorMessages, NewStyle}
import code.api.v1_3_0.{JSONFactory1_3_0, _}
Expand Down Expand Up @@ -146,7 +148,7 @@ trait APIMethods210 {
lazy val getTransactionRequestTypesSupportedByBank: OBPEndpoint = {
// Get transaction request types supported by the bank
case "banks" :: BankId(bankId) :: "transaction-request-types" :: Nil JsonGet _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(_, callContext) <- getTransactionRequestTypesIsPublic match {
case false => authenticatedAccess(cc)
Expand Down Expand Up @@ -396,7 +398,7 @@ trait APIMethods210 {
lazy val createTransactionRequest: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" ::
TransactionRequestType(transactionRequestType) :: "transaction-requests" :: Nil JsonPost json -> _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.isEnabledTransactionRequests(callContext)
Expand Down Expand Up @@ -601,7 +603,7 @@ trait APIMethods210 {
lazy val answerTransactionRequestChallenge: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: ViewId(viewId) :: "transaction-request-types" ::
TransactionRequestType(transactionRequestType) :: "transaction-requests" :: TransactionRequestId(transReqId) :: "challenge" :: Nil JsonPost json -> _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
// Check we have a User
(Full(u), callContext) <- authenticatedAccess(cc)
Expand Down Expand Up @@ -748,7 +750,7 @@ trait APIMethods210 {

lazy val getRoles: OBPEndpoint = {
case "roles" :: Nil JsonGet _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
_ <- authenticatedAccess(cc)
}
Expand Down Expand Up @@ -788,7 +790,7 @@ trait APIMethods210 {

lazy val getEntitlementsByBankAndUser: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "users" :: userId :: "entitlements" :: Nil JsonGet _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(loggedInUser), callContext) <- authenticatedAccess(cc)
(_, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand Down Expand Up @@ -961,7 +963,7 @@ trait APIMethods210 {

lazy val addCardForBank: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "cards" :: Nil JsonPost json -> _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canCreateCardsForBank, callContext)
Expand Down Expand Up @@ -1045,7 +1047,7 @@ trait APIMethods210 {

lazy val getUsers: OBPEndpoint = {
case "users" :: Nil JsonGet _ => {
cc =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canGetAnyUser, callContext)
Expand Down Expand Up @@ -1095,6 +1097,7 @@ trait APIMethods210 {
lazy val createTransactionType: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "transaction-types" :: Nil JsonPut json -> _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(_, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand Down Expand Up @@ -1453,6 +1456,7 @@ trait APIMethods210 {
lazy val getCustomersForCurrentUserAtBank : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "customers" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
(_, callContext) <- NewStyle.function.getBank(bankId, callContext)
Expand Down Expand Up @@ -1675,6 +1679,7 @@ trait APIMethods210 {
lazy val getMetrics : OBPEndpoint = {
case "management" :: "metrics" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canReadMetrics, callContext)
Expand Down
Loading

0 comments on commit fa38f30

Please sign in to comment.