From 267fb34edbcf44c7d221b15a70b9d3b2217be5c4 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Mon, 11 Nov 2024 14:31:25 +0100 Subject: [PATCH] gophercloudext: add ClientOpts.CustomizeAuthOptions Castellum needs a special affordance here because it wants to be able to use its cloud_admin credentials to scope into customer projects for some specific operations. --- gophercloudext/auth.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gophercloudext/auth.go b/gophercloudext/auth.go index ba0db89..a68f128 100644 --- a/gophercloudext/auth.go +++ b/gophercloudext/auth.go @@ -50,6 +50,13 @@ type ClientOpts struct { // gophercloud.ProviderClient insists on taking ownership of whatever is // given here, so we cannot just give http.DefaultClient here. HTTPClient *http.Client + + // CustomizeAuthOptions is a callback that can be used to modify the + // constructed AuthOptions before they are passed to the ProviderClient. + // + // This is used in rare special cases, e.g. when an application needs to + // spawn clients with different token scopes for specific operations. + CustomizeAuthOptions func(*gophercloud.AuthOptions) } // NewProviderClient authenticates with OpenStack using the credentials found @@ -128,6 +135,9 @@ func NewProviderClient(ctx context.Context, optsPtr *ClientOpts) (*gophercloud.P ApplicationCredentialID: os.Getenv(opts.EnvPrefix + "APPLICATION_CREDENTIAL_ID"), ApplicationCredentialSecret: os.Getenv(opts.EnvPrefix + "APPLICATION_CREDENTIAL_SECRET"), } + if opts.CustomizeAuthOptions != nil { + opts.CustomizeAuthOptions(&ao) + } provider, err := openstack.NewClient(ao.IdentityEndpoint) if err == nil {