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

impl: support for certificate based authentication#155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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
4 changes: 4 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,10 @@

## Unreleased

### Added

- support for certificate based authentication

## 0.5.0 - 2025-07-17

### Added
Expand Down
2 changes: 1 addition & 1 deletiongradle.properties
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
version=0.5.0
version=0.5.1
group=com.coder.toolbox
name=coder-toolbox
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ class CoderRemoteProvider(
environments.value = LoadableState.Value(emptyList())
isInitialized.update { false }
client = null
CoderCliSetupWizardState.resetSteps()
CoderCliSetupWizardState.goToFirstStep()
}

override val svgIcon: SvgIcon =
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -94,7 +94,10 @@ open class CoderRestClient(
.build()
}

if (token!=null) {
if (context.settingsStore.requireTokenAuth) {
if (token.isNullOrBlank()) {
throwIllegalStateException("Token is required for$url deployment")
}
builder= builder.addInterceptor {
it.proceed(
it.request().newBuilder().addHeader("Coder-Session-Token", token).build()
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ open class CoderProtocolHandler(

context.logger.info("Handling $uri...")
val deploymentURL = resolveDeploymentUrl(params) ?: return
val token = resolveToken(params) ?: return
val token =if (!context.settingsStore.requireTokenAuth) null elseresolveToken(params) ?: return
val workspaceName = resolveWorkspaceName(params) ?: return
val restClient = buildRestClient(deploymentURL, token) ?: return
val workspace = restClient.workspaces().matchName(workspaceName, deploymentURL) ?: return
Expand DownExpand Up@@ -128,7 +128,7 @@ open class CoderProtocolHandler(
return workspace
}

private suspend fun buildRestClient(deploymentURL: String, token: String): CoderRestClient? {
private suspend fun buildRestClient(deploymentURL: String, token: String?): CoderRestClient? {
try {
return authenticate(deploymentURL, token)
} catch (ex: Exception) {
Expand All@@ -140,11 +140,11 @@ open class CoderProtocolHandler(
/**
* Returns an authenticated Coder CLI.
*/
private suspend fun authenticate(deploymentURL: String, token: String): CoderRestClient {
private suspend fun authenticate(deploymentURL: String, token: String?): CoderRestClient {
val client = CoderRestClient(
context,
deploymentURL.toURL(),
if (settings.requireTokenAuth)token else null,
token,
PluginManager.pluginInfo.version
)
client.initializeSession()
Expand Down
20 changes: 12 additions & 8 deletionssrc/main/kotlin/com/coder/toolbox/views/ConnectStep.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,7 +47,7 @@ class ConnectStep(
context.i18n.pnotr("")
}

if (CoderCliSetupContext.isNotReadyForAuth()) {
if (context.settingsStore.requireTokenAuth &&CoderCliSetupContext.isNotReadyForAuth()) {
errorField.textState.update {
context.i18n.pnotr("URL and token were not properly configured. Please go back and provide a proper URL and token!")
}
Expand All@@ -67,7 +67,7 @@ class ConnectStep(
return
}

if (!CoderCliSetupContext.hasToken()) {
if (context.settingsStore.requireTokenAuth &&!CoderCliSetupContext.hasToken()) {
errorField.textState.update { context.i18n.ptrl("Token is required") }
return
}
Expand All@@ -77,7 +77,7 @@ class ConnectStep(
val client = CoderRestClient(
context,
CoderCliSetupContext.url!!,
CoderCliSetupContext.token!!,
if (context.settingsStore.requireTokenAuth)CoderCliSetupContext.token else null,
PluginManager.pluginInfo.version,
)
// allows interleaving with the back/cancel action
Expand All@@ -91,17 +91,17 @@ class ConnectStep(
statusField.textState.update { (context.i18n.pnotr(progress)) }
}
// We only need to log in if we are using token-based auth.
if (client.token != null) {
if (context.settingsStore.requireTokenAuth) {
statusField.textState.update { (context.i18n.ptrl("Configuring Coder CLI...")) }
// allows interleaving with the back/cancel action
yield()
cli.login(client.token)
cli.login(client.token!!)
}
statusField.textState.update { (context.i18n.ptrl("Successfully configured ${CoderCliSetupContext.url!!.host}...")) }
// allows interleaving with the back/cancel action
yield()
CoderCliSetupContext.reset()
CoderCliSetupWizardState.resetSteps()
CoderCliSetupWizardState.goToFirstStep()
onConnect(client, cli)
} catch (ex: CancellationException) {
if (ex.message != USER_HIT_THE_BACK_BUTTON) {
Expand All@@ -127,10 +127,14 @@ class ConnectStep(
} finally {
if (shouldAutoLogin.value) {
CoderCliSetupContext.reset()
CoderCliSetupWizardState.resetSteps()
CoderCliSetupWizardState.goToFirstStep()
context.secrets.rememberMe = false
} else {
CoderCliSetupWizardState.goToPreviousStep()
if (context.settingsStore.requireTokenAuth) {
CoderCliSetupWizardState.goToPreviousStep()
} else {
CoderCliSetupWizardState.goToFirstStep()
}
}
}
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -85,7 +85,11 @@ class DeploymentUrlStep(
notify("URL is invalid", e)
return false
}
CoderCliSetupWizardState.goToNextStep()
if (context.settingsStore.requireTokenAuth) {
CoderCliSetupWizardState.goToNextStep()
} else {
CoderCliSetupWizardState.goToLastStep()
}
return true
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,7 +25,11 @@ object CoderCliSetupWizardState {
currentStep=WizardStep.entries.toTypedArray()[(currentStep.ordinal-1)%WizardStep.entries.size]
}

funresetSteps() {
fungoToLastStep() {
currentStep=WizardStep.CONNECT
}

fungoToFirstStep() {
currentStep=WizardStep.URL_REQUEST
}
}
Expand Down
22 changes: 21 additions & 1 deletionsrc/test/kotlin/com/coder/toolbox/sdk/CoderRestClientTest.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -225,7 +225,7 @@ class CoderRestClientTest {
val client = CoderRestClient(context, URL(url), "token")
assertEquals(user.username, runBlocking { client.me() }.username)

val tests = listOf("invalid", null)
val tests = listOf("invalid")
tests.forEach { token ->
val ex =
assertFailsWith(
Expand All@@ -238,6 +238,26 @@ class CoderRestClientTest {
srv.stop(0)
}

@Test
fun `exception is raised when token is required for authentication and token value is null or empty`() {
listOf("", null).forEach { token ->
val ex =
assertFailsWith(
exceptionClass = IllegalStateException::class,
block = {
runBlocking {
CoderRestClient(
context,
URI.create("https://coder.com").toURL(),
token
).me()
}
},
)
assertEquals(ex.message, "Token is required for https://coder.com deployment")
}
}

@Test
fun testGetsWorkspaces() {
val tests =
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp