pull/31157/merge
Eric Stroczynski 2 weeks ago committed by GitHub
commit e2a6cb0445
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -66,16 +66,15 @@ type (
debug bool debug bool
enableCache bool enableCache bool
// path to repository config file e.g. ~/.docker/config.json // path to repository config file e.g. ~/.docker/config.json
credentialsFile string credentialsFile string
username string username string
password string password string
out io.Writer out io.Writer
authorizer *auth.Client authorizer *auth.Client
registryAuthorizer RemoteClient credentialsStore credentials.Store
credentialsStore credentials.Store httpClient *http.Client
httpClient *http.Client plainHTTP bool
plainHTTP bool err error // pass any errors from the ClientOption functions
err error // pass any errors from the ClientOption functions
} }
// ClientOption allows specifying various settings configurable by the user for overriding the defaults // ClientOption allows specifying various settings configurable by the user for overriding the defaults
@ -103,21 +102,23 @@ func NewClient(options ...ClientOption) (*Client, error) {
} }
} }
storeOptions := credentials.StoreOptions{ if client.credentialsStore == nil {
AllowPlaintextPut: true, storeOptions := credentials.StoreOptions{
DetectDefaultNativeStore: true, AllowPlaintextPut: true,
} DetectDefaultNativeStore: true,
store, err := credentials.NewStore(client.credentialsFile, storeOptions) }
if err != nil { store, err := credentials.NewStore(client.credentialsFile, storeOptions)
return nil, err if err != nil {
} return nil, err
dockerStore, err := credentials.NewStoreFromDocker(storeOptions) }
if err != nil { dockerStore, err := credentials.NewStoreFromDocker(storeOptions)
// should only fail if user home directory can't be determined if err != nil {
client.credentialsStore = store // should only fail if user home directory can't be determined
} else { client.credentialsStore = store
// use Helm credentials with fallback to Docker } else {
client.credentialsStore = credentials.NewStoreWithFallbacks(store, dockerStore) // use Helm credentials with fallback to Docker
client.credentialsStore = credentials.NewStoreWithFallbacks(store, dockerStore)
}
} }
if client.authorizer == nil { if client.authorizer == nil {
@ -162,7 +163,8 @@ func ClientOptEnableCache(enableCache bool) ClientOption {
} }
} }
// ClientOptBasicAuth returns a function that sets the username and password setting on client options set // ClientOptBasicAuth returns a function that sets the username and password setting on client options set.
// This will override the configured/default credentials store in the default authorizer.
func ClientOptBasicAuth(username, password string) ClientOption { func ClientOptBasicAuth(username, password string) ClientOption {
return func(client *Client) { return func(client *Client) {
client.username = username client.username = username
@ -179,21 +181,17 @@ func ClientOptWriter(out io.Writer) ClientOption {
// ClientOptAuthorizer returns a function that sets the authorizer setting on a client options set. This // ClientOptAuthorizer returns a function that sets the authorizer setting on a client options set. This
// can be used to override the default authorization mechanism. // can be used to override the default authorization mechanism.
//
// Depending on the use-case you may need to set both ClientOptAuthorizer and ClientOptRegistryAuthorizer.
func ClientOptAuthorizer(authorizer auth.Client) ClientOption { func ClientOptAuthorizer(authorizer auth.Client) ClientOption {
return func(client *Client) { return func(client *Client) {
client.authorizer = &authorizer client.authorizer = &authorizer
} }
} }
// ClientOptRegistryAuthorizer returns a function that sets the registry authorizer setting on a client options set. This // ClientOptCredentialsStore returns a function that sets the credentialsStore setting on a client options set.
// can be used to override the default authorization mechanism. // This will override the default Helm/Docker on-disk credentials store.
// func ClientOptCredentialsStore(credentialsStore credentials.Store) ClientOption {
// Depending on the use-case you may need to set both ClientOptAuthorizer and ClientOptRegistryAuthorizer.
func ClientOptRegistryAuthorizer(registryAuthorizer RemoteClient) ClientOption {
return func(client *Client) { return func(client *Client) {
client.registryAuthorizer = registryAuthorizer client.credentialsStore = credentialsStore
} }
} }

Loading…
Cancel
Save