Example usage for org.eclipse.jgit.transport URIish toPrivateASCIIString

List of usage examples for org.eclipse.jgit.transport URIish toPrivateASCIIString

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport URIish toPrivateASCIIString.

Prototype

public String toPrivateASCIIString() 

Source Link

Document

Convert the URI including password, formatted with only ASCII characters such that it will be valid for use over the network.

Usage

From source file:br.com.ingenieux.jenkins.plugins.codecommit.CodeCommitURLHelper.java

License:Apache License

private Iterable<RepositoryUsernameReference> fetchCodeCommitRepositoryNames(GitSCM scm)
        throws CredentialNotFoundException {
    AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();

    if (isNotBlank(credentialId)) {
        credentials = CredentialsFactory.getCredentials(credentialId);

        if (null == credentials)
            throw new CredentialNotFoundException(
                    "CredentialId '" + credentialId + "' specified but not found.");
    }/*from w w  w .  ja v  a 2s  . c om*/

    Set<RepositoryUsernameReference> results = new LinkedHashSet<RepositoryUsernameReference>();

    for (RemoteConfig cfg : scm.getRepositories()) {
        for (URIish u : cfg.getURIs()) {
            final String repositoryUrl = u.toPrivateASCIIString();
            final Matcher m = PATTERN_CODECOMMIT_REPO.matcher(repositoryUrl);

            if (m.matches()) {
                final String awsRegion = m.group(1);
                final String repositoryName = m.group(2);

                String usernamePassword = new CodeCommitRequestSigner(credentials, repositoryName, awsRegion,
                        new Date()).getPushUrl();

                int lastIndex = usernamePassword.lastIndexOf(':');

                String username = usernamePassword.substring(0, lastIndex);

                String password = usernamePassword.substring(1 + lastIndex);

                results.add(new RepositoryUsernameReference(repositoryUrl, repositoryName, username, password));
            }
        }
    }

    return results;
}