From 1caf41f1cf73532e4874be7f2f4dd0daecb14613 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 21 Nov 2023 12:53:31 -0800 Subject: [PATCH] Make the authorizer and registry authorizer configurable Fixes: #12584 This change makes the authorizer and registryAuthorizer of the registry client configurable via options. This allows Go SDK users to override the authentication behavior of the client. This PR makes both the authorizer and registryAuthorizer configurable because depending on the exact scenario that may be needed. The default registryAuthorizer only supports a specific implementation of the authorizer. Signed-off-by: Ryan Nowak --- pkg/registry/client.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/registry/client.go b/pkg/registry/client.go index 7538cf69b..aba4eeee2 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -175,6 +175,26 @@ func ClientOptWriter(out io.Writer) ClientOption { } } +// ClientOptAuthorizer returns a function that sets the authorizer setting on a client options set. This +// 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 { + return func(client *Client) { + client.authorizer = authorizer + } +} + +// ClientOptRegistryAuthorizer returns a function that sets the registry authorizer setting on a client options set. This +// can be used to override the default authorization mechanism. +// +// Depending on the use-case you may need to set both ClientOptAuthorizer and ClientOptRegistryAuthorizer. +func ClientOptRegistryAuthorizer(registryAuthorizer *registryauth.Client) ClientOption { + return func(client *Client) { + client.registryAuthorizer = registryAuthorizer + } +} + // ClientOptCredentialsFile returns a function that sets the credentialsFile setting on a client options set func ClientOptCredentialsFile(credentialsFile string) ClientOption { return func(client *Client) {