Skip to content

Commit

Permalink
[JENKINS-38827] Track credentials use in some relevant cases
Browse files Browse the repository at this point in the history
These were easy cases because CredentialsProvider.track() arguments were
available in the method where credentials were added.

It is expected that there are still cases where credentials are not
tracked correctly by the plugin.  Credential checks from the job
definition page are probably not currently tracked.  Other contexts
(like pipeline) may also not be tracked by these changes.
  • Loading branch information
MarkEWaite committed Apr 18, 2017
1 parent 44da1a4 commit 79e610c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -764,6 +764,7 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull(urlCredentials, idMatcher);
if (credentials != null) {
c.addCredentials(url, credentials);
CredentialsProvider.track(project, credentials);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/hudson/plugins/git/UserRemoteConfig.java
Expand Up @@ -185,7 +185,9 @@ public FormValidation doCheckUrl(@AncestorInPath Item item,
GitClient git = Git.with(TaskListener.NULL, environment)
.using(GitTool.getDefaultInstallation().getGitExe())
.getClient();
git.addDefaultCredentials(lookupCredentials(item, credentialsId, url));
StandardCredentials credential = lookupCredentials(item, credentialsId, url);
git.addDefaultCredentials(credential);
CredentialsProvider.track(item, credential);

// attempt to connect the provided URL
try {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/jenkins/plugins/git/GitSCMFileSystem.java
Expand Up @@ -27,6 +27,7 @@

import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import edu.umd.cs.findbugs.annotations.CheckForNull;
Expand Down Expand Up @@ -257,7 +258,7 @@ public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull
GitClient client = git.getClient();
String credentialsId = config.getCredentialsId();
if (credentialsId != null) {
client.addDefaultCredentials(CredentialsMatchers.firstOrNull(
StandardCredentials credential = CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class,
owner,
Expand All @@ -268,8 +269,9 @@ public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull
CredentialsMatchers.withId(credentialsId),
GitClient.CREDENTIALS_MATCHER
)
)
);
);
client.addDefaultCredentials(credential);
CredentialsProvider.track(owner, credential);
}

if (!client.hasGitRepo()) {
Expand Down

0 comments on commit 79e610c

Please sign in to comment.