Skip to content

Commit 42cd668

Browse files
committed
Use the host of the selfhosted reg as name
This is in order to improve vc log output Signed-off-by: Charlie Egan <[email protected]>
1 parent 25b1117 commit 42cd668

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://example.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://example.net

pkg/datagatherer/versionchecker/versionchecker.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/ioutil"
7+
"net/url"
78
"os"
89
"strings"
910
"time"
@@ -144,7 +145,16 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
144145
Host: data["host"],
145146
}
146147

147-
c.VersionCheckerClientOptions.Selfhosted[fmt.Sprintf("selfhosted-%d", i+1)] = &opts
148+
if len(opts.Host) == 0 {
149+
return fmt.Errorf("failed to init selfhosted dg, host is required (registry %d/%d): %s", i+1, len(aux.Registries), err)
150+
}
151+
152+
parsedURL, err := url.Parse(opts.Host)
153+
if err != nil {
154+
return fmt.Errorf("failed to parse host %s (registry %d/%d): %s", opts.Host, i+1, len(aux.Registries), err)
155+
}
156+
157+
c.VersionCheckerClientOptions.Selfhosted[parsedURL.Host] = &opts
148158
default:
149159
return fmt.Errorf("registry %d/%d was an unknown kind (%s)", i+1, len(aux.Registries), v.Kind)
150160
}

pkg/datagatherer/versionchecker/versionchecker_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ registries:
5858
token: fixtures/example_secret
5959
- kind: selfhosted
6060
params:
61-
host: fixtures/example_secret
61+
host: fixtures/example_host
6262
username: fixtures/example_secret
6363
password: fixtures/example_secret
6464
- kind: selfhosted
6565
params:
66-
host: fixtures/example_secret
66+
host: fixtures/example_host_2
6767
bearer: fixtures/example_secret
6868
`
6969

@@ -102,11 +102,11 @@ registries:
102102
t.Errorf("GCR token does not match: got=%+v want=%+v", got, want)
103103
}
104104

105-
if got, want := cfg.VersionCheckerClientOptions.Selfhosted["selfhosted-6"].Password, "pa55w0rd"; got != want {
105+
if got, want := cfg.VersionCheckerClientOptions.Selfhosted["example.com"].Password, "pa55w0rd"; got != want {
106106
t.Errorf("Selfhosted 6 password does not match: got=%+v want=%+v", got, want)
107107
}
108108

109-
if got, want := cfg.VersionCheckerClientOptions.Selfhosted["selfhosted-7"].Bearer, "pa55w0rd"; got != want {
109+
if got, want := cfg.VersionCheckerClientOptions.Selfhosted["example.net"].Bearer, "pa55w0rd"; got != want {
110110
t.Errorf("Selfhosted 7 bearer does not match: got=%+v want=%+v", got, want)
111111
}
112112
}

0 commit comments

Comments
 (0)