Skip to content

Commit

Permalink
fix api;
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
  • Loading branch information
jessfraz committed Nov 14, 2018
1 parent 45c0a0c commit 4a4d0e5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() {
}

func createRegistryClient(domain string) (*registry.Registry, error) {
// Use the auth-url domain if provided
// Use the auth-url domain if provided.
authDomain := authURL
if authDomain == "" {
authDomain = domain
Expand All @@ -119,7 +119,8 @@ func createRegistryClient(domain string) (*registry.Registry, error) {
}

// Create the registry client.
return registry.New(domain, auth, registry.Opt{
return registry.New(auth, registry.Opt{
Domain: domain,
Insecure: insecure,
Debug: debug,
SkipPing: skipPing,
Expand Down
4 changes: 2 additions & 2 deletions registry/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestDigestFromDockerHub(t *testing.T) {
t.Fatalf("Could not get auth config: %s", err)
}

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

r, err := New(auth.ServerAddress, auth, Opt{})
r, err := New(auth, Opt{})
if err != nil {
t.Fatalf("Could not create registry instance: %s", err)
}
Expand Down
19 changes: 14 additions & 5 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Log(format string, args ...interface{}) {

// Opt holds the options for a new registry.
type Opt struct {
Domain string
Insecure bool
Debug bool
SkipPing bool
Expand All @@ -50,7 +51,7 @@ type Opt struct {
}

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

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

return newFromTransport(domain, auth, transport, opt)
return newFromTransport(auth, transport, opt)
}

func newFromTransport(domain string, auth types.AuthConfig, transport http.RoundTripper, opt Opt) (*Registry, error) {
url := strings.TrimSuffix(domain, "/")
func newFromTransport(auth types.AuthConfig, transport http.RoundTripper, opt Opt) (*Registry, error) {
if len(opt.Domain) < 1 {
opt.Domain = auth.ServerAddress
}
url := strings.TrimSuffix(opt.Domain, "/")
authURL := strings.TrimSuffix(auth.ServerAddress, "/")

if !reProtocol.MatchString(url) {
Expand All @@ -75,8 +79,13 @@ func newFromTransport(domain string, auth types.AuthConfig, transport http.Round
url = "http://" + url
}
}

if !reProtocol.MatchString(authURL) {
authURL = "https://" + authURL
if !opt.NonSSL {
authURL = "https://" + authURL
} else {
authURL = "http://" + authURL
}
}

tokenTransport := &TokenTransport{
Expand Down
4 changes: 2 additions & 2 deletions registry/tokentransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestErrBasicAuth(t *testing.T) {
Password: "ss3j",
ServerAddress: ts.URL,
}
r, err := New(authConfig.ServerAddress, authConfig, Opt{Insecure: true, Debug: true})
r, err := New(authConfig, Opt{Insecure: true, Debug: true})
if err != nil {
t.Fatalf("expected no error creating client, got %v", err)
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestBothTokenAndAccessTokenWork(t *testing.T) {
ServerAddress: ts.URL,
}
authConfig.Email = "me@email.com"
r, err := New(ts.URL, authConfig, Opt{Insecure: true, Debug: true})
r, err := New(authConfig, Opt{Insecure: true, Debug: true})
if err != nil {
t.Fatalf("expected no error creating client, got %v", err)
}
Expand Down

0 comments on commit 4a4d0e5

Please sign in to comment.