com.cloudbees.plugins.credentials.domains.DomainCredentials Java Examples

The following examples show how to use com.cloudbees.plugins.credentials.domains.DomainCredentials. 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: GitHubAppCredentialsJCasCCompatibilityTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Test
public void should_support_configuration_as_code() {
    List<DomainCredentials> domainCredentials = SystemCredentialsProvider.getInstance()
            .getDomainCredentials();

    assertThat(domainCredentials.size(), is(1));
    List<Credentials> credentials = domainCredentials.get(0).getCredentials();
    assertThat(credentials.size(), is(1));

    Credentials credential = credentials.get(0);
    assertThat(credential, instanceOf(GitHubAppCredentials.class));
    GitHubAppCredentials gitHubAppCredentials = (GitHubAppCredentials) credential;

    assertThat(gitHubAppCredentials.getAppID(), is("1111"));
    assertThat(gitHubAppCredentials.getDescription(), is("GitHub app 1111"));
    assertThat(gitHubAppCredentials.getId(), is("github-app"));
    assertThat(gitHubAppCredentials.getPrivateKey(), hasPlainText(GITHUB_APP_KEY));
}
 
Example #2
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 #3
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());
}
 
Example #4
Source File: FolderIT.java    From hashicorp-vault-plugin with MIT License 4 votes vote down vote up
@Before
public void setupJenkins() throws IOException {
    GlobalVaultConfiguration globalConfig = GlobalConfiguration.all()
        .get(GlobalVaultConfiguration.class);

    VaultConfiguration vaultConfig = new VaultConfiguration();
    vaultConfig.setVaultUrl("http://global-vault-url.com");
    vaultConfig.setVaultCredentialId(GLOBAL_CREDENTIALS_ID_1);
    vaultConfig.setFailIfNotFound(false);
    vaultConfig.setVaultNamespace("mynamespace");
    vaultConfig.setTimeout(TIMEOUT);

    globalConfig.setConfiguration(vaultConfig);
    globalConfig.save();

    FOLDER_1_CREDENTIAL = createTokenCredential(FOLDER_1_CREDENTIALS_ID);
    FOLDER_2_CREDENTIAL = createTokenCredential(FOLDER_2_CREDENTIALS_ID);

    FolderCredentialsProvider.FolderCredentialsProperty folder1CredProperty = new FolderCredentialsProvider.FolderCredentialsProperty(
        new DomainCredentials[]{
            new DomainCredentials(Domain.global(),
                Collections.singletonList(FOLDER_1_CREDENTIAL))});

    FolderCredentialsProvider.FolderCredentialsProperty folder2CredProperty = new FolderCredentialsProvider.FolderCredentialsProperty(
        new DomainCredentials[]{
            new DomainCredentials(Domain.global(),
                Collections.singletonList(FOLDER_2_CREDENTIAL))});

    GLOBAL_CREDENTIAL_1 = createTokenCredential(GLOBAL_CREDENTIALS_ID_1);
    GLOBAL_CREDENTIAL_2 = createTokenCredential(GLOBAL_CREDENTIALS_ID_2);

    SystemCredentialsProvider.getInstance()
        .setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays
            .asList(GLOBAL_CREDENTIAL_1, GLOBAL_CREDENTIAL_2)));

    this.folder1 = jenkins.createProject(Folder.class, "folder1");
    this.folder2 = jenkins.createProject(Folder.class, "folder2");

    folder1.addProperty(folder1CredProperty);
    folder2.addProperty(folder2CredProperty);

    projectInFolder1 = this.folder1.createProject(FreeStyleProject.class, "projectInFolder1");
    projectInFolder2 = this.folder2.createProject(FreeStyleProject.class, "projectInFolder2");
}