use of com.azure.core.exception.ResourceNotFoundException 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();
}
use of com.azure.core.exception.ResourceNotFoundException in project tessera by ConsenSys.
the class AzureKeyVaultServiceTest method getSecretThrowsExceptionIfKeyNotFoundInVault.
@Test
public void getSecretThrowsExceptionIfKeyNotFoundInVault() {
final String secretName = "secret-name";
final String secretVersion = "secret-version";
final Map<String, String> getSecretData = Map.of(AzureKeyVaultService.SECRET_NAME_KEY, secretName, AzureKeyVaultService.SECRET_VERSION_KEY, secretVersion);
final ResourceNotFoundException toThrow = new ResourceNotFoundException("oh no", mock(HttpResponse.class));
when(secretClient.getSecret(anyString(), anyString())).thenThrow(toThrow);
when(secretClient.getVaultUrl()).thenReturn("vault-url");
final Throwable ex = catchThrowable(() -> keyVaultService.getSecret(getSecretData));
assertThat(ex).isExactlyInstanceOf(VaultSecretNotFoundException.class);
assertThat(ex).hasMessage("Azure Key Vault secret secret-name was not found in vault vault-url");
verify(secretClient).getSecret("secret-name", "secret-version");
}
use of com.azure.core.exception.ResourceNotFoundException in project azure-keyvault-plugin by jenkinsci.
the class AzureKeyVaultSecretSource method reveal.
@Override
public Optional<String> reveal(String secret) {
AzureKeyVaultGlobalConfiguration azureKeyVaultGlobalConfiguration = GlobalConfiguration.all().get(AzureKeyVaultGlobalConfiguration.class);
if (azureKeyVaultGlobalConfiguration == null) {
LOGGER.info("No AzureKeyVault url found, skipping jcasc secret resolution");
return Optional.empty();
}
String credentialID = azureKeyVaultGlobalConfiguration.getCredentialID();
TokenCredential keyVaultCredentials = AzureCredentials.getSystemCredentialById(credentialID);
if (keyVaultCredentials == null) {
LOGGER.info("No AzureKeyVault credentials found, skipping jcasc secret resolution");
return Optional.empty();
}
SecretClient client = SecretClientCache.get(credentialID, azureKeyVaultGlobalConfiguration.getKeyVaultURL());
try {
KeyVaultSecret secretBundle = client.getSecret(secret);
return Optional.of(secretBundle.getValue());
} catch (ResourceNotFoundException ignored) {
LOGGER.info("Couldn't find secret: " + secret);
return Optional.empty();
}
}
Aggregations