Skip to content

Commit

Permalink
Reuse token retrieve function in BrokerClient
Browse files Browse the repository at this point in the history
The MetaFunction used to retrieve IAM API Client tokens in the
BrokerClient created when initialising the Client creates a new Token
Retrieve Function and a Token Handler each time that it is called. This
means that an IAM call is made on every call and there is no IAM Token
reuse.  We fix this so that we create just the one handler and token
retrive function and reuse in the MetaFunction.
  • Loading branch information
eamonnotoole authored and mahesh-hpe committed Nov 22, 2024
1 parent 03fef2d commit 4cf81d3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/utils/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func SetMeta(apiClient *client.APIClient, r *schema.ResourceData) {

// SetMetaFnAndVersion sets the token-generation function and version for the Broker API client
func SetMetaFnAndVersion(apiClient *client.APIClient, r *schema.ResourceData, version int) {
// Initialise token handler
h, err := serviceclient.NewHandler(r)
if err != nil {
log.Printf("[WARN] Unable to create token handler: %s", err)
}
// Get token retrieve func
trf := retrieve.NewTokenRetrieveFunc(h)
// We'll use trf from above in this closure
apiClient.SetMetaFnAndVersion(nil, version, func(ctx *context.Context, meta interface{}) {
// Initialise token handler
h, err := serviceclient.NewHandler(r)
if err != nil {
log.Printf("[WARN] Unable to fetch token for SCM client: %s", err)
}

// Get token retrieve func and put in c
trf := retrieve.NewTokenRetrieveFunc(h)
token, err := trf(*ctx)
if err != nil {
log.Printf("[WARN] Unable to fetch token for SCM client: %s", err)
Expand Down

0 comments on commit 4cf81d3

Please sign in to comment.