Skip to content

Commit

Permalink
ssh: Add verbose logging option
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed Jun 9, 2024
1 parent 41af283 commit 4b7def7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
11 changes: 10 additions & 1 deletion extensions/SSHSessionBackend/src/SSHPty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface PtyOptions {
username: string;
privateKeyFilenames?: string[];
tryPasswordAuth: boolean;
verboseLogging?: boolean;
}

enum PtyState {
Expand Down Expand Up @@ -154,11 +155,19 @@ export class SSHPty implements Pty {
});
});

let debugFunction: ssh2.DebugFunction = undefined;
if (options.verboseLogging) {
debugFunction = (message: string): void => {
this.#onDataEventEmitter.fire(`ssh logging: ${message}\n\r`);
};
}

this.#sshConnection.connect({
debug: debugFunction,
host: options.host,
port: options.port,
username: options.username,
tryKeyboard: true,
tryKeyboard: false,
authHandler: (
methodsLeft: ssh2.AuthenticationType[],
partialSuccess: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface SSHSessionConfiguration extends SessionConfiguration {
username?: string;
authenicationMethod?: AuthenticationMethod;
keyFilePath?: string;
verboseLogging?: boolean;
}

class SSHBackend implements SessionBackend {
Expand Down Expand Up @@ -82,6 +83,7 @@ class SSHBackend implements SessionBackend {
username: username,
privateKeyFilenames,
tryPasswordAuth,
verboseLogging: sessionConfig.verboseLogging,
};

return new SSHPty(this._log, options);
Expand Down Expand Up @@ -122,7 +124,10 @@ class SSHBackend implements SessionBackend {
}
}

let log: Logger = null;

export function activate(context: ExtensionContext): any {
log = context.logger;
context.sessions.registerSessionBackend("ssh", new SSHBackend(context.logger));
}

Expand Down
19 changes: 17 additions & 2 deletions extensions/SSHSessionEditor/src/SSHSessionEditorExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import {ExtensionContext, Logger, SessionConfiguration, SessionEditorBase} from "@extraterm/extraterm-extension-api";
import { Direction, FileMode, QFileDialog, QLineEdit, QPushButton, QWidget } from "@nodegui/nodegui";
import { BoxLayout, ComboBox, GridLayout, LineEdit, SpinBox, Widget, PushButton } from "qt-construct";
import { BoxLayout, ComboBox, GridLayout, LineEdit, SpinBox, Widget, PushButton, CheckBox } from "qt-construct";


let log: Logger = null;
Expand All @@ -26,6 +26,7 @@ interface SSHSessionConfiguration extends SessionConfiguration {
username?: string;
authenicationMethod?: AuthenticationMethod;
keyFilePath?: string;
verboseLogging?: boolean;
}

export function activate(context: ExtensionContext): any {
Expand Down Expand Up @@ -138,7 +139,16 @@ class EditorUi {
}
]
})
})
}),

"",
CheckBox({
text: "Verbose logging",
checked: this.#config.verboseLogging ?? false,
onStateChanged: (enabled: number) => {
this.#handleVerboseLoggingChanged(enabled !== 0);
}
}),
]
})
});
Expand Down Expand Up @@ -168,6 +178,11 @@ class EditorUi {
this.#sessionEditorBase.setSessionConfiguration(this.#config);
}

#handleVerboseLoggingChanged(enabled: boolean): void {
this.#config.verboseLogging = enabled;
this.#sessionEditorBase.setSessionConfiguration(this.#config);
}

getWidget(): QWidget {
return this.#widget;
}
Expand Down

0 comments on commit 4b7def7

Please sign in to comment.