diff --git a/CHANGELOG.md b/CHANGELOG.md index e237c1035f..0698f8d5b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file. ### Fixed +- The src version command didn't send any authentication headers before, which could have failed for some instance configurations. The authentication header is now properly set for the request done in this command. [#411](https://github.com/sourcegraph/src-cli/pull/411) + ### Removed ## 3.23.0 diff --git a/cmd/src/version.go b/cmd/src/version.go index a6e8f5f1db..a80d7269f3 100644 --- a/cmd/src/version.go +++ b/cmd/src/version.go @@ -1,12 +1,14 @@ package main import ( + "context" "encoding/json" "flag" "fmt" "io/ioutil" "net/http" - "net/url" + + "github.com/sourcegraph/src-cli/internal/api" ) // buildTag is the git tag at the time of build and is used to @@ -25,10 +27,13 @@ Examples: flagSet := flag.NewFlagSet("version", flag.ExitOnError) + var apiFlags = api.NewFlags(flagSet) + handler := func(args []string) error { fmt.Printf("Current version: %s\n", buildTag) - recommendedVersion, err := getRecommendedVersion() + client := cfg.apiClient(apiFlags, flagSet.Output()) + recommendedVersion, err := getRecommendedVersion(context.Background(), client) if err != nil { return err } @@ -53,20 +58,12 @@ Examples: }) } -func getRecommendedVersion() (string, error) { - url, err := url.Parse(cfg.Endpoint + "/.api/src-cli/version") +func getRecommendedVersion(ctx context.Context, client api.Client) (string, error) { + req, err := client.NewHTTPRequest(ctx, "GET", ".api/src-cli/version", nil) if err != nil { return "", err } - req, err := http.NewRequest("GET", url.String(), nil) - if err != nil { - return "", err - } - for k, v := range cfg.AdditionalHeaders { - req.Header.Set(k, v) - } - resp, err := http.DefaultClient.Do(req) if err != nil { return "", err