Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception with failing to open SSH channel with no yubikey key #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
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