-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from dvsa/feat-secrets-manager
fix: added secrets amanger implementation
- Loading branch information
Showing
12 changed files
with
100 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,4 @@ jobs: | |
uses: ./.github/workflows/maven.yaml | ||
with: | ||
maven-goal: package | ||
needs: security | ||
|
||
|
||
needs: security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package apiCalls.Utils.generic; | ||
|
||
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; | ||
import com.amazonaws.regions.Regions; | ||
import com.amazonaws.services.secretsmanager.AWSSecretsManager; | ||
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder; | ||
import com.amazonaws.services.secretsmanager.model.*; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.json.JSONObject; | ||
|
||
public class SecretsManager { | ||
|
||
public static String secretsId = "OLCS-DEVAPPCI-DEVCI-BATCHTESTRUNNER-MAIN-APPLICATION"; | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(SecretsManager.class); | ||
|
||
public static AWSSecretsManager awsClientSetup(){ | ||
Regions region = Regions.EU_WEST_1; | ||
return AWSSecretsManagerClientBuilder | ||
.standard() | ||
.withCredentials(new DefaultAWSCredentialsProviderChain()) | ||
.withRegion(region) | ||
.build(); | ||
} | ||
|
||
public static String getSecret(String secretKey) { | ||
String secret = null; | ||
|
||
GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest() | ||
.withSecretId(secretsId); | ||
GetSecretValueResult getSecretValueResult = null; | ||
|
||
try { | ||
getSecretValueResult = awsClientSetup().getSecretValue(getSecretValueRequest); | ||
|
||
} catch (ResourceNotFoundException e) { | ||
LOGGER.info("The requested secret " + secretKey + " was not found"); | ||
} catch (InvalidRequestException e) { | ||
LOGGER.info("The request was invalid due to: " + e.getMessage()); | ||
} catch (InvalidParameterException e) { | ||
LOGGER.info("The request had invalid params: " + e.getMessage()); | ||
} | ||
|
||
assert getSecretValueResult != null; | ||
|
||
if (getSecretValueResult != null && getSecretValueResult.getSecretString() != null) { | ||
secret = getSecretValueResult.getSecretString(); | ||
JSONObject jsonObject = new JSONObject(secret); | ||
secret = jsonObject.getString(secretKey); | ||
} | ||
return secret; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters