Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Automatically use token on disk if there is one
Rather than asking the user to confirm.  This only happens if we
explicitly want to use an existing token anyway, and "existing" is
defined in the help text as either the token on disk or one the user
already copied, so the extra confirmation to use the token on disk seems
unnecessary.
  • Loading branch information
code-asher committed Aug 16, 2023
commit aa453f4bdbf198bd57cf297dc39cd9db4fb3ed3f
25 changes: 17 additions & 8 deletions src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,25 @@ class CoderRemoteConnectionHandle {
): Pair<String, TokenSource>? {
var (existingToken, tokenSource) = token ?: Pair("", TokenSource.USER)
val getTokenUrl = url.withPath("/login?redirect=%2Fcli-auth")
if (!isRetry && !useExisting) {
BrowserUtil.browse(getTokenUrl)
} else if (!isRetry && useExisting) {
val (u, t) = CoderCLIManager.readConfig()
if (url == u?.toURL() && !t.isNullOrBlank() && t != existingToken) {
logger.info("Injecting token for $url from CLI config")
tokenSource = TokenSource.CONFIG
existingToken = t

// On the first run either open a browser to generate a new token
// or, if using an existing token, use the token on disk if it
// exists otherwise assume the user already copied an existing
// token and they will paste in.
if (!isRetry) {
if (!useExisting) {
BrowserUtil.browse(getTokenUrl)
} else {
val (u, t) = CoderCLIManager.readConfig()
if (url == u?.toURL() && !t.isNullOrBlank() && t != existingToken) {
logger.info("Injecting token for $url from CLI config")
return Pair(t, TokenSource.CONFIG)
}
}
}

// On subsequent tries or if not using an existing token, ask the user
// for the token.
val tokenFromUser = ask(
CoderGatewayBundle.message(
if (isRetry) "gateway.connector.view.workspaces.token.rejected"
Expand Down