Skip to content

Commit

Permalink
fixed exception whe yubikey have no key and trying to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Oct 3, 2024
1 parent 3f0d502 commit 55bbf89
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/main/kotlin/com/vk/admstorm/ssh/SshConnectionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,7 @@ class SshConnectionService(private var myProject: Project) : Disposable {
"Plugin can try to automatically reset the Yubikey or you can do it yourself with " +
code("ssh-agent")

AdmErrorNotification(message, true)
.withTitle("Failed to connect to server")
.withActions(AdmNotification.Action("Reset Yubikey and Connect...") { _, notification ->
notification.expire()

val success = YubikeyHandler().autoReset(project) {
connectWithConnector(connector, onSuccessful)
}

if (!success) {
return@Action
}
connectWithConnector(connector, onSuccessful)
})
.withActions(AdmNotification.Action("Connect...") { _, notification ->
notification.expire()
connectWithConnector(connector, onSuccessful)
})
.show()
resetYubikeyNotification(message)

LOG.warn("Failed to connect", ex)
} catch (ex: TimeoutException) {
Expand Down Expand Up @@ -235,13 +217,49 @@ class SshConnectionService(private var myProject: Project) : Disposable {
} catch (ex: Exception) {
scheduler.shutdownNow()

if (ex.message?.contains("Failed to open SSH channel in a just created TCP session") == true) {
handleOpenTcpSessionError()
return
}

val exceptionName = ex.javaClass.name
LOG.error("Unhandled exception", ex)
AdmErrorNotification("Unhandled exception $exceptionName").show()
return
}
}

fun resetYubikeyNotification(message: String) {
AdmErrorNotification(message, true)
.withTitle("Failed to connect to server")
.withActions(AdmNotification.Action("Reset Yubikey and Connect...") { _, notification ->
notification.expire()

val success = YubikeyHandler().autoReset(project) {
connectWithConnector(connector, onSuccessful)
}

if (!success) {
return@Action
}
connectWithConnector(connector, onSuccessful)
})
.withActions(AdmNotification.Action("Connect...") { _, notification ->
notification.expire()
connectWithConnector(connector, onSuccessful)
})
.show()
}

fun handleOpenTcpSessionError() {
val message = "Failed to open SSH channel in a just created TCP session"
resetYubikeyNotification(message)
LOG.warn(
"Failed to connect",
OpenFailException("TCP", OpenFailException.Reason.CONNECT_FAILED, message)
)
}

override fun onCancel() {
super.onCancel()
cancelled = true
Expand Down

0 comments on commit 55bbf89

Please sign in to comment.