Skip to content

Commit ab6791e

Browse files
authored
Access token err msg (#1121)
* Bugfix: Improved access token error msg * Bugfix: Added replace directive for sourcegraph-public-snapshot in go.mod * Updated login tests.
1 parent 177b25b commit ab6791e

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

cmd/src/login.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ func loginCmd(ctx context.Context, cfg *config, client api.Client, endpointArg s
7171
fmt.Fprintf(out, "❌ Problem: %s\n", problem)
7272
}
7373

74-
createAccessTokenMessage := fmt.Sprintf("\n"+`🛠 To fix: Create an access token at %s/user/settings/tokens, then set the following environment variables:
74+
createAccessTokenMessage := fmt.Sprintf("\n"+`🛠 To fix: Create an access token by going to %s/user/settings/tokens, then set the following environment variables in your terminal:
7575
76-
SRC_ENDPOINT=%s
77-
SRC_ACCESS_TOKEN=(the access token you just created)
76+
export SRC_ENDPOINT=%s
77+
export SRC_ACCESS_TOKEN=(your access token)
7878
79-
To verify that it's working, run this command again.
79+
To verify that it's working, run the login command again.
8080
`, endpointArg, endpointArg)
8181

8282
if cfg.ConfigFilePath != "" {

cmd/src/login_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestLogin(t *testing.T) {
2727
if err != cmderrors.ExitCode1 {
2828
t.Fatal(err)
2929
}
30-
wantOut := "❌ Problem: No access token is configured.\n\n🛠 To fix: Create an access token at https://sourcegraph.example.com/user/settings/tokens, then set the following environment variables:\n\n SRC_ENDPOINT=https://sourcegraph.example.com\n SRC_ACCESS_TOKEN=(the access token you just created)\n\n To verify that it's working, run this command again."
30+
wantOut := "❌ Problem: No access token is configured.\n\n🛠 To fix: Create an access token by going to https://sourcegraph.example.com/user/settings/tokens, then set the following environment variables in your terminal:\n\n export SRC_ENDPOINT=https://sourcegraph.example.com\n export SRC_ACCESS_TOKEN=(your access token)\n\n To verify that it's working, run the login command again."
3131
if out != wantOut {
3232
t.Errorf("got output %q, want %q", out, wantOut)
3333
}
@@ -38,7 +38,7 @@ func TestLogin(t *testing.T) {
3838
if err != cmderrors.ExitCode1 {
3939
t.Fatal(err)
4040
}
41-
wantOut := "❌ Problem: No access token is configured.\n\n🛠 To fix: Create an access token at https://sourcegraph.example.com/user/settings/tokens, then set the following environment variables:\n\n SRC_ENDPOINT=https://sourcegraph.example.com\n SRC_ACCESS_TOKEN=(the access token you just created)\n\n To verify that it's working, run this command again."
41+
wantOut := "❌ Problem: No access token is configured.\n\n🛠 To fix: Create an access token by going to https://sourcegraph.example.com/user/settings/tokens, then set the following environment variables in your terminal:\n\n export SRC_ENDPOINT=https://sourcegraph.example.com\n export SRC_ACCESS_TOKEN=(your access token)\n\n To verify that it's working, run the login command again."
4242
if out != wantOut {
4343
t.Errorf("got output %q, want %q", out, wantOut)
4444
}
@@ -49,7 +49,7 @@ func TestLogin(t *testing.T) {
4949
if err != cmderrors.ExitCode1 {
5050
t.Fatal(err)
5151
}
52-
wantOut := "⚠️ Warning: Configuring src with a JSON file is deprecated. Please migrate to using the env vars SRC_ENDPOINT, SRC_ACCESS_TOKEN, and SRC_PROXY instead, and then remove f. See https://github.com/sourcegraph/src-cli#readme for more information.\n\n❌ Problem: No access token is configured.\n\n🛠 To fix: Create an access token at https://example.com/user/settings/tokens, then set the following environment variables:\n\n SRC_ENDPOINT=https://example.com\n SRC_ACCESS_TOKEN=(the access token you just created)\n\n To verify that it's working, run this command again."
52+
wantOut := "⚠️ Warning: Configuring src with a JSON file is deprecated. Please migrate to using the env vars SRC_ENDPOINT, SRC_ACCESS_TOKEN, and SRC_PROXY instead, and then remove f. See https://github.com/sourcegraph/src-cli#readme for more information.\n\n❌ Problem: No access token is configured.\n\n🛠 To fix: Create an access token by going to https://example.com/user/settings/tokens, then set the following environment variables in your terminal:\n\n export SRC_ENDPOINT=https://example.com\n export SRC_ACCESS_TOKEN=(your access token)\n\n To verify that it's working, run the login command again."
5353
if out != wantOut {
5454
t.Errorf("got output %q, want %q", out, wantOut)
5555
}
@@ -67,7 +67,7 @@ func TestLogin(t *testing.T) {
6767
if err != cmderrors.ExitCode1 {
6868
t.Fatal(err)
6969
}
70-
wantOut := "❌ Problem: Invalid access token.\n\n🛠 To fix: Create an access token at $ENDPOINT/user/settings/tokens, then set the following environment variables:\n\n SRC_ENDPOINT=$ENDPOINT\n SRC_ACCESS_TOKEN=(the access token you just created)\n\n To verify that it's working, run this command again.\n\n (If you need to supply custom HTTP request headers, see information about SRC_HEADER_* and SRC_HEADERS env vars at https://github.com/sourcegraph/src-cli/blob/main/AUTH_PROXY.md.)"
70+
wantOut := "❌ Problem: Invalid access token.\n\n🛠 To fix: Create an access token by going to $ENDPOINT/user/settings/tokens, then set the following environment variables in your terminal:\n\n export SRC_ENDPOINT=$ENDPOINT\n export SRC_ACCESS_TOKEN=(your access token)\n\n To verify that it's working, run the login command again.\n\n (If you need to supply custom HTTP request headers, see information about SRC_HEADER_* and SRC_HEADERS env vars at https://github.com/sourcegraph/src-cli/blob/main/AUTH_PROXY.md.)"
7171
wantOut = strings.ReplaceAll(wantOut, "$ENDPOINT", endpoint)
7272
if out != wantOut {
7373
t.Errorf("got output %q, want %q", out, wantOut)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,4 @@ require (
196196

197197
// See: https://github.com/ghodss/yaml/pull/65
198198
replace github.com/ghodss/yaml => github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152
199+
replace github.com/sourcegraph/sourcegraph/lib => github.com/sourcegraph/sourcegraph-public-snapshot/lib v0.0.0-20240709083501-1af563b61442

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ github.com/sourcegraph/log v0.0.0-20231018134238-fbadff7458bb h1:tHKdC+bXxxGJ0cy
388388
github.com/sourcegraph/log v0.0.0-20231018134238-fbadff7458bb/go.mod h1:IDp09QkoqS8Z3CyN2RW6vXjgABkNpDbyjLIHNQwQ8P8=
389389
github.com/sourcegraph/scip v0.3.1-0.20230627154934-45df7f6d33fc h1:o+eq0cjVV3B5ngIBF04Lv3GwttKOuYFF5NTcfXWXzfA=
390390
github.com/sourcegraph/scip v0.3.1-0.20230627154934-45df7f6d33fc/go.mod h1:7ZKAtLIUmiMvOIgG5LMcBxdtBXVa0v2GWC4Hm1ASYQ0=
391-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20240709083501-1af563b61442 h1:n3HZCz5fJRtxCzjcUHZwrfJb96xU0+s2L4/+Da2kD3A=
392-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20240709083501-1af563b61442/go.mod h1:RBdAauod1tGL33L1Izr2YymwN8uWQV++fL6orhD4aqc=
391+
github.com/sourcegraph/sourcegraph-public-snapshot/lib v0.0.0-20240709083501-1af563b61442 h1:M/jSgKSzeYbfrE/C6H8b8zu07c59taz4fIQcOGh1vqY=
392+
github.com/sourcegraph/sourcegraph-public-snapshot/lib v0.0.0-20240709083501-1af563b61442/go.mod h1:RBdAauod1tGL33L1Izr2YymwN8uWQV++fL6orhD4aqc=
393393
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
394394
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
395395
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=

0 commit comments

Comments
 (0)