Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-11-14 10:18:18 -05:00
parent 45c0a0c5f9
commit 4a4d0e5d10
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
4 changed files with 21 additions and 11 deletions

View file

@ -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
@ -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,

View file

@ -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)
}
@ -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)
}

View file

@ -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
@ -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 {
@ -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) {
@ -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{

View file

@ -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)
}
@ -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)
}