Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Commit

Permalink
our own api respects settings of GitLabConnection (ignoreCertificateE…
Browse files Browse the repository at this point in the history
…rrors & timeout)
  • Loading branch information
Argelbargel committed Nov 21, 2017
1 parent bbc1a81 commit b22505d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import hudson.model.Item;
import hudson.security.ACL;
import jenkins.model.Jenkins;
import org.apache.commons.codec.digest.DigestUtils;

import javax.annotation.Nonnull;
import java.util.ArrayList;
Expand All @@ -26,7 +25,7 @@ private GitLabHelper() { /* no instances allowed */ }

public static GitLabAPI gitLabAPI(String connectionName) throws GitLabAPIException {
GitLabConnection connection = gitLabConnection(connectionName);
return GitLabAPI.connect(connection.getUrl(), gitLabApiToken(connection.getApiTokenId()));
return GitLabAPI.connect(connection.getUrl(), gitLabApiToken(connection.getApiTokenId()), connection.isIgnoreCertificateErrors(), connection.getReadTimeout());
}

public static GitLabConnection gitLabConnection(String connectionName) {
Expand Down Expand Up @@ -56,20 +55,10 @@ static List<String> gitLabConnectionNames() {
return names;
}

static String gitLabConnectionId(String connectionName) {
try {
GitLabConnection conn = gitLabConnection(connectionName);
return DigestUtils.md5Hex(conn.getUrl()) + "::" + DigestUtils.md5Hex(gitLabApiToken(conn.getApiTokenId()));
} catch (NoSuchElementException e) {
return DigestUtils.md5Hex(connectionName);
}
}

private static GitLabConnectionConfig connectionConfig() {
return (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
}


private static String gitLabApiToken(String id) {
StandardCredentials credentials = CredentialsMatchers.firstOrNull(
lookupCredentials(StandardCredentials.class, (Item) null, ACL.SYSTEM, new ArrayList<DomainRequirement>()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
public final class GitLabAPI {
private static final String PATH_SEP = "/";

public static GitLabAPI connect(String url, String token) throws GitLabAPIException {
public static GitLabAPI connect(String url, String token, boolean ignoreCertificateErrors, int requestTimeout) throws GitLabAPIException {
try {
return new GitLabAPI(GitlabAPI.connect(url, token));
GitlabAPI delegate = GitlabAPI.connect(url, token);
delegate.ignoreCertificateErrors(ignoreCertificateErrors);
delegate.setRequestTimeout(requestTimeout);
return new GitLabAPI(delegate);
} catch (Exception e) {
throw new GitLabAPIException(e);
}
Expand Down

0 comments on commit b22505d

Please sign in to comment.