Skip to content
Browse files

Merge pull request #10 from ptierno/JENKINS-38939

[JENKINS-38939] add VaultGithubTokenCredential to authenticate to vau…
  • Loading branch information
ptierno committed May 22, 2017
2 parents ee8acbd + b93ac10 commit 94d618ceb83930b091ec465c4be539ab55243102
@@ -0,0 +1,54 @@
package com.datapipe.jenkins.vault.credentials;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.kohsuke.stapler.DataBoundConstructor;

import com.bettercloud.vault.Vault;
import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
import com.datapipe.jenkins.vault.exception.VaultPluginException;

import hudson.Extension;
import hudson.util.Secret;

public class VaultGithubTokenCredential extends BaseStandardCredentials implements VaultCredential {

private final @Nonnull Secret accessToken;

public VaultGithubTokenCredential(@CheckForNull CredentialsScope scope,
@CheckForNull String id,
@CheckForNull String description,
@Nonnull Secret accessToken) {
super(scope, id, description);
this.accessToken = accessToken;

public Secret getAccessToken() {
return accessToken;

public Vault authorizeWithVault(Vault vault, VaultConfig config) {
String token = null;
try {
token = vault.auth().loginByGithub(Secret.toString(accessToken)).getAuthClientToken();
} catch (VaultException e) {
throw new VaultPluginException("could not log in into vault", e);
return new Vault(config.token(token));

public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
public String getDisplayName() {
return "Vault Github Token Credential";
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<f:entry title="Personal Access Token">
<f:textbox field="accessToken" name="accessToken" />
<st:include page="id-and-description" class="${descriptor.clazz}"/>

0 comments on commit 94d618c

Please sign in to comment.
You can’t perform that action at this time.