From 561ca6d3ce44b86f3ceb438620e3be96f684f33e Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Thu, 13 Jun 2024 10:18:06 +0100 Subject: [PATCH] feat: scrts manager refactoring --- pom.xml | 4 +--- src/main/java/apiCalls/Utils/generic/BaseAPI.java | 13 ++++++++++--- src/main/java/apiCalls/eupaActions/BaseAPI.java | 9 +++++---- .../eupaActions/internal/IrhpPermitWindowAPI.java | 3 ++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 6aaedb1..c329ac0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,8 +6,6 @@ vol-api-calls 2.4.1-SNAPSHOT - - 2.2.1 @@ -19,7 +17,7 @@ 3.8.1 https://maven.pkg.github.com/dvsa/vol-api-calls 1.12.610 - 1.12.610 + 1.12.610 diff --git a/src/main/java/apiCalls/Utils/generic/BaseAPI.java b/src/main/java/apiCalls/Utils/generic/BaseAPI.java index 3c14b97..90f477b 100644 --- a/src/main/java/apiCalls/Utils/generic/BaseAPI.java +++ b/src/main/java/apiCalls/Utils/generic/BaseAPI.java @@ -11,11 +11,18 @@ public class BaseAPI extends Token { protected static EnvironmentType env = EnvironmentType.getEnum(Properties.get("env", true)); + protected SecretsManager secrets; + + + public BaseAPI() { + secrets= new SecretsManager(); + } + static Headers headers = new Headers(); - SecretsManager secretsManagerClient = new SecretsManager(); + public synchronized String adminJWT() throws HttpException { - String adminUser =secretsManagerClient.getSecret("adminUser"); - String adminPassword = secretsManagerClient.getSecret("adminPassword"); + String adminUser =secrets.getSecret("adminUser"); + String adminPassword = secrets.getSecret("adminPassword"); if(getAdminToken() == null){ generateAdminToken(adminUser, adminPassword); } diff --git a/src/main/java/apiCalls/eupaActions/BaseAPI.java b/src/main/java/apiCalls/eupaActions/BaseAPI.java index 9e239a3..f9b6778 100644 --- a/src/main/java/apiCalls/eupaActions/BaseAPI.java +++ b/src/main/java/apiCalls/eupaActions/BaseAPI.java @@ -1,6 +1,7 @@ package apiCalls.eupaActions; import activesupport.system.Properties; +import apiCalls.Utils.generic.SecretsManager; import apiCalls.Utils.generic.Utils; import apiCalls.actions.Token; import apiCalls.enums.UserRoles; @@ -18,13 +19,13 @@ public abstract class BaseAPI { private static final Map headers = new HashMap<>(); - + protected static SecretsManager secrets; static { - SecretsManagerClient secrets = new SecretsManagerClient(); - Token token = new Token(client); + secrets = new SecretsManager(); + Token token = new Token(); URL.build(EnvironmentType.getEnum(Properties.get("env", true))); try { - setHeader( "Authorization", "Bearer " + token.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + setHeader( "Authorization", "Bearer " + token.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); } catch (HttpException e) { throw new RuntimeException(e); } diff --git a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java index 865cfae..358e371 100644 --- a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java +++ b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java @@ -4,6 +4,7 @@ import activesupport.system.Properties; import apiCalls.Utils.eupaBuilders.internal.irhp.permit.stock.OpenByCountryModel; import apiCalls.Utils.generic.Headers; +import apiCalls.Utils.generic.SecretsManager; import apiCalls.Utils.generic.Utils; import apiCalls.actions.Token; import apiCalls.enums.UserRoles; @@ -25,7 +26,7 @@ public class IrhpPermitWindowAPI { public static OpenByCountryModel openByCountry(String[] countryIds) throws HttpException { Token accessToken = new Token(); - apiHeaders.apiHeader.put( "Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + apiHeaders.apiHeader.put( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); String openCountries = URL.build(env,"irhp-permit-window/open-by-country").toString(); Map map = new HashMap<>();