Skip to content

Commit

Permalink
notification about touching yubikey when we have Timeout (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio authored Jun 18, 2024
1 parent 9c5a700 commit 6520d60
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/kotlin/com/vk/admstorm/ssh/SshConnectionService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vk.admstorm.ssh

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
Expand All @@ -14,6 +15,7 @@ import com.intellij.ssh.ConnectionBuilder
import com.intellij.ssh.ExecBuilder
import com.intellij.ssh.channels.SftpChannel
import com.intellij.ssh.connectionBuilder
import com.intellij.util.ConcurrencyUtil
import com.jetbrains.plugins.remotesdk.console.SshConfigConnector
import com.vk.admstorm.AdmStartupService
import com.vk.admstorm.notifications.AdmErrorNotification
Expand Down Expand Up @@ -123,6 +125,14 @@ class SshConnectionService(private var myProject: Project) : Disposable {
// Disconnect the current connection, if it exists.
disconnect()

val scheduler = ConcurrencyUtil.newSingleScheduledThreadExecutor("YubiKeyTouchingNotification")
scheduler.schedule({
ApplicationManager.getApplication().invokeLater {
AdmNotification("Did you forget to touch yubikey?")
.show()
}
}, 5, TimeUnit.SECONDS)

executeOnPooledThread {
// See also [com.jetbrains.plugins.remotesdk.tools.RemoteTool.startRemoteProcess]
@Suppress("UnstableApiUsage")
Expand Down Expand Up @@ -153,6 +163,8 @@ class SshConnectionService(private var myProject: Project) : Disposable {
onSuccessful?.run()
}
} catch (ex: OpenFailException) {
scheduler.shutdownNow()

val message = "${ex.message}<br>" +
"Plugin can try to automatically reset the Yubikey or you can do it yourself with " +
code("ssh-agent")
Expand All @@ -179,6 +191,8 @@ class SshConnectionService(private var myProject: Project) : Disposable {

LOG.warn("Failed to connect", ex)
} catch (ex: TimeoutException) {
scheduler.shutdownNow()

if (indicator.isCanceled) {
LOG.info("Cancelled by user", ex)
return
Expand All @@ -193,6 +207,8 @@ class SshConnectionService(private var myProject: Project) : Disposable {

LOG.info("Yubikey waiting timeout", ex)
} catch (ex: TransportException) {
scheduler.shutdownNow()

if (ex.message == null) {
LOG.error("Transport exception:", ex.javaClass.name)
return
Expand All @@ -217,6 +233,8 @@ class SshConnectionService(private var myProject: Project) : Disposable {
}).show()
LOG.info("Corporate access error", ex)
} catch (ex: Exception) {
scheduler.shutdownNow()

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

0 comments on commit 6520d60

Please sign in to comment.