Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 9 additions & 12 deletions cmd/src/version.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down