Java Code Examples for com.cloudbees.plugins.credentials.SystemCredentialsProvider#getInstance()

The following examples show how to use com.cloudbees.plugins.credentials.SystemCredentialsProvider#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitLabConfigurationTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithReadme("gitlab/README.md")
public void configure_gitlab_api_token() throws Exception {
    SystemCredentialsProvider systemCreds = SystemCredentialsProvider.getInstance();
    List<DomainCredentials> domainCredentials = systemCreds.getDomainCredentials();
    assertEquals(1, domainCredentials.size());
    final DomainCredentials gitLabCredential = domainCredentials.get(0);
    assertEquals(Domain.global(), gitLabCredential.getDomain());
    assertEquals(1, gitLabCredential.getCredentials().size());
    final GitLabApiToken apiToken = (GitLabApiToken)gitLabCredential.getCredentials().get(0);
    assertEquals("gitlab_token", apiToken.getId());
    assertEquals("qwertyuiopasdfghjklzxcvbnm", apiToken.getApiToken().getPlainText());
    assertEquals("Gitlab Token", apiToken.getDescription());
}
 
Example 2
Source File: CodeBuilder.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems() {
    final ListBoxModel selections = new ListBoxModel();

    SystemCredentialsProvider s = SystemCredentialsProvider.getInstance();
    Set<String> displayCredentials = new HashSet<>();

    for (Credentials c: s.getCredentials()) {
        if (c instanceof CodeBuildBaseCredentials) {
            displayCredentials.add(((CodeBuildBaseCredentials) c).getId());
        }
    }

    Jenkins instance = Jenkins.getInstance();
    if(instance != null) {
        List<Folder> folders = instance.getAllItems(Folder.class);
        for(Folder folder: folders) {
            List<Credentials> creds = CredentialsProvider.lookupCredentials(Credentials.class, (Item) folder);
            for(Credentials cred: creds) {
                if (cred instanceof CodeBuildBaseCredentials) {
                    displayCredentials.add(((CodeBuildBaseCredentials) cred).getId());
                }
            }
        }
    }


    for(String credString: displayCredentials) {
        selections.add(credString);
    }

    return selections;
}
 
Example 3
Source File: CodeBuildStep.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems() {
    final ListBoxModel selections = new ListBoxModel();

    SystemCredentialsProvider s = SystemCredentialsProvider.getInstance();
    Set<String> displayCredentials = new HashSet<>();

    for (Credentials c: s.getCredentials()) {
        if (c instanceof CodeBuildBaseCredentials) {
            displayCredentials.add(((CodeBuildBaseCredentials) c).getId());
        }
    }

    Jenkins instance = Jenkins.getInstance();
    if(instance != null) {
        List<Folder> folders = instance.getAllItems(Folder.class);
        for(Folder folder: folders) {
            List<Credentials> creds = CredentialsProvider.lookupCredentials(Credentials.class, (Item) folder);
            for(Credentials cred: creds) {
                if (cred instanceof CodeBuildBaseCredentials) {
                    displayCredentials.add(((CodeBuildBaseCredentials) cred).getId());
                }
            }
        }
    }


    for(String credString: displayCredentials) {
        selections.add(credString);
    }

    return selections;
}
 
Example 4
Source File: GitLabConnectionConfigAsCodeTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
@ConfiguredWithCode("global-config.yml")
public void configure_gitlab_api_token() throws Exception {
    SystemCredentialsProvider systemCreds = SystemCredentialsProvider.getInstance();
    List<DomainCredentials> domainCredentials = systemCreds.getDomainCredentials();
    assertEquals(1, domainCredentials.size());
    final DomainCredentials gitLabCredential = domainCredentials.get(0);
    assertEquals(Domain.global(), gitLabCredential.getDomain());
    assertEquals(1, gitLabCredential.getCredentials().size());
    final GitLabApiToken apiToken = (GitLabApiToken)gitLabCredential.getCredentials().get(0);
    assertEquals("gitlab_token", apiToken.getId());
    assertEquals("qwertyuiopasdfghjklzxcvbnm", apiToken.getApiToken().getPlainText());
    assertEquals("Gitlab Token", apiToken.getDescription());
}