Skip to content

Commit

Permalink
fix additional PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sirstrahd committed Mar 15, 2019
1 parent 94811cd commit 4e071dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/main/java/jenkins/plugins/slack/CredentialsObtainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cloudbees.plugins.credentials.CredentialsProvider;
import hudson.model.Item;
import hudson.security.ACL;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;

Expand All @@ -13,6 +14,12 @@

public class CredentialsObtainer {

public static StringCredentials lookupCredentials(String credentialId) {
List<StringCredentials> credentials = CredentialsProvider.lookupCredentials(StringCredentials.class, Jenkins.get(), ACL.SYSTEM, Collections.emptyList());
CredentialsMatcher matcher = CredentialsMatchers.withId(credentialId);
return CredentialsMatchers.firstOrNull(credentials, matcher);
}

public static StringCredentials lookupCredentials(String credentialId, Item item) {
List<StringCredentials> credentials = CredentialsProvider.lookupCredentials(StringCredentials.class, item, ACL.SYSTEM, Collections.emptyList());
CredentialsMatcher matcher = CredentialsMatchers.withId(credentialId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public boolean publish(String message, JSONArray attachments, String color) {

private String getTokenToUse(String authTokenCredentialId, String token) {
if (!StringUtils.isEmpty(authTokenCredentialId)) {
StringCredentials credentials = CredentialsObtainer.lookupCredentials(authTokenCredentialId, null);
StringCredentials credentials = CredentialsObtainer.lookupCredentials(authTokenCredentialId);
if (credentials != null) {
logger.fine("Using Integration Token Credential ID.");
return credentials.getSecret().getPlainText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public class SlackSendStep extends Step {
private Object attachments;
private boolean replyBroadcast;



@Nonnull
public String getMessage() {
return message;
Expand Down

0 comments on commit 4e071dc

Please sign in to comment.