Skip to content

Commit

Permalink
feat: scrts manager refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sr4850 committed Jun 13, 2024
1 parent d700ac6 commit 561ca6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<artifactId>vol-api-calls</artifactId>
<version>2.4.1-SNAPSHOT</version>




<properties>
<active-support.version>2.2.1</active-support.version>
Expand All @@ -19,7 +17,7 @@
<maven.compiler.version>3.8.1</maven.compiler.version>
<github.url>https://maven.pkg.github.com/dvsa/vol-api-calls</github.url>
<aws-java-sdk-s3.version>1.12.610</aws-java-sdk-s3.version>
<aws-secrets-manager.version>1.12.610</aws-secrets-manager>
<aws-secrets-manager.version>1.12.610</aws-secrets-manager.version>
</properties>

<profiles>
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/apiCalls/Utils/generic/BaseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/apiCalls/eupaActions/BaseAPI.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,13 +19,13 @@
public abstract class BaseAPI {

private static final Map<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> map = new HashMap<>();
Expand Down

0 comments on commit 561ca6d

Please sign in to comment.