Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaefcc31

Browse files
committed
Extract setting source description
This will let us use it in auth flows that are not dialog-based like thecurrent auth flow. In the future both flows might be refactored toshare a code path but holding off on that until it becomes apparentthere is a good interface for that.
1 parentabe0326 commitaefcc31

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

‎src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ enum class Source {
2828
QUERY,// From the Gateway link as a query parameter.
2929
SETTINGS,// Pulled from settings.
3030
USER,// Input by the user.
31+
;
32+
33+
/**
34+
* Return a description of the source.
35+
*/
36+
fundescription(name:String,url:URL):String=when (this) {
37+
CONFIG->"This$name was pulled from your global CLI config."
38+
DEPLOYMENT_CONFIG->"This$name was pulled from your CLI config for${url.host}."
39+
LAST_USED->"This last used$name for${url.host}."
40+
QUERY->"This$name was pulled from the Gateway link from${url.host}."
41+
USER->"The last used$name for${url.host}."
42+
ENVIRONMENT->"This$name was pulled from an environment variable."
43+
SETTINGS->"This$name was pulled from your settings for Coder Gateway."
44+
}
3145
}
3246

3347
openclassCoderSettingsState(

‎src/main/kotlin/com/coder/gateway/util/Dialogs.kt

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class DialogUi(
185185
isRetry:Boolean,
186186
useExisting:Boolean,
187187
):Pair<String,Source>? {
188-
var (existingToken, tokenSource)= token?:Pair("",Source.USER)
189188
val getTokenUrl= url.withPath("/login?redirect=%2Fcli-auth")
190189

191190
// On the first run either open a browser to generate a new token
@@ -199,7 +198,7 @@ class DialogUi(
199198
// Look on disk in case we already have a token, either in
200199
// the deployment's config or the global config.
201200
val tryToken= settings.token(url)
202-
if (tryToken!=null&& tryToken.first!=existingToken) {
201+
if (tryToken!=null&& tryToken.first!=token?.first) {
203202
return tryToken
204203
}
205204
}
@@ -212,29 +211,19 @@ class DialogUi(
212211
title="Session Token",
213212
description=if (isRetry) {
214213
"This token was rejected by${url.host}."
215-
}elseif (tokenSource==Source.CONFIG) {
216-
"This token was pulled from your global CLI config."
217-
}elseif (tokenSource==Source.DEPLOYMENT_CONFIG) {
218-
"This token was pulled from your CLI config for${url.host}."
219-
}elseif (tokenSource==Source.LAST_USED) {
220-
"This token was the last used token for${url.host}."
221-
}elseif (tokenSource==Source.QUERY) {
222-
"This token was pulled from the Gateway link from${url.host}."
223-
}elseif (existingToken.isNotBlank()) {
224-
"The last used token for${url.host} is shown above."
225214
}else {
226-
"No existing token for${url.host} found."
215+
token?.second?.description("token", url)
216+
?:"No existing token for${url.host} found."
227217
},
228-
placeholder=existingToken,
218+
placeholder=token?.first,
229219
link=Pair("Session Token:", getTokenUrl.toString()),
230220
isError= isRetry,
231221
)
232222
if (tokenFromUser.isNullOrBlank()) {
233223
returnnull
234224
}
235-
if (tokenFromUser!= existingToken) {
236-
tokenSource=Source.USER
237-
}
238-
returnPair(tokenFromUser, tokenSource)
225+
// If the user submitted the same token, keep the same source too.
226+
val source=if (tokenFromUser== token?.first) token.secondelseSource.USER
227+
returnPair(tokenFromUser, source)
239228
}
240229
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp