use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project azure-credentials-plugin by jenkinsci.
the class ITSecretStringCredentials method getSecret.
@Test
public void getSecret() {
final KeyVaultSecret secretBundle = createSecret("secret-string", "I'm secret");
final String secretIdentifier = secretBundle.getId();
// Verify configuration
final SecretStringCredentials.DescriptorImpl descriptor = new SecretStringCredentials.DescriptorImpl();
final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier);
Assert.assertEquals(FormValidation.Kind.OK, result.kind);
// Get secret
final SecretStringCredentials credentials = new SecretStringCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier);
final Secret secret = credentials.getSecret();
Assert.assertEquals("I'm secret", secret.getPlainText());
}
use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project azure-credentials-plugin by jenkinsci.
the class KeyVaultIntegrationTestBase method createSecret.
protected KeyVaultSecret createSecret(final String name, final String value) {
KeyVaultSecret keyVaultSecret = new KeyVaultSecret(name, value);
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder().clientId(testEnv.clientId).clientSecret(testEnv.clientSecret).tenantId(testEnv.tenantId).build();
SecretClient secretClient = AzureCredentials.createKeyVaultClient(clientSecretCredential, vaultUri);
return secretClient.setSecret(keyVaultSecret);
}
use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project azure-keyvault-plugin by jenkinsci.
the class AzureKeyVaultBuildWrapper method setUp.
public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) {
if (azureKeyVaultSecrets == null || azureKeyVaultSecrets.isEmpty()) {
return;
}
SecretClient client = AzureCredentials.createKeyVaultClient(getKeyVaultCredential(build), getKeyVaultURL());
for (AzureKeyVaultSecret secret : azureKeyVaultSecrets) {
if (secret.isPassword()) {
KeyVaultSecret bundle = getSecret(client, secret);
if (bundle != null) {
valuesToMask.add(bundle.getValue());
context.env(secret.getEnvVariable(), bundle.getValue());
} else {
throw new AzureKeyVaultException(format("Secret: %s not found in vault: %s", secret.getName(), getKeyVaultURL()));
}
} else if (secret.isCertificate()) {
// Get Certificate from Keyvault as a Secret
KeyVaultSecret bundle = getSecret(client, secret);
if (bundle != null) {
try {
String path = AzureKeyVaultUtil.convertAndWritePfxToDisk(workspace, bundle.getValue());
context.env(secret.getEnvVariable(), path);
} catch (Exception e) {
throw new AzureKeyVaultException(e.getMessage(), e);
}
} else {
throw new AzureKeyVaultException(format("Certificate: %s not found in vault: %s", secret.getName(), getKeyVaultURL()));
}
}
}
}
use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project lowkey-vault by nagyesta.
the class SecretsStepDefs method theSecretNamedNameIsRestored.
@And("the secret named {name} is restored")
public void theSecretNamedNameIsRestored(final String name) {
final byte[] bytes = context.getBackupBytes(name);
final KeyVaultSecret secret = context.getClient(context.getSecretServiceVersion()).restoreSecretBackup(bytes);
context.addFetchedSecret(name, secret);
}
use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project lowkey-vault by nagyesta.
the class SecretsStepDefs method fetchLatestSecretVersion.
@When("the last secret version of {name} is fetched without providing a version")
public void fetchLatestSecretVersion(final String name) {
final KeyVaultSecret secret = context.getClient(context.getSecretServiceVersion()).getSecret(name);
final List<KeyVaultSecret> versionsCreated = context.getCreatedEntities().get(name);
final String expectedLastVersionId = versionsCreated.get(versionsCreated.size() - 1).getId();
context.addFetchedSecret(name, secret);
assertEquals(expectedLastVersionId, secret.getId());
}
Aggregations