11package io .jenkins .plugins .gitlabserverconfig .servers ;
22
3- import static com .cloudbees .plugins .credentials .CredentialsMatchers .withId ;
4- import static com .cloudbees .plugins .credentials .CredentialsProvider .lookupCredentials ;
53import static com .cloudbees .plugins .credentials .domains .URIRequirementBuilder .fromUri ;
64import static io .jenkins .plugins .gitlabbranchsource .helpers .GitLabHelper .getPrivateTokenAsPlainText ;
75import static io .jenkins .plugins .gitlabbranchsource .helpers .GitLabHelper .getProxyConfig ;
1412import com .cloudbees .plugins .credentials .SystemCredentialsProvider ;
1513import com .cloudbees .plugins .credentials .common .StandardCredentials ;
1614import com .cloudbees .plugins .credentials .common .StandardListBoxModel ;
17- import com .cloudbees .plugins .credentials .domains .DomainRequirement ;
1815import edu .umd .cs .findbugs .annotations .CheckForNull ;
1916import edu .umd .cs .findbugs .annotations .NonNull ;
2017import hudson .Extension ;
3229import java .net .MalformedURLException ;
3330import java .net .URL ;
3431import java .security .SecureRandom ;
35- import java .util .ArrayList ;
3632import java .util .Collections ;
3733import java .util .List ;
3834import java .util .logging .Level ;
@@ -281,14 +277,12 @@ public StandardCredentials getCredentials(AccessControlled context) {
281277 }
282278 return StringUtils .isBlank (credentialsId )
283279 ? null
284- : CredentialsMatchers .firstOrNull (
285- lookupCredentials (
286- StandardCredentials .class ,
287- jenkins ,
288- ACL .SYSTEM ,
289- fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
290- .build ()),
291- withId (credentialsId ));
280+ : CredentialsProvider .findCredentialByIdInItemGroup (
281+ credentialsId ,
282+ StandardCredentials .class ,
283+ null ,
284+ null ,
285+ fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL )).build ());
292286 }
293287
294288 /**
@@ -337,38 +331,37 @@ public StringCredentials getWebhookSecretCredentials(AccessControlled context) {
337331 jenkins .checkPermission (CredentialsProvider .USE_OWN );
338332 return StringUtils .isBlank (webhookSecretCredentialsId )
339333 ? null
340- : CredentialsMatchers .firstOrNull (
341- lookupCredentials (
342- StringCredentials .class ,
343- jenkins ,
344- ACL .SYSTEM ,
345- fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
346- .build ()),
347- withId (webhookSecretCredentialsId ));
334+ : CredentialsProvider .findCredentialByIdInItemGroup (
335+ webhookSecretCredentialsId ,
336+ StringCredentials .class ,
337+ null ,
338+ null ,
339+ fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
340+ .build ());
348341 } else {
349342 context .checkPermission (CredentialsProvider .USE_OWN );
350- if (context instanceof ItemGroup ) {
343+ if (context instanceof ItemGroup <?> g ) {
351344 return StringUtils .isBlank (webhookSecretCredentialsId )
352345 ? null
353- : CredentialsMatchers .firstOrNull (
354- lookupCredentials (
355- StringCredentials .class ,
356- (ItemGroup ) context ,
357- ACL .SYSTEM ,
358- fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
359- .build ()),
360- withId (webhookSecretCredentialsId ));
361- } else {
346+ : CredentialsProvider .findCredentialByIdInItemGroup (
347+ webhookSecretCredentialsId ,
348+ StringCredentials .class ,
349+ g ,
350+ null ,
351+ fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
352+ .build ());
353+ } else if (context instanceof Item i ) {
362354 return StringUtils .isBlank (webhookSecretCredentialsId )
363355 ? null
364- : CredentialsMatchers .firstOrNull (
365- lookupCredentials (
366- StringCredentials .class ,
367- (Item ) context ,
368- ACL .SYSTEM ,
369- fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
370- .build ()),
371- withId (webhookSecretCredentialsId ));
356+ : CredentialsProvider .findCredentialByIdInItem (
357+ webhookSecretCredentialsId ,
358+ StringCredentials .class ,
359+ i ,
360+ null ,
361+ fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
362+ .build ());
363+ } else {
364+ return null ;
372365 }
373366 }
374367 }
@@ -387,13 +380,10 @@ public Secret getSecretToken() {
387380 }
388381
389382 private StringCredentials getWebhookSecretCredentials (String webhookSecretCredentialsId ) {
390- Jenkins jenkins = Jenkins .get ();
391383 return StringUtils .isBlank (webhookSecretCredentialsId )
392384 ? null
393- : CredentialsMatchers .firstOrNull (
394- lookupCredentials (
395- StringCredentials .class , jenkins , ACL .SYSTEM , new ArrayList <DomainRequirement >()),
396- withId (webhookSecretCredentialsId ));
385+ : CredentialsProvider .findCredentialByIdInItemGroup (
386+ webhookSecretCredentialsId , StringCredentials .class , null , null , null );
397387 }
398388
399389 public String getSecretTokenAsPlainText () {
@@ -668,14 +658,13 @@ private StandardCredentials getCredentials(String serverUrl, String credentialsI
668658 jenkins .checkPermission (Jenkins .MANAGE );
669659 return StringUtils .isBlank (credentialsId )
670660 ? null
671- : CredentialsMatchers .firstOrNull (
672- lookupCredentials (
673- StandardCredentials .class ,
674- jenkins ,
675- ACL .SYSTEM ,
676- fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
677- .build ()),
678- withId (credentialsId ));
661+ : CredentialsProvider .findCredentialByIdInItemGroup (
662+ credentialsId ,
663+ StandardCredentials .class ,
664+ null ,
665+ null ,
666+ fromUri (defaultIfBlank (serverUrl , GITLAB_SERVER_URL ))
667+ .build ());
679668 }
680669 }
681670}
0 commit comments