Skip to content

Commit

Permalink
gophercloudext: add ClientOpts.CustomizeAuthOptions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
majewsky committed Nov 11, 2024
1 parent 667137c commit 267fb34
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gophercloudext/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 267fb34

Please sign in to comment.