mirror of
https://github.com/genuinetools/reg.git
synced 2024-05-13 01:38:32 -04:00
fix api;
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
parent
45c0a0c5f9
commit
4a4d0e5d10
5
main.go
5
main.go
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue