|
|
@ -87,36 +87,40 @@ func NewClient(options ...ClientOption) (*Client, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client.authorizer = authClient
|
|
|
|
client.authorizer = authClient
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client.resolver = func(ref registry.Reference) (remotes.Resolver, error) {
|
|
|
|
|
|
|
|
headers := http.Header{}
|
|
|
|
if client.resolver == nil {
|
|
|
|
headers.Set("User-Agent", version.GetUserAgent())
|
|
|
|
client.resolver = func(ref registry.Reference) (remotes.Resolver, error) {
|
|
|
|
dockerClient, ok := client.authorizer.(*dockerauth.Client)
|
|
|
|
headers := http.Header{}
|
|
|
|
if ok {
|
|
|
|
headers.Set("User-Agent", version.GetUserAgent())
|
|
|
|
username, password, err := dockerClient.Credential(ref.Registry)
|
|
|
|
dockerClient, ok := client.authorizer.(*dockerauth.Client)
|
|
|
|
if err != nil {
|
|
|
|
if ok {
|
|
|
|
return nil, errors.New("unable to retrieve credentials")
|
|
|
|
username, password, err := dockerClient.Credential(ref.Registry)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
// A blank returned username and password value is a bearer token
|
|
|
|
return nil, errors.New("unable to retrieve credentials")
|
|
|
|
if username == "" && password != "" {
|
|
|
|
}
|
|
|
|
headers.Set("Authorization", fmt.Sprintf("Bearer %s", password))
|
|
|
|
// A blank returned username and password value is a bearer token
|
|
|
|
} else {
|
|
|
|
if username == "" && password != "" {
|
|
|
|
headers.Set("Authorization", fmt.Sprintf("Basic %s", basicAuth(username, password)))
|
|
|
|
headers.Set("Authorization", fmt.Sprintf("Bearer %s", password))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
headers.Set("Authorization", fmt.Sprintf("Basic %s", basicAuth(username, password)))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts := []auth.ResolverOption{auth.WithResolverHeaders(headers)}
|
|
|
|
opts := []auth.ResolverOption{auth.WithResolverHeaders(headers)}
|
|
|
|
if client.httpClient != nil {
|
|
|
|
if client.httpClient != nil {
|
|
|
|
opts = append(opts, auth.WithResolverClient(client.httpClient))
|
|
|
|
opts = append(opts, auth.WithResolverClient(client.httpClient))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if client.plainHTTP {
|
|
|
|
if client.plainHTTP {
|
|
|
|
opts = append(opts, auth.WithResolverPlainHTTP())
|
|
|
|
opts = append(opts, auth.WithResolverPlainHTTP())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resolver, err := client.authorizer.ResolverWithOpts(opts...)
|
|
|
|
resolver, err := client.authorizer.ResolverWithOpts(opts...)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolver, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resolver, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// allocate a cache if option is set
|
|
|
|
// allocate a cache if option is set
|
|
|
|
var cache registryauth.Cache
|
|
|
|
var cache registryauth.Cache
|
|
|
|
if client.enableCache {
|
|
|
|
if client.enableCache {
|
|
|
@ -202,7 +206,9 @@ func ClientOptPlainHTTP() ClientOption {
|
|
|
|
// ClientOptResolver returns a function that sets the resolver setting on a client options set
|
|
|
|
// ClientOptResolver returns a function that sets the resolver setting on a client options set
|
|
|
|
func ClientOptResolver(resolver remotes.Resolver) ClientOption {
|
|
|
|
func ClientOptResolver(resolver remotes.Resolver) ClientOption {
|
|
|
|
return func(client *Client) {
|
|
|
|
return func(client *Client) {
|
|
|
|
client.resolver = resolver
|
|
|
|
client.resolver = func(ref registry.Reference) (remotes.Resolver, error) {
|
|
|
|
|
|
|
|
return resolver, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|