aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
diff options
context:
space:
mode:
authorJoel Baranick <joel.baranick@ensighten.com>2015-10-21 14:21:34 -0700
committerJoel Baranick <joel.baranick@ensighten.com>2015-10-21 14:21:34 -0700
commit8101c2fc7b6ca2b2fa1d835f2c5b2a5f159539a0 (patch)
treeb3c1bbed511705fe1cef01570be2f3002240f520 /src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
parentd002e0b758c1907c2d4963a2b9e556177e05ab03 (diff)
downloadbbprb-8101c2fc7b6ca2b2fa1d835f2c5b2a5f159539a0.tar.gz
Support credentials by allowing UsernamePasswordCredentials to be picked when configuring BitbucketBuildTrigger and change BitbucketRepository to use the credentials when setting up the ApiClient.
Diffstat (limited to 'src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java')
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
index bdf5d7c..8606c45 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
@@ -10,6 +10,12 @@ import java.util.regex.Pattern;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.ApiClient;
import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.Pullrequest;
+import com.cloudbees.plugins.credentials.CredentialsMatchers;
+import com.cloudbees.plugins.credentials.CredentialsProvider;
+import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
+import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
+
+import static com.cloudbees.plugins.credentials.CredentialsMatchers.instanceOf;
/**
* Created by nishio
@@ -39,9 +45,10 @@ public class BitbucketRepository {
public void init() {
trigger = this.builder.getTrigger();
+ StandardUsernamePasswordCredentials credentials = getCredentials(trigger.getCredentialsId());
client = new ApiClient(
- trigger.getUsername(),
- trigger.getPassword(),
+ credentials.getUsername(),
+ credentials.getPassword().getPlainText(),
trigger.getRepositoryOwner(),
trigger.getRepositoryName());
}
@@ -192,4 +199,12 @@ public class BitbucketRepository {
}
return false;
}
+
+ private StandardUsernamePasswordCredentials getCredentials(String credentialsId) {
+ return CredentialsMatchers
+ .firstOrNull(
+ CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class),
+ CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId),
+ instanceOf(UsernamePasswordCredentials.class)));
+ }
}