Skip to content

Commit

Permalink
update atf
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Nov 8, 2024
1 parent ee5be5a commit c9ca794
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions internal/acceptance_test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"strconv"
"time"

api_client "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/client"
"github.com/HewlettPackard/hpegl-vmaas-terraform-resources/pkg/constants"
Expand Down Expand Up @@ -61,14 +62,26 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) {
DefaultQueryParams: map[string]string{},
}
cmpAPIClient := api_client.NewAPIClient(&cfg)
cmpAPIClient.CMPToken = cmpDetails.AccessToken
cmpAPIClient.TokenExpiry = cmpDetails.ValidTill
cmpAPIClient.SetMetaFnAndVersion(nil, 0, func(ctx *context.Context, meta interface{}) {
// Initialise token handler
cmpDetails, err := brokerClient.GetCMPDetails(*ctx)
if err != nil {
log.Printf("[ERROR] Unable to fetch token for CMP client: %s", err)
} else {
*ctx = context.WithValue(*ctx, api_client.ContextAccessToken, cmpDetails.AccessToken)
tokenExpiry := cmpAPIClient.TokenExpiry/1000 - 15
token := cmpAPIClient.CMPToken
// Token is about to expire and get new
if tokenExpiry < time.Now().Unix() {
cmpDetails, err := brokerClient.GetCMPDetails(*ctx)
if err != nil {
log.Printf("[ERROR] Unable to fetch token for CMP client: %s", err)
panic("Unable to renew token")
} else {
token = cmpDetails.AccessToken
cmpAPIClient.CMPToken = cmpDetails.AccessToken
cmpAPIClient.TokenExpiry = cmpDetails.ValidTill
}

}
*ctx = context.WithValue(*ctx, api_client.ContextAccessToken, token)
})
ctx = context.WithValue(ctx, api_client.ContextAccessToken, cmpDetails.AccessToken)
err = cmpAPIClient.SetCMPVersion(ctx)
Expand Down

0 comments on commit c9ca794

Please sign in to comment.