-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from atistler/revoke-lease-vault-disposer
Revoke lease vault disposer
- Loading branch information
Showing
8 changed files
with
114 additions
and
22 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/datapipe/jenkins/vault/VaultDisposer.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,40 @@ | ||
package com.datapipe.jenkins.vault; | ||
|
||
import com.bettercloud.vault.response.LogicalResponse; | ||
import com.datapipe.jenkins.vault.configuration.VaultConfiguration; | ||
import com.datapipe.jenkins.vault.credentials.VaultCredential; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import jenkins.tasks.SimpleBuildWrapper; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by adamtistler on 8/29/17. | ||
*/ | ||
public class VaultDisposer extends SimpleBuildWrapper.Disposer { | ||
private final List<String> leaseIds; | ||
private final VaultConfiguration vaultConfiguration; | ||
private final VaultCredential vaultCredential; | ||
|
||
public VaultDisposer(final VaultConfiguration vaultConfiguration, final VaultCredential vaultCredential, final List<String> leaseIds) { | ||
this.vaultConfiguration = vaultConfiguration; | ||
this.vaultCredential = vaultCredential; | ||
this.leaseIds = leaseIds; | ||
} | ||
|
||
@Override | ||
public void tearDown(final Run<?, ?> build, final FilePath workspace, final Launcher launcher, final TaskListener listener) throws IOException, InterruptedException { | ||
VaultAccessor vaultAccessor = new VaultAccessor(); | ||
vaultAccessor.init(vaultConfiguration.getVaultUrl()); | ||
vaultAccessor.auth(vaultCredential); | ||
for (String leaseId : leaseIds) { | ||
if (leaseId != null && !leaseId.isEmpty()) { | ||
vaultAccessor.revoke(leaseId); | ||
} | ||
} | ||
} | ||
} |
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