Search in sources :

Example 1 with SecretProperties

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

use of com.azure.security.keyvault.secrets.models.SecretProperties in project azure-keyvault-plugin by jenkinsci.

the class AzureCredentialsProvider method fetchCredentials.

private static Collection<IdCredentials> fetchCredentials() {
    AzureKeyVaultGlobalConfiguration azureKeyVaultGlobalConfiguration = GlobalConfiguration.all().get(AzureKeyVaultGlobalConfiguration.class);
    if (azureKeyVaultGlobalConfiguration == null) {
        throw new AzureKeyVaultException("No global key vault url configured.");
    }
    String credentialID = azureKeyVaultGlobalConfiguration.getCredentialID();
    try {
        SecretClient client = SecretClientCache.get(credentialID, azureKeyVaultGlobalConfiguration.getKeyVaultURL());
        List<IdCredentials> credentials = new ArrayList<>();
        for (SecretProperties secretItem : client.listPropertiesOfSecrets()) {
            String id = secretItem.getId();
            Map<String, String> tags = secretItem.getTags();
            if (tags == null) {
                tags = new HashMap<>();
            }
            String type = tags.getOrDefault("type", DEFAULT_TYPE);
            // initial implementation didn't require a type
            if (tags.containsKey("username") && type.equals(DEFAULT_TYPE)) {
                type = "username";
            }
            switch(type) {
                case "string":
                    {
                        AzureSecretStringCredentials cred = new AzureSecretStringCredentials(getSecretName(id), "", new KeyVaultSecretRetriever(client, id));
                        credentials.add(cred);
                    }
                    break;
                case "username":
                    {
                        AzureUsernamePasswordCredentials cred = new AzureUsernamePasswordCredentials(getSecretName(id), tags.get("username"), "", new KeyVaultSecretRetriever(client, id));
                        credentials.add(cred);
                    }
                    break;
                default:
                    {
                        throw new IllegalStateException("Unknown type: " + type);
                    }
            }
        }
        return credentials;
    } catch (Exception e) {
        LOG.log(Level.WARNING, "Error retrieving secrets from Azure KeyVault: " + e.getMessage(), e);
        return Collections.emptyList();
    }
}
Also used : IdCredentials(com.cloudbees.plugins.credentials.common.IdCredentials) AzureSecretStringCredentials(org.jenkinsci.plugins.azurekeyvaultplugin.credentials.string.AzureSecretStringCredentials) ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) SecretClient(com.azure.security.keyvault.secrets.SecretClient) SecretProperties(com.azure.security.keyvault.secrets.models.SecretProperties) AzureUsernamePasswordCredentials(org.jenkinsci.plugins.azurekeyvaultplugin.credentials.usernamepassword.AzureUsernamePasswordCredentials)

Example 3 with SecretProperties

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

the class SecretsStepDefs method theUpdateRequestIsSent.

@When("the secret update request is sent")
public void theUpdateRequestIsSent() {
    final SecretProperties properties = context.getClient(context.getSecretServiceVersion()).updateSecretProperties(context.getUpdateProperties());
    fetchLatestSecretVersion(properties.getName());
}
Also used : SecretProperties(com.azure.security.keyvault.secrets.models.SecretProperties) When(io.cucumber.java.en.When)

Aggregations

SecretProperties (com.azure.security.keyvault.secrets.models.SecretProperties)3 When (io.cucumber.java.en.When)2 SecretClient (com.azure.security.keyvault.secrets.SecretClient)1 KeyVaultSecret (com.azure.security.keyvault.secrets.models.KeyVaultSecret)1 IdCredentials (com.cloudbees.plugins.credentials.common.IdCredentials)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 AzureSecretStringCredentials (org.jenkinsci.plugins.azurekeyvaultplugin.credentials.string.AzureSecretStringCredentials)1 AzureUsernamePasswordCredentials (org.jenkinsci.plugins.azurekeyvaultplugin.credentials.usernamepassword.AzureUsernamePasswordCredentials)1