Skip to content

Commit

Permalink
switch to new client
Browse files Browse the repository at this point in the history
  • Loading branch information
hugorut committed Mar 5, 2024
1 parent bfaffd4 commit 517b730
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 3 additions & 6 deletions cmd/infracost/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,14 +943,11 @@ func checkAPIKeyIsValid(ctx *config.RunContext, next runCommandFunc) runCommandF
"if you continue having issues.")
}

pricingClient := apiclient.GetPricingAPIClient(ctx)
resp, err := pricingClient.DoQueries([]apiclient.GraphQLQuery{
pricingClient := apiclient.NewPricingAPIClient(ctx)
_, err := pricingClient.DoQueries([]apiclient.GraphQLQuery{
{},
})
if len(resp) > 0 {
cmd.Println(resp[0])
}
//cmd.Println(err)

var apiError *apiclient.APIError
if errors.As(err, &apiError) {
if apiError.ErrorCode == apiclient.ErrorCodeAPIKeyInvalid {
Expand Down
15 changes: 13 additions & 2 deletions internal/apiclient/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ func GetPricingAPIClient(ctx *config.RunContext) *PricingAPIClient {
return pricingClient
}

c := NewPricingAPIClient(ctx)

initCache(ctx, c)
pricingClient = c
return c
}

// NewPricingAPIClient creates a new instance of PricingAPIClient using the given
// RunContext configuration. Most callers should use GetPricingAPIClient instead
// of this function to ensure that the client cache is global across the
// application. This function is useful for creating isolated pricing clients
// which do not share the global cache.
func NewPricingAPIClient(ctx *config.RunContext) *PricingAPIClient {
if ctx == nil {
return nil
}
Expand Down Expand Up @@ -129,8 +142,6 @@ func GetPricingAPIClient(ctx *config.RunContext) *PricingAPIClient {
EventsDisabled: ctx.Config.EventsDisabled,
}

initCache(ctx, c)
pricingClient = c
return c
}

Expand Down

0 comments on commit 517b730

Please sign in to comment.