CLI: fix keyring backend bug

This commit is contained in:
2026-09-01 14:09:37 +02:00
parent 768bb0c650
commit 7f92df1ca5
3 changed files with 10 additions and 3 deletions
+3 -1
View File
@@ -80,7 +80,9 @@ kotlin {
} }
tasks.withType<ShadowJar> { tasks.withType<ShadowJar> {
archiveFileName = if(isDebug) "phoebench-cli-debug.jar" else "phoebench-cli.jar" val archive = if(isDebug) "phoebench-cli-debug.jar" else "phoebench-cli.jar"
println("Using archive '$archive'")
archiveFileName = archive
} }
buildConfig { buildConfig {
@@ -14,7 +14,7 @@ object AuthHandlers {
if (handshake.version != ProtocolVersion.VERSION) { if (handshake.version != ProtocolVersion.VERSION) {
Client.onClearServer() Client.onClearServer()
ErrorResponse("Mismatched protocol version (server: ${handshake.version}, client: ${ProtocolVersion.VERSION})").error() ErrorResponse("Mismatched protocol version (server: ${handshake.version}, client: ${ProtocolVersion.VERSION})").error()
} else Unit.value() } else Client.onSelectServer(useServer).value()
} }
} }
} }
@@ -2,6 +2,7 @@ package com.jaytux.phoebench.clients.cli
import com.github.javakeyring.BackendNotSupportedException import com.github.javakeyring.BackendNotSupportedException
import com.github.javakeyring.Keyring import com.github.javakeyring.Keyring
import com.github.javakeyring.PasswordAccessException
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.serializer import kotlinx.serialization.serializer
@@ -22,7 +23,11 @@ object PersistentStorage {
private object KeyringBackend : IBackend { private object KeyringBackend : IBackend {
override fun read(key: String): String? = try { override fun read(key: String): String? = try {
Keyring.create().use { it.getPassword(SERVICE, key) } Keyring.create().use { it.getPassword(SERVICE, key) }
} catch(e: Exception) { }
catch(e: PasswordAccessException) {
return null
}
catch(e: BackendNotSupportedException) {
_backend = PreferencesBackend _backend = PreferencesBackend
_backend.read(key) _backend.read(key)
} }