Skip to content

Commit

Permalink
add timeout and panic
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Nov 22, 2024
1 parent f5e710d commit 79858d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions internal/acceptance_test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package acceptancetest

import (
"context"
"fmt"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -66,7 +67,7 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) {
Host: cmpDetails.URL,
DefaultHeader: map[string]string{},
DefaultQueryParams: map[string]string{},
HTTPClient: &http.Client{Transport: tr},
HTTPClient: &http.Client{Transport: tr, Timeout: 2 * time.Minute},
}
cmpAPIClient := api_client.NewAPIClient(&cfg)
cmpAPIClient.CMPToken = cmpDetails.AccessToken
Expand Down Expand Up @@ -146,7 +147,7 @@ func apiClientSetMeta(apiClient *api_client.APIClient, iamVersion string) error
trf := retrieve.NewTokenRetrieveFunc(h)
token, err := trf(*ctx)
if err != nil {
log.Printf("[WARN] Unable to fetch token for SCM client: %s", err)
panic(fmt.Sprintf("[WARN] Unable to fetch token for SCM client: %s", err))
} else {
*ctx = context.WithValue(*ctx, api_client.ContextAccessToken, token)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"os"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand Down Expand Up @@ -82,7 +83,7 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error)
Host: vmaasProviderSettings[constants.BROKERRURL].(string),
DefaultHeader: brokerHeaders,
DefaultQueryParams: queryParam,
HTTPClient: &http.Client{Transport: tr},
HTTPClient: &http.Client{Transport: tr, Timeout: 2 * time.Minute},
}
brokerApiClient := api_client.NewAPIClient(&brokerCfgForAPIClient)
utils.SetMetaFnAndVersion(brokerApiClient, r, 0)
Expand All @@ -91,7 +92,7 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error)
Host: "",
DefaultHeader: map[string]string{},
DefaultQueryParams: map[string]string{},
HTTPClient: &http.Client{Transport: tr},
HTTPClient: &http.Client{Transport: tr, Timeout: 2 * time.Minute},
}
apiClient := api_client.NewAPIClient(&cfg)
err = utils.SetCMPVars(apiClient, brokerApiClient, &cfg)
Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"context"
"fmt"
"log"
"time"

Expand All @@ -23,7 +24,7 @@ func SetMeta(apiClient *client.APIClient, r *schema.ResourceData) {
trf := retrieve.NewTokenRetrieveFunc(h)
token, err := trf(*ctx)
if err != nil {
log.Printf("[WARN] Unable to fetch token for SCM client: %s", err)
panic(fmt.Sprintf("[WARN] Unable to fetch token for SCM client: %s", err))
} else {
*ctx = context.WithValue(*ctx, client.ContextAccessToken, token)
}
Expand Down

0 comments on commit 79858d7

Please sign in to comment.