From 86031f3ee1dc63db4e9544c1935c791cdc0d54d9 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Wed, 16 Aug 2023 09:39:10 -0500 Subject: [PATCH] Fix: env0_agent_values data source doesn't fetch values (#694) --- client/http/client.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/client/http/client.go b/client/http/client.go index 1efb5df5..35768fcb 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -3,6 +3,8 @@ package http //go:generate mockgen -destination=client_mock.go -package=http . HttpClientInterface import ( + "reflect" + "github.com/go-resty/resty/v2" ) @@ -76,11 +78,22 @@ func (client *HttpClient) Put(path string, request interface{}, response interfa } func (client *HttpClient) Get(path string, params map[string]string, response interface{}) error { - result, err := client.request(). - SetQueryParams(params). - SetResult(response). - Get(path) - return client.httpResult(result, err) + request := client.request().SetQueryParams(params) + + responseType := reflect.TypeOf(response) + + if responseType.Kind() == reflect.Ptr && responseType.Elem().Kind() == reflect.String { + responseStrPtr := response.(*string) + + result, err := request.Get(path) + if err == nil { + *responseStrPtr = string(result.Body()) + } + + return client.httpResult(result, err) + } else { + return client.httpResult(request.SetResult(response).Get(path)) + } } func (client *HttpClient) Delete(path string, params map[string]string) error {