Skip to content

Commit

Permalink
JCasC - Don't throw an error if secret not found (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored May 6, 2021
1 parent 6dae257 commit 66da3ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hudson.EnvVars;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander;

Expand All @@ -18,4 +19,10 @@ public class AzureKeyVaultEnvironmentExpander extends EnvironmentExpander {
public void expand(@Nonnull EnvVars env) throws IOException, InterruptedException {
env.overrideAll(secrets);
}

@Nonnull
@Override
public Set<String> getSensitiveVariables() {
return secrets.keySet();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.azurekeyvaultplugin;

import com.azure.core.credential.TokenCredential;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.security.keyvault.secrets.SecretClient;
import com.azure.security.keyvault.secrets.models.KeyVaultSecret;
import com.microsoft.azure.util.AzureCredentials;
Expand Down Expand Up @@ -32,12 +33,12 @@ public Optional<String> reveal(String secret) {

SecretClient client = AzureCredentials.createKeyVaultClient(keyVaultCredentials, azureKeyVaultGlobalConfiguration.getKeyVaultURL());

KeyVaultSecret secretBundle = client.getSecret(secret);
if (secretBundle != null) {
try {
KeyVaultSecret secretBundle = client.getSecret(secret);
return Optional.of(secretBundle.getValue());
} catch (ResourceNotFoundException ignored) {
LOGGER.info("Couldn't find secret: " + secret);
return Optional.empty();
}

LOGGER.info("Couldn't find secret: " + secret);
return Optional.empty();
}
}

0 comments on commit 66da3ee

Please sign in to comment.