-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
531 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...in/java/org/jenkinsci/plugins/azurekeyvaultplugin/provider/CredentialsProviderHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.jenkinsci.plugins.azurekeyvaultplugin.provider; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import org.jenkinsci.plugins.azurekeyvaultplugin.provider.folder.FolderAzureCredentialsProvider; | ||
import org.jenkinsci.plugins.azurekeyvaultplugin.provider.global.AzureCredentialsProvider; | ||
|
||
public class CredentialsProviderHelper { | ||
|
||
private CredentialsProviderHelper() { | ||
} | ||
|
||
public static boolean isAzureCredentialsProvider(CredentialsProvider provider) { | ||
return provider instanceof AzureCredentialsProvider || provider instanceof FolderAzureCredentialsProvider; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...main/java/org/jenkinsci/plugins/azurekeyvaultplugin/provider/KeyVaultSecretRetriever.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jenkinsci.plugins.azurekeyvaultplugin.provider; | ||
|
||
import com.azure.security.keyvault.secrets.SecretClient; | ||
import hudson.util.Secret; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.function.Supplier; | ||
|
||
public class KeyVaultSecretRetriever implements Supplier<Secret> { | ||
|
||
private final transient SecretClient client; | ||
private final String secretId; | ||
|
||
public KeyVaultSecretRetriever(SecretClient secretClient, String secretId) { | ||
this.client = secretClient; | ||
this.secretId = secretId; | ||
} | ||
|
||
public String retrieveSecret() { | ||
int NAME_POSITION = 2; | ||
int VERSION_POSITION = 3; | ||
URL secretIdentifierUrl; | ||
try { | ||
secretIdentifierUrl = new URL(secretId); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// old SDK supports secret identifier which is a full URI to the secret | ||
// the new SDK doesn't seem to support it to we parse it to get the values we need | ||
// https://mine.vault.azure.net/secrets/<name>/<version> | ||
String[] split = secretIdentifierUrl.getPath().split("/"); | ||
|
||
if (split.length == NAME_POSITION + 1) { | ||
return client.getSecret(split[NAME_POSITION]).getValue(); | ||
} | ||
return client.getSecret(split[NAME_POSITION], split[VERSION_POSITION]).getValue(); | ||
} | ||
|
||
@Override | ||
public Secret get() { | ||
return Secret.fromString(retrieveSecret()); | ||
} | ||
} |
Oops, something went wrong.