Skip to content

Commit

Permalink
[JENKINS-38831] Fix binary incompatability and fix erroneous extra cr…
Browse files Browse the repository at this point in the history
…edential lookups.
  • Loading branch information
iwarapter committed Oct 24, 2016
1 parent f220b8a commit be563fa
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 18 deletions.
Expand Up @@ -24,17 +24,13 @@

package org.jenkinsci.plugins.credentialsbinding;

import com.cloudbees.plugins.credentials.CredentialsDescriptor;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.IdCredentials;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
Expand Down Expand Up @@ -62,7 +58,7 @@ protected MultiBinding(String credentialsId) {
}

/** Type token. */
public abstract Class<C> type();
protected abstract Class<C> type();

/** Identifier of the credentials to be bound. */
public final String getCredentialsId() {
Expand Down Expand Up @@ -120,6 +116,7 @@ protected static final class NullUnbinder implements Unbinder {
*/
protected final @Nonnull C getCredentials(@Nonnull Run<?,?> build) throws IOException {
IdCredentials cred = CredentialsProvider.findCredentialById(credentialsId, IdCredentials.class, build);
CredentialsProvider.track(build, cred);
if (cred==null)
throw new CredentialNotFoundException(credentialsId);

Expand Down
Expand Up @@ -24,8 +24,6 @@

package org.jenkinsci.plugins.credentialsbinding.impl;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.IdCredentials;
import com.google.inject.Inject;
import hudson.EnvVars;
import hudson.Extension;
Expand Down Expand Up @@ -94,8 +92,6 @@ public static final class Execution extends AbstractStepExecutionImpl {
MultiBinding.MultiEnvironment environment = binding.bind(run, workspace, launcher, listener);
unbinders.add(environment.getUnbinder());
overrides.putAll(environment.getValues());
IdCredentials id = CredentialsProvider.findCredentialById(binding.getCredentialsId(), binding.type(), run);
CredentialsProvider.track(run, id);
}
getContext().newBodyInvoker().
withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new Overrider(overrides))).
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class FileBinding extends Binding<FileCredentials> {
super(variable, credentialsId);
}

@Override public Class<FileCredentials> type() {
@Override protected Class<FileCredentials> type() {
return FileCredentials.class;
}

Expand Down
Expand Up @@ -24,8 +24,6 @@

package org.jenkinsci.plugins.credentialsbinding.impl;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.IdCredentials;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
Expand Down Expand Up @@ -59,8 +57,6 @@ public List<? extends MultiBinding<?>> getBindings() {
final List<MultiBinding.MultiEnvironment> m = new ArrayList<MultiBinding.MultiEnvironment>();
for (MultiBinding binding : bindings) {
m.add(binding.bind(build, build.getWorkspace(), launcher, listener));
IdCredentials id = CredentialsProvider.findCredentialById(binding.getCredentialsId(), binding.type(), build);
CredentialsProvider.track(build, id);
}
return new Environment() {
@Override public void buildEnvVars(Map<String,String> env) {
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class StringBinding extends Binding<StringCredentials> {
super(variable, credentialsId);
}

@Override public Class<StringCredentials> type() {
@Override protected Class<StringCredentials> type() {
return StringCredentials.class;
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public class UsernamePasswordBinding extends Binding<StandardUsernamePasswordCre
super(variable, credentialsId);
}

@Override public Class<StandardUsernamePasswordCredentials> type() {
@Override protected Class<StandardUsernamePasswordCredentials> type() {
return StandardUsernamePasswordCredentials.class;
}

Expand Down
Expand Up @@ -60,7 +60,7 @@ public String getPasswordVariable() {
return passwordVariable;
}

@Override public Class<StandardUsernamePasswordCredentials> type() {
@Override protected Class<StandardUsernamePasswordCredentials> type() {
return StandardUsernamePasswordCredentials.class;
}

Expand Down

0 comments on commit be563fa

Please sign in to comment.