From 2d26c80ec39fa19322fff1d866e3d90e421660d4 Mon Sep 17 00:00:00 2001 From: hongwei Date: Mon, 13 Nov 2023 15:39:18 +0100 Subject: [PATCH 1/3] bugfix/fixed the cacheKey for getResourceDocs-tweaked --- obp-api/src/main/scala/code/api/util/APIUtil.scala | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index 3783afd7b7..ca7ff8f1f8 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -4882,16 +4882,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ apiCollectionIdParam: Option[String], isVersion4OrHigher: Option[Boolean], isStaticResource: Option[Boolean], - ) = (requestedApiVersionString - + bankId - + tags - + partialFunctions - + locale.toString - + contentParam - + apiCollectionIdParam - + isVersion4OrHigher - + isStaticResource - ).intern() + ) = s"$requestedApiVersionString-$bankId-$tags-$partialFunctions-${locale.toString}" + + s"-$contentParam-$apiCollectionIdParam-$isVersion4OrHigher-$isStaticResource".intern() } From 2f7e1c6aa71dddedf85f78f1a4be14cd24f28f17 Mon Sep 17 00:00:00 2001 From: hongwei Date: Mon, 13 Nov 2023 15:45:09 +0100 Subject: [PATCH 2/3] bugfix/fixed the cacheKey for getResourceDocs-tweaked value --- obp-api/src/main/scala/code/api/util/APIUtil.scala | 4 ++-- obp-api/src/main/scala/code/api/v1_4_0/JSONFactory1_4_0.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index ca7ff8f1f8..c9ed2693a6 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -4882,8 +4882,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ apiCollectionIdParam: Option[String], isVersion4OrHigher: Option[Boolean], isStaticResource: Option[Boolean], - ) = s"$requestedApiVersionString-$bankId-$tags-$partialFunctions-${locale.toString}" + - s"-$contentParam-$apiCollectionIdParam-$isVersion4OrHigher-$isStaticResource".intern() + ) = s"requestedApiVersionString:$requestedApiVersionString-bankId:$bankId-tags:$tags-partialFunctions:$partialFunctions-locale:${locale.toString}" + + s"-contentParam:$contentParam-apiCollectionIdParam:$apiCollectionIdParam-isVersion4OrHigher:$isVersion4OrHigher-isStaticResource:$isStaticResource".intern() } diff --git a/obp-api/src/main/scala/code/api/v1_4_0/JSONFactory1_4_0.scala b/obp-api/src/main/scala/code/api/v1_4_0/JSONFactory1_4_0.scala index 8bebff124e..a8df0e99e4 100644 --- a/obp-api/src/main/scala/code/api/v1_4_0/JSONFactory1_4_0.scala +++ b/obp-api/src/main/scala/code/api/v1_4_0/JSONFactory1_4_0.scala @@ -597,7 +597,7 @@ object JSONFactory1_4_0 extends MdcLoggable{ val userDefinedEndpointTags = getAllEndpointTagsBox(rd.operationId).map(endpointTag =>ResourceDocTag(endpointTag.tagName)) val resourceDocWithUserDefinedEndpointTags: ResourceDoc = rd.copy(tags = userDefinedEndpointTags++ rd.tags) - val cacheKey = (resourceDocWithUserDefinedEndpointTags.operationId + locale + isVersion4OrHigher).intern() + val cacheKey = s"operationId:${resourceDocWithUserDefinedEndpointTags.operationId}-locale:$locale- isVersion4OrHigher:$isVersion4OrHigher".intern() val cacheValueFromRedis = Caching.getLocalisedResourceDocCache(cacheKey) if(cacheValueFromRedis.isDefined){ From de51b8e68d33a63652ae2029092c1c88e44dbb35 Mon Sep 17 00:00:00 2001 From: hongwei Date: Mon, 13 Nov 2023 16:46:17 +0100 Subject: [PATCH 3/3] refactor/added the locale guard for all resourceDocs endpoints --- .../ResourceDocsAPIMethods.scala | 20 ++++++++++++++++--- .../main/scala/code/api/util/APIUtil.scala | 8 ++++++++ .../scala/code/api/util/ErrorMessages.scala | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala index 5c7d30265e..3608e490ba 100644 --- a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala +++ b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala @@ -22,7 +22,7 @@ import code.api.v3_0_0.OBPAPI3_0_0 import code.api.v3_1_0.OBPAPI3_1_0 import code.api.v4_0_0.{APIMethods400, OBPAPI4_0_0} import code.apicollectionendpoint.MappedApiCollectionEndpointsProvider -import code.util.Helper.{MdcLoggable, ObpS} +import code.util.Helper.{MdcLoggable, ObpS, SILENCE_IS_GOLDEN} import com.github.dwickern.macros.NameOf.nameOf import com.openbankproject.commons.model.{BankId, ListResult, User} import com.openbankproject.commons.model.enums.ContentParam.{ALL, DYNAMIC, STATIC} @@ -396,7 +396,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth | You may filter this endpoint using the 'content' url parameter, e.g. ?content=dynamic | if set content=dynamic, only show dynamic endpoints, if content=static, only show the static endpoints. if omit this parameter, we will show all the endpoints. | - | You may need some other language resource docs, now we support i18n language tag , e.g. ?locale=zh_CN + | You may need some other language resource docs, now we support en_GB and es_ES at the moment. | | You can filter with api-collection-id, but api-collection-id can not be used with others together. If api-collection-id is used in URL, it will ignore all other parameters. | @@ -410,7 +410,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth |${getObpApiRoot}/v4.0.0$endpointBankIdPath/resource-docs/v4.0.0/obp |${getObpApiRoot}/v4.0.0$endpointBankIdPath/resource-docs/v4.0.0/obp?tags=Account,Bank |${getObpApiRoot}/v4.0.0$endpointBankIdPath/resource-docs/v4.0.0/obp?functions=getBanks,bankById - |${getObpApiRoot}/v4.0.0$endpointBankIdPath/resource-docs/v4.0.0/obp?locale=zh_CN + |${getObpApiRoot}/v4.0.0$endpointBankIdPath/resource-docs/v4.0.0/obp?locale=es_ES |${getObpApiRoot}/v4.0.0$endpointBankIdPath/resource-docs/v4.0.0/obp?content=static,dynamic,all |${getObpApiRoot}/v4.0.0$endpointBankIdPath/resource-docs/v4.0.0/obp?api-collection-id=4e866c86-60c3-4268-a221-cb0bbf1ad221 | @@ -540,6 +540,13 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth } requestedApiVersion <- NewStyle.function.tryons(s"$InvalidApiVersionString $requestedApiVersionString", 400, callContext) {ApiVersionUtils.valueOf(requestedApiVersionString)} _ <- Helper.booleanToFuture(s"$ApiVersionNotSupported $requestedApiVersionString", 400, callContext)(versionIsAllowed(requestedApiVersion)) + _ <- if (locale.isDefined) { + Helper.booleanToFuture(failMsg = s"$InvalidLocale Current Locale is ${locale.get}" intern(), cc = cc.callContext) { + APIUtil.obpLocaleValidation(locale.get) == SILENCE_IS_GOLDEN + } + } else { + Future.successful(true) + } cacheKey = APIUtil.createResourceDocCacheKey( None, requestedApiVersionString, @@ -637,6 +644,13 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth case false => anonymousAccess(cc) case true => authenticatedAccess(cc) // If set resource_docs_requires_role=true, we need check the authentication } + _ <- if (locale.isDefined) { + Helper.booleanToFuture(failMsg = s"$InvalidLocale Current Locale is ${locale.get}" intern(), cc = cc.callContext) { + APIUtil.obpLocaleValidation(locale.get) == SILENCE_IS_GOLDEN + } + } else { + Future.successful(true) + } (_, callContext) <- NewStyle.function.getBank(BankId(bankId), Option(cc)) _ <- resourceDocsRequireRole match { case false => Future() diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index c9ed2693a6..aafd682817 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -969,6 +969,14 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ } } + /** only support en_GB, es_ES at the moment, will support more later*/ + def obpLocaleValidation(value:String): String ={ + if(value.equalsIgnoreCase("es_Es")|| value.equalsIgnoreCase("en_GB")) + SILENCE_IS_GOLDEN + else + ErrorMessages.ConsumerKeyIsInvalid + } + /** only A-Z, a-z, 0-9, all allowed characters for password and max length <= 512 */ /** also support space now */ def basicPasswordValidation(value:String): String ={ diff --git a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala index 15c89a78d4..e96757dbce 100644 --- a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala +++ b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala @@ -116,6 +116,7 @@ object ErrorMessages { val InvalidHttpMethod = "OBP-10037: Incorrect http_method." val InvalidHttpProtocol = "OBP-10038: Incorrect http_protocol." val ServiceIsTooBusy = "OBP-10040: The Service is too busy, please try it later." + val InvalidLocale = "OBP-10041: This locale is not supported. Only the following can be used: en_GB , es_ES." // General Sort and Paging val FilterSortDirectionError = "OBP-10023: obp_sort_direction parameter can only take two values: DESC or ASC!" // was OBP-20023