Skip to content

Commit

Permalink
Merge pull request #135 from oatmealraisin/rymurphy/132
Browse files Browse the repository at this point in the history
Modified credentialsId to never return null
  • Loading branch information
bparees committed May 18, 2017
2 parents 74bbacd + 47e0f44 commit e88d5b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
@@ -1,11 +1,7 @@
package io.fabric8.jenkins.openshiftsync;

import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsStore;
import com.cloudbees.plugins.credentials.*;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
Expand All @@ -25,12 +21,7 @@
import java.util.logging.Logger;

import static hudson.Util.fixNull;
import static io.fabric8.jenkins.openshiftsync.Constants.OPENSHIFT_SECRETS_DATA_PASSWORD;
import static io.fabric8.jenkins.openshiftsync.Constants.OPENSHIFT_SECRETS_DATA_SSHPRIVATEKEY;
import static io.fabric8.jenkins.openshiftsync.Constants.OPENSHIFT_SECRETS_DATA_USERNAME;
import static io.fabric8.jenkins.openshiftsync.Constants.OPENSHIFT_SECRETS_TYPE_BASICAUTH;
import static io.fabric8.jenkins.openshiftsync.Constants.OPENSHIFT_SECRETS_TYPE_OPAQUE;
import static io.fabric8.jenkins.openshiftsync.Constants.OPENSHIFT_SECRETS_TYPE_SSH;
import static io.fabric8.jenkins.openshiftsync.Constants.*;
import static io.fabric8.jenkins.openshiftsync.OpenShiftUtils.getAuthenticatedOpenShiftClient;
import static org.apache.commons.lang.StringUtils.isNotBlank;

Expand Down Expand Up @@ -65,18 +56,25 @@ public static synchronized String updateSourceCredentials(BuildConfig buildConfi
return id;
}

// getCurrentToken returns the ServiceAccount token currently selected by the user. A return value of empty string
// implies no token is configured.
public static String getCurrentToken() {
String credentialsId = GlobalPluginConfiguration.get().getCredentialsId();
if(credentialsId.equals("")) {
return "";
}

OpenShiftToken token = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
OpenShiftToken.class,
Jenkins.getActiveInstance(),
ACL.SYSTEM,
Collections.<DomainRequirement> emptyList()
Collections.<DomainRequirement>emptyList()
),
CredentialsMatchers.withId(GlobalPluginConfiguration.get().getCredentialsId())
);
CredentialsMatchers.withId(credentialsId)
);

if( token != null ) {
if (token != null) {
return token.getToken();
}

Expand Down
Expand Up @@ -103,8 +103,9 @@ public void setServer(String server) {
this.server = server;
}

// When Jenkins is reset, credentialsId is strangely set to null. However, credentialsId has no reason to be null.
public String getCredentialsId() {
return credentialsId;
return credentialsId == null ? "" : credentialsId;
}

public void setCredentialsId(String credentialsId) {
Expand Down

0 comments on commit e88d5b3

Please sign in to comment.