Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

GITLAB_{URI,HOST} lead to failure if scheme is provided, documentation doesn't match what code needs #592

Closed
hartzell opened this issue Jan 28, 2021 · 4 comments · Fixed by #667
Labels
bug Something isn't working priority: medium Affects more than a few users but doesn't prevent core functions status: open-for-PRs Pull request can be opened for this issue

Comments

@hartzell
Copy link

Description

We have a self-hosted GitLab instance.

The glab help string that says:

GITLAB_HOST or GL_HOST: specify the url of the gitlab server if self hosted (eg: https://gitlab.example.com). Default is https://gitlab.com.

If I set GITLAB_HOST to https://gitlab.my.company.com, it fails to connect to my GitLab:

▶ export GITLAB_HOST=https://gitlab.my.company.com
▶ ./bin/glab repo search -s docker
error connecting to https
lookup https on 10.0.1.11:53: read udp 172.16.194.177:48449->10.0.1.11:53: i/o timeout
check your internet connection or status.gitlab.com or 'Run sudo gitlab-ctl status' on your server if self-hosted

▶

Walking into the code with Delve, I can see where the API endpoint is screwy:

> github.com/profclems/glab/internal/glinstance.APIEndpoint() ./internal/glinstance/host.go:66 (PC: 0x6cb5e7)
    61:	func APIEndpoint(hostname, protocol string) string {
    62:		if protocol == "" {
    63:			protocol = "https"
    64:		}
    65:		if IsSelfHosted(hostname) {
=>  66:			return fmt.Sprintf("%s://%s/api/v4/", protocol, hostname)
    67:		}
    68:		return "https://gitlab.com/api/v4/"
    69:	}
    70:
    71:	// GraphQLEndpoint returns the GraphQL API endpoint prefix for a GitLab instance :)
(dlv)
> github.com/profclems/glab/pkg/api.(*Client).NewLab() ./pkg/api/client.go:214 (PC: 0xebc094)
Values returned:
	~r2: "https://https://gitlab.my.company.com/api/v4/"

If I set GITLAB_HOST (also tested GITLAB_URI) to just the hostname, then it works as expected

▶ export GITLAB_HOST=gitlab.my.company.com
▶ ./bin/glab repo search -s docker
Showing results for "docker"
[...]

Possible Fix

Change the documentation string to describe what is actually acceptable, or change the code to handle the string that the documentation suggests.

Steps to Reproduce

see above.

Your Environment

CentOS 7, go 1.13.11 (sigh...)

Glab built locally from source

▶ ./bin/glab --version
[--version] -> [--version]
glab version 1.14.0 (2021-01-28)
▶ git log | head
commit a086fdd49409da8b621f10c0cd2778b4d5b2f51a
[...]
@hartzell hartzell added the bug Something isn't working label Jan 28, 2021
@profclems profclems added the priority: medium Affects more than a few users but doesn't prevent core functions label Jan 28, 2021
@profclems
Copy link
Owner

profclems commented Jan 28, 2021

Thanks @hartzell for reporting this issue!

For a quick fix, I will change the documentation to fit what our code currently understands but I will consider that as a bug because it should be able to parse the URL (if it's a fully qualified url) provided and use the hostname.

I think this issue came up after we made big changes to glab's flow in 6c4fe1c

This issue is however open in case you'd want to submit a PR with a fix

@profclems profclems added the status: open-for-PRs Pull request can be opened for this issue label Jan 28, 2021
@clemsbot
Copy link
Collaborator

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@clemsbot clemsbot added the stale label Mar 10, 2021
@zemzale zemzale mentioned this issue Mar 25, 2021
5 tasks
@zemzale
Copy link
Collaborator

zemzale commented Mar 25, 2021

I created a dirty fix in #667 by just checking if the hostname starts with http and if it does we ignore the protocol part, but that just feels dirty to me, and a new issue came up.

I have a api token registred for the host I am trying to use (and it works if GITLAB_HOST=my.gitlab.com is without protocol), but when I try to use it with protocol I get 401, because config resolution is looking for my.gitlab.com not https://my.gitlab.com.

My idea of fixing that is that we just strip the protocol from the GITLAB_HOST when we setting the hostname override.
Does that sounds like a valid solution @profclems? I just be worried that it might break something.

@clemsbot clemsbot removed the stale label Mar 26, 2021
@clemsbot
Copy link
Collaborator

This issue has been automatically marked as stale because it has not had recent activity. We haven't had the time to address it yet, but we want to keep it open. This message is just a reminder for us to help triage issues.

@clemsbot clemsbot added the stale label Apr 25, 2021
zemzale added a commit to zemzale/glab that referenced this issue Apr 28, 2021
When trying to override host with full URLs, config key lookups would
fail. This came down to the fact that we use `my.gitlab.com` as config
key and when providing override as `https://my.gitlab.com/` it would
fail to find this config key.

Issue profclems#592
@zemzale zemzale removed the stale label Apr 28, 2021
profclems pushed a commit to olearycrew/glab that referenced this issue Jun 12, 2021
When trying to override host with full URLs, config key lookups would
fail. This came down to the fact that we use `my.gitlab.com` as config
key and when providing override as `https://my.gitlab.com/` it would
fail to find this config key.

Issue profclems#592
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working priority: medium Affects more than a few users but doesn't prevent core functions status: open-for-PRs Pull request can be opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants