Search in sources :

Example 1 with VaultSecretNotFoundException

use of com.quorum.tessera.key.vault.VaultSecretNotFoundException in project tessera by ConsenSys.

the class AzureKeyVaultService method getSecret.

@Override
public String getSecret(Map<String, String> azureGetSecretData) {
    final String secretName = azureGetSecretData.get(SECRET_NAME_KEY);
    final String secretVersion = azureGetSecretData.get(SECRET_VERSION_KEY);
    final KeyVaultSecret secret;
    try {
        LOGGER.debug("SecretName : {} , SecretVersion: {}", secretName, secretVersion);
        secret = secretClient.getSecret(secretName, secretVersion);
        LOGGER.debug("secret.id {}", secret.getId());
    } catch (ResourceNotFoundException e) {
        throw new VaultSecretNotFoundException("Azure Key Vault secret " + secretName + " was not found in vault " + secretClient.getVaultUrl());
    }
    return secret.getValue();
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) VaultSecretNotFoundException(com.quorum.tessera.key.vault.VaultSecretNotFoundException) ResourceNotFoundException(com.azure.core.exception.ResourceNotFoundException)

Example 2 with VaultSecretNotFoundException

use of com.quorum.tessera.key.vault.VaultSecretNotFoundException in project tessera by ConsenSys.

the class AWSKeyVaultServiceTest method getSecretSecretManagerRerurnsNull.

@Test
public void getSecretSecretManagerRerurnsNull() {
    String secretName = "name";
    Map<String, String> getSecretData = Map.of(AWSKeyVaultService.SECRET_NAME_KEY, secretName);
    GetSecretValueResponse secretValueResponse = null;
    when(secretsManager.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResponse);
    try {
        keyVaultService.getSecret(getSecretData);
        failBecauseExceptionWasNotThrown(VaultSecretNotFoundException.class);
    } catch (VaultSecretNotFoundException vaultSecretNotFoundException) {
        verify(secretsManager).getSecretValue(any(GetSecretValueRequest.class));
        assertThat(vaultSecretNotFoundException).hasMessage("The requested secret '" + secretName + "' was not found in AWS Secrets Manager");
    }
}
Also used : GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) VaultSecretNotFoundException(com.quorum.tessera.key.vault.VaultSecretNotFoundException) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) Test(org.junit.Test)

Example 3 with VaultSecretNotFoundException

use of com.quorum.tessera.key.vault.VaultSecretNotFoundException in project tessera by ConsenSys.

the class AWSKeyVaultService method getSecret.

@Override
public String getSecret(Map<String, String> getSecretData) {
    final String secretName = getSecretData.get(SECRET_NAME_KEY);
    GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
    GetSecretValueResponse secretValueResponse;
    try {
        secretValueResponse = secretsManager.getSecretValue(getSecretValueRequest);
    } catch (ResourceNotFoundException e) {
        throw new VaultSecretNotFoundException("The requested secret '" + secretName + "' was not found in AWS Secrets Manager");
    } catch (InvalidRequestException | InvalidParameterException e) {
        throw new AWSSecretsManagerException(e);
    }
    if (secretValueResponse != null && secretValueResponse.secretString() != null) {
        return secretValueResponse.secretString();
    }
    throw new VaultSecretNotFoundException("The requested secret '" + secretName + "' was not found in AWS Secrets Manager");
}
Also used : InvalidParameterException(software.amazon.awssdk.services.secretsmanager.model.InvalidParameterException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) VaultSecretNotFoundException(com.quorum.tessera.key.vault.VaultSecretNotFoundException) InvalidRequestException(software.amazon.awssdk.services.secretsmanager.model.InvalidRequestException) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) ResourceNotFoundException(software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)

Aggregations

VaultSecretNotFoundException (com.quorum.tessera.key.vault.VaultSecretNotFoundException)3 GetSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest)2 GetSecretValueResponse (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)2 ResourceNotFoundException (com.azure.core.exception.ResourceNotFoundException)1 KeyVaultSecret (com.azure.security.keyvault.secrets.models.KeyVaultSecret)1 Test (org.junit.Test)1 InvalidParameterException (software.amazon.awssdk.services.secretsmanager.model.InvalidParameterException)1 InvalidRequestException (software.amazon.awssdk.services.secretsmanager.model.InvalidRequestException)1 ResourceNotFoundException (software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)1