Skip to content

Commit

Permalink
chore:reference secrtsManager from active support
Browse files Browse the repository at this point in the history
  • Loading branch information
sr4850 committed Aug 7, 2024
1 parent 4231426 commit 8e46c53
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 71 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


<properties>
<active-support.version>2.4.2-SNAPSHOT</active-support.version>
<active-support.version>2.4.1</active-support.version>
<log4j.version>2.22.0</log4j.version>
<log4j12.version>2.22.0</log4j12.version>
<commons-lang3.version>3.14.0</commons-lang3.version>
Expand Down Expand Up @@ -124,5 +124,10 @@
<artifactId>ion-java</artifactId>
<version>1.11.9</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
</project>
5 changes: 3 additions & 2 deletions src/main/java/apiCalls/Utils/generic/BaseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import activesupport.http.RestUtils;
import activesupport.system.Properties;
import activesupport.aws.s3.SecretsManager;
import apiCalls.actions.Token;
import com.auth0.jwt.JWT;
import com.auth0.jwt.exceptions.JWTDecodeException;
Expand All @@ -25,8 +26,8 @@ public class BaseAPI extends Token {
static Headers headers = new Headers();

public synchronized String adminJWT() throws HttpException {
String adminUser = SecretsManager.getSecret("adminUser");
String adminPassword = SecretsManager.getSecret("adminPassword");
String adminUser = SecretsManager.getSecretValue("adminUser");
String adminPassword = SecretsManager.getSecretValue("adminPassword");

if (getAdminToken() == null || isTokenExpired(getAdminToken())) {
LOGGER.info("Generating new admin token");
Expand Down
55 changes: 0 additions & 55 deletions src/main/java/apiCalls/Utils/generic/SecretsManager.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/apiCalls/actions/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public synchronized String getToken(String username, String password, String rea
LOGGER.warning("Token creation failed, retrying... " + e.getMessage());
retryCount++;
try {
Thread.sleep((long) Math.pow(2, retryCount) * 1000); // Exponential backoff
Thread.sleep((long) Math.pow(2, retryCount) * 1000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/apiCalls/eupaActions/BaseAPI.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package apiCalls.eupaActions;

import activesupport.system.Properties;
import apiCalls.Utils.generic.SecretsManager;
import apiCalls.Utils.generic.Utils;
import activesupport.aws.s3.SecretsManager;
import apiCalls.actions.Token;
import apiCalls.enums.UserRoles;
import com.google.gson.Gson;
Expand All @@ -25,7 +24,7 @@ public abstract class BaseAPI {
Token token = new Token();
URL.build(EnvironmentType.getEnum(Properties.get("env", true)));
try {
setHeader( "Authorization", "Bearer " + token.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString()));
setHeader( "Authorization", "Bearer " + token.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString()));
} catch (HttpException e) {
throw new RuntimeException(e);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/apiCalls/eupaActions/external/UserAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package apiCalls.eupaActions.external;

import activesupport.aws.s3.SecretsManager;
import activesupport.http.RestUtils;
import activesupport.system.Properties;
import apiCalls.Utils.eupaBuilders.external.PersonModel;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class UserAPI extends BaseAPI {
*/
public static PersonModel register(@NotNull UserRegistrationDetailsModel userRegistrationDetailsModel) throws HttpException {
Token accessToken = new Token();
BaseAPI.setHeader("Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString()));
BaseAPI.setHeader("Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString()));
URL.build(EnvironmentType.getEnum(Properties.get("env", true)), baseResource + "register");
int maxTries = 5;

Expand Down Expand Up @@ -71,7 +72,7 @@ public static PersonModel register(@NotNull UserRegistrationDetailsModel userReg
* @return the information associated with the person passed in as an argument.
*/
public static UserModel get(@NotNull PersonModel personModel) {
BaseAPI.getHeaders().put("x-pid", secrets.getSecret("apiHeader"));
BaseAPI.getHeaders().put("x-pid", SecretsManager.getSecretValue("apiHeader"));
URL.build(EnvironmentType.getEnum(Properties.get("env", true)), baseResource + personModel.getUserId());

response = RestUtils.get(String.valueOf(URL.getURL()), getHeaders());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package apiCalls.eupaActions.internal;

import activesupport.aws.s3.SecretsManager;
import activesupport.http.RestUtils;
import activesupport.system.Properties;
import apiCalls.Utils.eupaBuilders.external.StandardResponseModel;
import apiCalls.Utils.eupaBuilders.internal.GrantApplicationModel;
import apiCalls.Utils.eupaBuilders.internal.OverviewModel;
import apiCalls.Utils.generic.Utils;
import apiCalls.actions.Token;
import apiCalls.enums.UserRoles;
import apiCalls.eupaActions.BaseAPI;
Expand All @@ -22,7 +22,7 @@ public class CaseWorkerAPI extends BaseAPI {
private static Token accessToken = new Token();

public static void overview(@NotNull OverviewModel overview) throws HttpException {
updateHeader("Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString()));
updateHeader("Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString()));
URL.build(EnvironmentType.getEnum(Properties.get("env", true)), String.format("application/%s/overview/", overview.getApplicationId()));
int version = 1;

Expand All @@ -43,7 +43,7 @@ public static void overview(@NotNull OverviewModel overview) throws HttpExceptio
}

public static StandardResponseModel grantApplication(@NotNull GrantApplicationModel grantApplication) throws HttpException {
updateHeader( "Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString()));
updateHeader( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString()));
URL.build(EnvironmentType.getEnum(Properties.get("env", true)), String.format("application/%s/grant/", grantApplication.getId()));

response = RestUtils.put(grantApplication, String.valueOf(URL.getURL()), getHeaders());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package apiCalls.eupaActions.internal;

import activesupport.aws.s3.SecretsManager;
import activesupport.http.RestUtils;
import activesupport.system.Properties;
import apiCalls.Utils.eupaBuilders.internal.irhp.permit.stock.AvailableCountriesModel;
Expand All @@ -19,7 +20,7 @@ public class IrhpPermitStockAPI extends BaseAPI {

public static AvailableCountriesModel availableCountries() throws HttpException {
Token accessToken = new Token();
updateHeader( "Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString()));
updateHeader( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString()));

URL.build(EnvironmentType.getEnum(Properties.get("env", true)), baseResource.concat("available-countries/?dto=Dvsa%5COlcs%5CTransfer%5CQuery%5CIrhpPermitStock%5CAvailableCountries"));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package apiCalls.eupaActions.internal;

import activesupport.aws.s3.SecretsManager;
import activesupport.http.RestUtils;
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 @@ -26,7 +26,7 @@ public class IrhpPermitWindowAPI {

public static OpenByCountryModel openByCountry(String[] countryIds) throws HttpException {
Token accessToken = new Token();
apiHeaders.getApiHeader().put( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString()));
apiHeaders.getApiHeader().put( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString()));
String openCountries = URL.build(env,"irhp-permit-window/open-by-country").toString();

Map<String, String> map = new HashMap<>();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/apiCalls/eupaActions/internal/LicenceAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package apiCalls.eupaActions.internal;

import activesupport.aws.s3.SecretsManager;
import activesupport.http.RestUtils;
import activesupport.system.Properties;
import apiCalls.Utils.generic.Utils;
Expand All @@ -19,7 +20,7 @@ public class LicenceAPI extends BaseAPI {

public static String licenceNumber(@NotNull String licenceId) throws HttpException {
Token accessToken = new Token();
updateHeader( "Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString()));
updateHeader( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString()));

String env = Properties.get("env", true);
URL.build(EnvironmentType.getEnum(env), baseResource.concat(licenceId));
Expand Down

0 comments on commit 8e46c53

Please sign in to comment.