|
2 | 2 |
|
3 | 3 | import com.cloudbees.plugins.credentials.CredentialsMatchers; |
4 | 4 | import com.cloudbees.plugins.credentials.common.StandardListBoxModel; |
5 | | -import com.cloudbees.plugins.credentials.domains.DomainRequirement; |
6 | 5 | import com.google.common.base.Function; |
7 | 6 | import com.google.common.base.Optional; |
8 | 7 | import com.google.common.base.Predicate; |
|
21 | 20 | import java.io.IOException; |
22 | 21 | import java.net.MalformedURLException; |
23 | 22 | import java.net.URL; |
24 | | -import java.util.Collections; |
25 | | -import java.util.List; |
26 | 23 | import jenkins.model.Jenkins; |
27 | 24 | import jenkins.scm.api.SCMName; |
28 | 25 | import org.apache.commons.lang3.StringUtils; |
29 | 26 | import org.jenkinsci.plugins.github.internal.GitHubLoginFunction; |
30 | | -import org.jenkinsci.plugins.github.util.FluentIterableWrapper; |
31 | 27 | import org.jenkinsci.plugins.github.util.misc.NullSafeFunction; |
32 | 28 | import org.jenkinsci.plugins.github.util.misc.NullSafePredicate; |
33 | 29 | import org.jenkinsci.plugins.plaincredentials.StringCredentials; |
|
41 | 37 | import org.slf4j.Logger; |
42 | 38 | import org.slf4j.LoggerFactory; |
43 | 39 |
|
44 | | -import static com.cloudbees.plugins.credentials.CredentialsMatchers.filter; |
45 | | -import static com.cloudbees.plugins.credentials.CredentialsMatchers.withId; |
46 | | -import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials; |
| 40 | +import static com.cloudbees.plugins.credentials.CredentialsProvider.findCredentialByIdInItemGroup; |
47 | 41 | import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri; |
48 | 42 | import static org.apache.commons.lang3.StringUtils.defaultIfBlank; |
49 | 43 | import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; |
50 | 44 | import static org.apache.commons.lang3.StringUtils.isNotBlank; |
51 | | -import static org.apache.commons.lang3.StringUtils.trimToEmpty; |
52 | 45 |
|
53 | 46 | /** |
54 | 47 | * This object represents configuration of each credentials-github pair. |
@@ -287,20 +280,14 @@ public Secret get() { |
287 | 280 | */ |
288 | 281 | @NonNull |
289 | 282 | public static Optional<Secret> secretFor(String credentialsId) { |
290 | | - List<StringCredentials> creds = filter( |
291 | | - lookupCredentials(StringCredentials.class, |
292 | | - Jenkins.getInstance(), ACL.SYSTEM, |
293 | | - Collections.<DomainRequirement>emptyList()), |
294 | | - withId(trimToEmpty(credentialsId)) |
295 | | - ); |
296 | | - |
297 | | - return FluentIterableWrapper.from(creds) |
298 | | - .transform(new NullSafeFunction<StringCredentials, Secret>() { |
299 | | - @Override |
300 | | - protected Secret applyNullSafe(@NonNull StringCredentials input) { |
301 | | - return input.getSecret(); |
302 | | - } |
303 | | - }).first(); |
| 283 | + if (credentialsId == null) { |
| 284 | + return Optional.absent(); |
| 285 | + } |
| 286 | + var creds = findCredentialByIdInItemGroup(credentialsId, StringCredentials.class, null, null, null); |
| 287 | + if (creds == null) { |
| 288 | + return Optional.absent(); |
| 289 | + } |
| 290 | + return Optional.of(creds.getSecret()); |
304 | 291 | } |
305 | 292 |
|
306 | 293 | /** |
|
0 commit comments