Skip to content

Commit

Permalink
Get fresh oauth token on every git clone (#824)
Browse files Browse the repository at this point in the history
Previously token was fetched only once and saved in BitbucketSCMSource.

Fixes #808.
See also #810 and #796.
  • Loading branch information
andrey-fomin authored Mar 10, 2024
1 parent bbd5243 commit 4a79ab9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket;

import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryProtocol;
Expand Down Expand Up @@ -309,6 +310,13 @@ private String getCloneLink(List<BitbucketHref> cloneLinks) {
return cloneLinks.stream()
.filter(link -> protocol.matches(link.getName()))
.findAny()
.map(bitbucketHref -> {
BitbucketAuthenticator authenticator = scmSource().authenticator();
if (authenticator == null) {

Check warning on line 315 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 315 is only partially covered, one branch is missing
return bitbucketHref;
}
return authenticator.addAuthToken(bitbucketHref);

Check warning on line 318 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 318 is not covered by tests
})
.orElseThrow(() -> new IllegalStateException("Can't find clone link for protocol " + protocol))
.getHref();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import jenkins.authentication.tokens.api.AuthenticationTokens;
import jenkins.model.Jenkins;
import jenkins.plugins.git.AbstractGitSCMSource.SCMRevisionImpl;
Expand Down Expand Up @@ -1039,12 +1038,7 @@ public SCM build(SCMHead head, SCMRevision revision) {
}

private void setPrimaryCloneLinks(List<BitbucketHref> links) {
BitbucketAuthenticator authenticator = authenticator();
if (authenticator == null) {
primaryCloneLinks = links;
} else {
primaryCloneLinks = links.stream().map(authenticator::addAuthToken).collect(Collectors.toList());
}
primaryCloneLinks = links;
}

@NonNull
Expand Down

0 comments on commit 4a79ab9

Please sign in to comment.