feat: add credentials store override option in registry.Client

Signed-off-by: Eric Stroczynski <estroczynski@nvidia.com>
pull/31157/head
Eric Stroczynski 1 month ago
parent de9ea4d1e3
commit a57ac27e3f

@ -73,7 +73,6 @@ type (
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
@ -105,6 +104,7 @@ func NewClient(options ...ClientOption) (*Client, error) {
} }
} }
if client.credentialsStore == nil {
storeOptions := credentials.StoreOptions{ storeOptions := credentials.StoreOptions{
AllowPlaintextPut: true, AllowPlaintextPut: true,
DetectDefaultNativeStore: true, DetectDefaultNativeStore: true,
@ -121,6 +121,7 @@ func NewClient(options ...ClientOption) (*Client, error) {
// use Helm credentials with fallback to Docker // use Helm credentials with fallback to Docker
client.credentialsStore = credentials.NewStoreWithFallbacks(store, dockerStore) client.credentialsStore = credentials.NewStoreWithFallbacks(store, dockerStore)
} }
}
if client.authorizer == nil { if client.authorizer == nil {
authorizer := auth.Client{ authorizer := auth.Client{
@ -161,7 +162,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
@ -178,21 +180,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