Search in sources :

Example 1 with TunnelProxy

use of com.microsoft.azure.toolkit.lib.appservice.TunnelProxy in project azure-tools-for-java by Microsoft.

the class SSHIntoWebAppAction method actionPerformed.

@Override
protected void actionPerformed(NodeActionEvent nodeActionEvent) throws AzureCmdException {
    logger.info(message("webapp.ssh.hint.startSSH", webAppName));
    // ssh to connect to remote web app container.
    final AzureString title = title("webapp|ssh.connect", webAppName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final TunnelProxy proxy = new TunnelProxy(webApp);
        int localPort;
        try {
            localPort = proxy.start();
        } catch (IOException e) {
            try {
                proxy.close();
            } catch (Throwable ex) {
            // ignore
            }
            throw new AzureToolkitRuntimeException(message("webapp.ssh.error.message"));
        }
        final int finalLocalPort = localPort;
        // ssh to local proxy and open terminal.
        AzureTaskManager.getInstance().runAndWait(() -> {
            // create a new terminal tab.
            TerminalView terminalView = TerminalView.getInstance(project);
            ShellTerminalWidget shellTerminalWidget = terminalView.createLocalShellWidget(null, String.format(WEBAPP_TERMINAL_TABLE_NAME, webAppName));
            final AzureString messageTitle = title("webapp|ssh.open", webAppName);
            AzureTaskManager.getInstance().runInBackground(new AzureTask(project, messageTitle, false, () -> {
                // create connection to the local proxy.
                final SSHTerminalManager.CreateRemoteConnectionInfo info = new SSHTerminalManager.CreateRemoteConnectionInfo();
                info.setUsername(TunnelProxy.DEFAULT_SSH_USERNAME);
                info.setPassword(TunnelProxy.DEFAULT_SSH_PASSWORD);
                info.setPort(finalLocalPort);
                SSHTerminalManager.INSTANCE.openConnectionInTerminal(shellTerminalWidget, info);
            }));
        }, AzureTask.Modality.ANY);
    }));
    logger.info(message("webapp.ssh.hint.SSHDone", webAppName));
}
Also used : TerminalView(org.jetbrains.plugins.terminal.TerminalView) TunnelProxy(com.microsoft.azure.toolkit.lib.appservice.TunnelProxy) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) ShellTerminalWidget(org.jetbrains.plugins.terminal.ShellTerminalWidget) IOException(java.io.IOException) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Aggregations

TunnelProxy (com.microsoft.azure.toolkit.lib.appservice.TunnelProxy)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)1 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)1 IOException (java.io.IOException)1 ShellTerminalWidget (org.jetbrains.plugins.terminal.ShellTerminalWidget)1 TerminalView (org.jetbrains.plugins.terminal.TerminalView)1