From 747e30bb8ea6434a236c140f325d2251cf85fe64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 8 Sep 2023 13:52:03 +0200 Subject: [PATCH] refactor/Reactor function isNewStyleEndpoint --- .../main/scala/code/api/OBPRestHelper.scala | 51 ++---------- .../main/scala/code/api/util/NewStyle.scala | 79 ------------------- 2 files changed, 8 insertions(+), 122 deletions(-) diff --git a/obp-api/src/main/scala/code/api/OBPRestHelper.scala b/obp-api/src/main/scala/code/api/OBPRestHelper.scala index d6aae981bf..7b8bab6e7d 100644 --- a/obp-api/src/main/scala/code/api/OBPRestHelper.scala +++ b/obp-api/src/main/scala/code/api/OBPRestHelper.scala @@ -303,51 +303,16 @@ trait OBPRestHelper extends RestHelper with MdcLoggable { /** * Function which inspect does an Endpoint use Akka's Future in non-blocking way i.e. without using Await.result * @param rd Resource Document which contains all description of an Endpoint - * @return true if some endpoint can get User from Authorization Header + * @return true if some endpoint is written as a new style one */ - def newStyleEndpoints(rd: Option[ResourceDoc]) : Boolean = { + // TODO Remove Option type in case of Resource Doc + def isNewStyleEndpoint(rd: Option[ResourceDoc]) : Boolean = { rd match { - // Versions that precede the 3.0.0 are mostly written as Old Style endpoint. - // In this case we assume all are written as Old Style and explicitly list NewStyle endpoints. - case Some(e) if NewStyle.endpoints.exists(_ == (e.partialFunctionName, e.implementedInApiVersion.toString())) => - true - // Since the 3.0.0 we assume that endpoints are written in New Style. - // In this case we list all endpoints as New Style and explicitly exclude Old ones. - case Some(e) if APIMethods300.newStyleEndpoints.exists { - (_ == (e.partialFunctionName, e.implementedInApiVersion.toString())) - } => - true - // Since the 3.0.0 we assume that endpoints are written in New Style. - // In this case we list all endpoints as New Style and explicitly exclude Old ones. - case Some(e) if APIMethods310.newStyleEndpoints.exists { - (_ == (e.partialFunctionName, e.implementedInApiVersion.toString())) - } => - true - // Since the 3.0.0 we assume that endpoints are written in New Style. - // In this case we list all endpoints as New Style and explicitly exclude Old ones. - case Some(e) if APIMethods400.newStyleEndpoints.exists { - (_ == (e.partialFunctionName, e.implementedInApiVersion.toString())) - } => - true - // Berlin Group endpoints are written in New Style - case Some(e) if APIMethods_AccountInformationServiceAISApi.newStyleEndpoints.exists { - (_ == (e.partialFunctionName, e.implementedInApiVersion.toString())) - } => - true - case Some(e) if List( - ApiVersion.v1_2_1.toString, - ApiVersion.v1_3_0.toString, - ApiVersion.v1_4_0.toString, - ApiVersion.v2_0_0.toString, - ApiVersion.v2_1_0.toString, - ApiVersion.v2_2_0.toString, - ApiVersion.b1.toString, //apiBuilder is the old style. - ).exists(_ == e.implementedInApiVersion.toString()) => - false - case Some(e) if APIMethods300.oldStyleEndpoints.exists(_ == e.partialFunctionName) => - false - case None => //added the None resource doc endpoint is the false + case Some(e) if e.tags.exists(_ == ApiTag.apiTagOldStyle) => false + case None => + logger.error("Function isNewStyleEndpoint received empty resource doc") + true case _ => true } @@ -398,7 +363,7 @@ trait OBPRestHelper extends RestHelper with MdcLoggable { if(maybeJsonResponse.isDefined) { maybeJsonResponse - } else if(newStyleEndpoints(rd)) { + } else if(isNewStyleEndpoint(rd)) { fn(cc) } else if (APIUtil.hasConsentJWT(reqHeaders)) { val (usr, callContext) = Consent.applyRulesOldStyle(APIUtil.getConsentJWT(reqHeaders), cc) diff --git a/obp-api/src/main/scala/code/api/util/NewStyle.scala b/obp-api/src/main/scala/code/api/util/NewStyle.scala index 6d76959291..6052e476b4 100644 --- a/obp-api/src/main/scala/code/api/util/NewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/NewStyle.scala @@ -81,85 +81,6 @@ import code.views.system.AccountAccess import net.liftweb.mapper.By object NewStyle extends MdcLoggable{ - lazy val endpoints: List[(String, String)] = List( - (nameOf(ImplementationsResourceDocs.getResourceDocsObp), ApiVersion.v1_4_0.toString), - (nameOf(Implementations1_2_1.deleteWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getOtherAccountForTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getOtherAccountMetadata), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getCounterpartyPublicAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addCounterpartyMoreInfo), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateCounterpartyMoreInfo), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyMoreInfo), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addCounterpartyPublicAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addCounterpartyUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateCounterpartyUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyCorporateLocation), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyPhysicalLocation), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addCounterpartyImageUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateCounterpartyImageUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyImageUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addCounterpartyOpenCorporatesUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateCounterpartyOpenCorporatesUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyOpenCorporatesUrl), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addOtherAccountPrivateAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateCounterpartyPrivateAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyPrivateAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateCounterpartyPublicAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCounterpartyPublicAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getOtherAccountPrivateAlias), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateAccountLabel), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addImageForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteImageForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getImagesForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addTagForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteTagForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getTagsForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addCommentForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteCommentForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getCommentsForViewOnTransaction), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteTransactionNarrative), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.updateTransactionNarrative), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addTransactionNarrative), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.getTransactionNarrative), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.deleteViewForBankAccount), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_2_1.addPermissionForUserForBankAccountForOneView), ApiVersion.v1_2_1.toString), - (nameOf(Implementations1_4_0.getTransactionRequestTypes), ApiVersion.v1_4_0.toString), - (nameOf(Implementations1_4_0.addCustomerMessage), ApiVersion.v1_4_0.toString), - (nameOf(Implementations2_0_0.getAllEntitlements), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.publicAccountsAtOneBank), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.privateAccountsAtOneBank), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.corePrivateAccountsAtOneBank), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.getKycDocuments), ApiVersion.v2_0_0.toString), - (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.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), - (nameOf(Implementations2_0_0.addKycCheck), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.addEntitlement), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.deleteEntitlement), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.getTransactionTypes), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.getPermissionsForBankAccount), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_0_0.publicAccountsAllBanks), ApiVersion.v2_0_0.toString), - (nameOf(Implementations2_1_0.getEntitlementsByBankAndUser), ApiVersion.v2_1_0.toString), - (nameOf(Implementations2_1_0.getRoles), ApiVersion.v2_1_0.toString), - (nameOf(Implementations2_1_0.getCustomersForCurrentUserAtBank), ApiVersion.v2_1_0.toString), - (nameOf(Implementations2_1_0.getMetrics), ApiVersion.v2_1_0.toString), - (nameOf(Implementations2_1_0.createTransactionType), ApiVersion.v2_1_0.toString), - (nameOf(Implementations2_1_0.getTransactionRequestTypesSupportedByBank), ApiVersion.v2_1_0.toString), - (nameOf(Implementations2_2_0.config), ApiVersion.v2_2_0.toString), - (nameOf(Implementations2_2_0.getMessageDocs), ApiVersion.v2_2_0.toString), - (nameOf(Implementations2_2_0.getViewsForBankAccount), ApiVersion.v2_2_0.toString), - (nameOf(Implementations2_2_0.getCurrentFxRate), ApiVersion.v2_2_0.toString), - (nameOf(Implementations2_2_0.getExplictCounterpartiesForAccount), ApiVersion.v2_2_0.toString), - (nameOf(Implementations2_2_0.getExplictCounterpartyById), ApiVersion.v2_2_0.toString), - (nameOf(Implementations2_2_0.createAccount), ApiVersion.v2_2_0.toString) - ) object HttpCode { def `200`(callContext: Option[CallContext]): Option[CallContext] = {