Skip to content

Commit 4a4d0e5

Browse files
committed
fix api;
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
1 parent 45c0a0c commit 4a4d0e5

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func main() {
103103
}
104104

105105
func createRegistryClient(domain string) (*registry.Registry, error) {
106-
// Use the auth-url domain if provided
106+
// Use the auth-url domain if provided.
107107
authDomain := authURL
108108
if authDomain == "" {
109109
authDomain = domain
@@ -119,7 +119,8 @@ func createRegistryClient(domain string) (*registry.Registry, error) {
119119
}
120120

121121
// Create the registry client.
122-
return registry.New(domain, auth, registry.Opt{
122+
return registry.New(auth, registry.Opt{
123+
Domain: domain,
123124
Insecure: insecure,
124125
Debug: debug,
125126
SkipPing: skipPing,

registry/digest_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestDigestFromDockerHub(t *testing.T) {
1212
t.Fatalf("Could not get auth config: %s", err)
1313
}
1414

15-
r, err := New(auth.ServerAddress, auth, Opt{})
15+
r, err := New(auth, Opt{})
1616
if err != nil {
1717
t.Fatalf("Could not create registry instance: %s", err)
1818
}
@@ -33,7 +33,7 @@ func TestDigestFromGCR(t *testing.T) {
3333
t.Fatalf("Could not get auth config: %s", err)
3434
}
3535

36-
r, err := New(auth.ServerAddress, auth, Opt{})
36+
r, err := New(auth, Opt{})
3737
if err != nil {
3838
t.Fatalf("Could not create registry instance: %s", err)
3939
}

registry/registry.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func Log(format string, args ...interface{}) {
4141

4242
// Opt holds the options for a new registry.
4343
type Opt struct {
44+
Domain string
4445
Insecure bool
4546
Debug bool
4647
SkipPing bool
@@ -50,7 +51,7 @@ type Opt struct {
5051
}
5152

5253
// New creates a new Registry struct with the given URL and credentials.
53-
func New(domain string, auth types.AuthConfig, opt Opt) (*Registry, error) {
54+
func New(auth types.AuthConfig, opt Opt) (*Registry, error) {
5455
transport := http.DefaultTransport
5556

5657
if opt.Insecure {
@@ -61,11 +62,14 @@ func New(domain string, auth types.AuthConfig, opt Opt) (*Registry, error) {
6162
}
6263
}
6364

64-
return newFromTransport(domain, auth, transport, opt)
65+
return newFromTransport(auth, transport, opt)
6566
}
6667

67-
func newFromTransport(domain string, auth types.AuthConfig, transport http.RoundTripper, opt Opt) (*Registry, error) {
68-
url := strings.TrimSuffix(domain, "/")
68+
func newFromTransport(auth types.AuthConfig, transport http.RoundTripper, opt Opt) (*Registry, error) {
69+
if len(opt.Domain) < 1 {
70+
opt.Domain = auth.ServerAddress
71+
}
72+
url := strings.TrimSuffix(opt.Domain, "/")
6973
authURL := strings.TrimSuffix(auth.ServerAddress, "/")
7074

7175
if !reProtocol.MatchString(url) {
@@ -75,8 +79,13 @@ func newFromTransport(domain string, auth types.AuthConfig, transport http.Round
7579
url = "http://" + url
7680
}
7781
}
82+
7883
if !reProtocol.MatchString(authURL) {
79-
authURL = "https://" + authURL
84+
if !opt.NonSSL {
85+
authURL = "https://" + authURL
86+
} else {
87+
authURL = "http://" + authURL
88+
}
8089
}
8190

8291
tokenTransport := &TokenTransport{

registry/tokentransport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestErrBasicAuth(t *testing.T) {
2525
Password: "ss3j",
2626
ServerAddress: ts.URL,
2727
}
28-
r, err := New(authConfig.ServerAddress, authConfig, Opt{Insecure: true, Debug: true})
28+
r, err := New(authConfig, Opt{Insecure: true, Debug: true})
2929
if err != nil {
3030
t.Fatalf("expected no error creating client, got %v", err)
3131
}
@@ -78,7 +78,7 @@ func TestBothTokenAndAccessTokenWork(t *testing.T) {
7878
ServerAddress: ts.URL,
7979
}
8080
authConfig.Email = "me@email.com"
81-
r, err := New(ts.URL, authConfig, Opt{Insecure: true, Debug: true})
81+
r, err := New(authConfig, Opt{Insecure: true, Debug: true})
8282
if err != nil {
8383
t.Fatalf("expected no error creating client, got %v", err)
8484
}

0 commit comments

Comments
 (0)