diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index 37a25833f..41fb661d8 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -2,10 +2,9 @@ package cliutils import ( "encoding/json" + "errors" "fmt" "github.com/jfrog/gofrog/version" - "github.com/jfrog/jfrog-client-go/http/httpclient" - "github.com/jfrog/jfrog-client-go/utils/io/httputils" "io" "net/http" "os" @@ -28,7 +27,6 @@ import ( "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/utils/io/content" "github.com/jfrog/jfrog-client-go/utils/log" - "github.com/pkg/errors" "github.com/urfave/cli" ) @@ -822,11 +820,15 @@ func shouldCheckLatestCliVersion() (shouldCheck bool, err error) { } func getLatestCliVersionFromGithubAPI() (githubVersionInfo githubResponse, err error) { - client, err := httpclient.ClientBuilder().Build() - if err != nil { + client := &http.Client{Timeout: time.Second * 2} + if errorutils.CheckError(err) != nil { + return + } + req, err := http.NewRequest(http.MethodGet, "https://api.github.com/repos/jfrog/jfrog-cli/releases/latest", nil) + if errorutils.CheckError(err) != nil { return } - resp, body, _, err := client.SendGet("https://api.github.com/repos/jfrog/jfrog-cli/releases/latest", true, httputils.HttpClientDetails{HttpTimeout: time.Second * 2}, "") + resp, body, err := doHttpRequest(client, req) if err != nil { err = errors.New("couldn't get latest JFrog CLI latest version info from GitHub API: " + err.Error()) return @@ -838,3 +840,19 @@ func getLatestCliVersionFromGithubAPI() (githubVersionInfo githubResponse, err e err = json.Unmarshal(body, &githubVersionInfo) return } + +func doHttpRequest(client *http.Client, req *http.Request) (resp *http.Response, body []byte, err error) { + req.Close = true + resp, err = client.Do(req) + if errorutils.CheckError(err) != nil { + return + } + defer func() { + if resp != nil && resp.Body != nil { + e := errorutils.CheckError(resp.Body.Close()) + err = errors.Join(err, e) + } + }() + body, err = io.ReadAll(resp.Body) + return resp, body, errorutils.CheckError(err) +}