You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix/login: override config endpoint if endpoint positional argument is given (#1300)
* determine if we are using the Default endpoint or not
* move notifce of config file deprecation earlier
* Move endpoint validation to happen before running loginCmd
- update config endpointURL if endpointURL is set either as a flag or
positional argument
- warn the user about endpoint conflict or that the default endpoint is
being used
* fix tests and remove unused login funcs
* move DefaultEndpointConfigured to be attr on struct
* fix tests
Copy file name to clipboardExpand all lines: cmd/src/login.go
+38-42Lines changed: 38 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -50,25 +50,43 @@ Examples:
50
50
returnerr
51
51
}
52
52
53
-
varloginEndpointURL*url.URL
53
+
ifcfg.configFilePath!="" {
54
+
fmt.Fprintln(os.Stderr)
55
+
fmt.Fprintf(os.Stderr, "⚠️ 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 %s. See https://github.com/sourcegraph/src-cli#readme for more information.\n", cfg.configFilePath)
// If the default is configured it means SRC_ENDPOINT is not set
69
+
ifcfg.usingDefaultEndpoint {
70
+
fmt.Fprintf(os.Stderr, "⚠️ Warning: No SRC_ENDPOINT is configured in the environment. Logging in using %q.\n", loginEndpointURL)
71
+
fmt.Fprintf(os.Stderr, "\n💡 Tip: To use this endpoint in your shell, run:\n\n export SRC_ENDPOINT=%s\n\nNOTE: By default src will use %q if SRC_ENDPOINT is not set.\n", loginEndpointURL, SGDotComEndpoint)
72
+
} else {
73
+
fmt.Fprintf(os.Stderr, "⚠️ Warning: Logging into %s instead of the configured endpoint %s.\n", loginEndpointURL, cfg.endpointURL)
74
+
fmt.Fprintf(os.Stderr, "\n💡 Tip: To use this endpoint in your shell, run:\n\n export SRC_ENDPOINT=%s\n\n", loginEndpointURL)
75
+
}
76
+
}
77
+
78
+
// An explicit endpoint on the CLI overrides the configured endpoint for this login.
fmt.Fprintf(p.out, "⚠️ 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 %s. See https://github.com/sourcegraph/src-cli#readme for more information.\n", p.cfg.configFilePath)
110
-
}
111
-
112
-
_, flow:=selectLoginFlow(p)
115
+
flow:=selectLoginFlow(p)
113
116
iferr:=flow(ctx, p); err!=nil {
114
117
returnerr
115
118
}
116
-
fmt.Fprintf(p.out, "\n💡 Tip: To use this endpoint in your shell, run:\n\n export SRC_ENDPOINT=%s\n\n", p.cfg.endpointURL)
117
119
returnnil
118
120
}
119
121
120
122
// selectLoginFlow decides what login flow to run based on configured AuthMode.
t.Fatal("expected stored oauth token to avoid device flow")
157
132
}
158
133
gotOut:=strings.TrimSpace(out.String())
159
-
wantOut:="✔︎ Authenticated as alice on $ENDPOINT\n\n\n✔︎ Authenticated with OAuth credentials\n\n💡 Tip: To use this endpoint in your shell, run:\n\n export SRC_ENDPOINT=$ENDPOINT"
134
+
wantOut:="✔︎ Authenticated as alice on $ENDPOINT\n\n\n✔︎ Authenticated with OAuth credentials"
0 commit comments