Search in sources :

Example 1 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project lowkey-vault by nagyesta.

the class SecretsStepDefs method theLastVersionOfTheSecretIsPreparedForAnUpdate.

@When("the last version of the secret is prepared for an update")
public void theLastVersionOfTheSecretIsPreparedForAnUpdate() {
    final KeyVaultSecret lastResult = context.getLastResult();
    final SecretProperties updatedProperties = context.getClient(context.getSecretServiceVersion()).getSecret(lastResult.getName(), lastResult.getProperties().getVersion()).getProperties();
    context.setUpdateProperties(updatedProperties);
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) SecretProperties(com.azure.security.keyvault.secrets.models.SecretProperties) When(io.cucumber.java.en.When)

Example 2 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project lowkey-vault by nagyesta.

the class SecretsStepDefs method versionsCountVersionOfTheSecretIsCreated.

@Given("{int} version of the secret is created")
public void versionsCountVersionOfTheSecretIsCreated(final int versionsCount) {
    final KeyVaultSecret secretCreateInfo = context.getCreateSecretOptions();
    IntStream.range(0, versionsCount).forEach(i -> {
        final KeyVaultSecret secret = context.getClient(context.getSecretServiceVersion()).setSecret(secretCreateInfo);
        context.addCreatedEntity(secretCreateInfo.getName(), secret);
    });
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) Given(io.cucumber.java.en.Given)

Example 3 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project lowkey-vault by nagyesta.

the class AbstractLowkeyVaultContainerTest method verifyConnectionIsWorking.

protected void verifyConnectionIsWorking(final String vaultUrl, final HttpClient httpClient, final TokenCredential credential) {
    final SecretClient secretClient = new SecretClientBuilder().vaultUrl(vaultUrl).credential(credential).httpClient(httpClient).serviceVersion(SecretServiceVersion.V7_2).retryPolicy(new RetryPolicy(new FixedDelay(0, Duration.ZERO))).buildClient();
    final KeyVaultSecret secret = secretClient.setSecret(NAME, VALUE);
    Assertions.assertNotNull(secret);
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) SecretClientBuilder(com.azure.security.keyvault.secrets.SecretClientBuilder) FixedDelay(com.azure.core.http.policy.FixedDelay) RetryPolicy(com.azure.core.http.policy.RetryPolicy) SecretClient(com.azure.security.keyvault.secrets.SecretClient)

Example 4 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret 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 5 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project tessera by ConsenSys.

the class AzureKeyVaultServiceTest method setSecret.

@Test
public void setSecret() {
    final String secretName = "secret-name";
    final String secret = "secret-value";
    final Map<String, String> setSecretData = Map.of(AzureKeyVaultService.SECRET_NAME_KEY, secretName, AzureKeyVaultService.SECRET_KEY, secret);
    final KeyVaultSecret newSecret = mock(KeyVaultSecret.class);
    when(secretClient.setSecret(secretName, secret)).thenReturn(newSecret);
    final Object result = keyVaultService.setSecret(setSecretData);
    assertThat(result).isSameAs(newSecret);
    verify(secretClient).setSecret("secret-name", "secret-value");
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) Test(org.junit.Test)

Aggregations

KeyVaultSecret (com.azure.security.keyvault.secrets.models.KeyVaultSecret)19 Test (org.junit.Test)6 When (io.cucumber.java.en.When)5 SecretClient (com.azure.security.keyvault.secrets.SecretClient)4 FormValidation (hudson.util.FormValidation)3 Secret (hudson.util.Secret)3 ResourceNotFoundException (com.azure.core.exception.ResourceNotFoundException)2 SecretCertificateCredentials (com.microsoft.jenkins.keyvault.SecretCertificateCredentials)2 KeyStore (java.security.KeyStore)2 TokenCredential (com.azure.core.credential.TokenCredential)1 FixedDelay (com.azure.core.http.policy.FixedDelay)1 RetryPolicy (com.azure.core.http.policy.RetryPolicy)1 ClientSecretCredential (com.azure.identity.ClientSecretCredential)1 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)1 SecretClientBuilder (com.azure.security.keyvault.secrets.SecretClientBuilder)1 DeletedSecret (com.azure.security.keyvault.secrets.models.DeletedSecret)1 SecretProperties (com.azure.security.keyvault.secrets.models.SecretProperties)1 SecretStringCredentials (com.microsoft.jenkins.keyvault.SecretStringCredentials)1 VaultSecretNotFoundException (com.quorum.tessera.key.vault.VaultSecretNotFoundException)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1