Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept gitlab hosts w/out scheme and use https:// by default #55

Closed
foot opened this issue Sep 30, 2020 · 2 comments · Fixed by #71
Closed

Accept gitlab hosts w/out scheme and use https:// by default #55

foot opened this issue Sep 30, 2020 · 2 comments · Fixed by #71

Comments

@foot
Copy link
Collaborator

foot commented Sep 30, 2020

At the moment we have to explicitly include the scheme to the gitlab api server. e.g.

These work:

c, err = NewClient(gitlabToken, "", WithDomain("https://gitlab.works")) // "https://gitlab.works"
c, err = NewClient(gitlabToken, "", WithDomain("http://gitlab.works")) // "http://gitlab.works"

This does not work yet but should prepend https:

c, err = NewClient(gitlabToken, "", WithDomain("gitlab.works")) // "https://gitlab.works"
@foot
Copy link
Collaborator Author

foot commented Mar 30, 2021

Fix might go in here

gitlabBaseURL := "https://"+domain;

if tokenType == "oauth2" {
if opts.Domain == nil || *opts.Domain == DefaultDomain {
// No domain set or the default gitlab.com used
domain = DefaultDomain
gl, err = gogitlab.NewOAuthClient(token, gogitlab.WithHTTPClient(httpClient))
if err != nil {
return nil, err
}
} else {
domain = *opts.Domain
gl, err = gogitlab.NewOAuthClient(token, gogitlab.WithHTTPClient(httpClient), gogitlab.WithBaseURL(domain))
if err != nil {
return nil, err
}
}
} else {
if opts.Domain == nil || *opts.Domain == DefaultDomain {
// No domain set or the default gitlab.com used
domain = DefaultDomain
gl, err = gogitlab.NewClient(token, gogitlab.WithHTTPClient(httpClient))
if err != nil {
return nil, err
}
} else {
domain = *opts.Domain
gl, err = gogitlab.NewClient(token, gogitlab.WithHTTPClient(httpClient), gogitlab.WithBaseURL(domain))
if err != nil {
return nil, err
}
}
}

@dinosk
Copy link
Contributor

dinosk commented Mar 31, 2021

The domain could also be parsed and have https:// prepended only if it's missing, at:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants