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

SSH Target Selector #9760

Merged
merged 15 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"c_cpp.configuration.legacyCompilerArgsBehavior.markdownDescription": "Enable pre-v1.10.0 behavior for how shell escaping is handled in compiler arg settings. Shell escaping is no longer expected or supported by default in arg arrays starting in v1.10.0.",
"c_cpp.configuration.legacyCompilerArgsBehavior.deprecationMessage": "This setting is temporary to support transitioning to corrected behavior in v1.10.0.",
"c_cpp.contributes.views.cppReferencesView.title": "C/C++: Other references results",
"c_cpp.contributes.views.SshTargetsView.title": "C/C++: SSH targets",
"c_cpp.contributes.views.SshTargetsView.title": { "message": "CppTools: SSH targets", "comment": [ "Do not localize `CppTools`." ] },
xisui-MSFT marked this conversation as resolved.
Show resolved Hide resolved
"c_cpp.contributes.viewsWelcome.contents": { "message": "To learn more about launch.json, see [Configuring C/C++ debugging](https://code.visualstudio.com/docs/cpp/launch-json-reference).", "comment": [ "Markdown text between () should not be altered: https://en.wikipedia.org/wiki/Markdown" ] },
"c_cpp.configuration.debugShortcut.description": "Show the \"Run and Debug\" play button and \"Add Debug Configuration\" gear in the editor title bar for C++ files.",
"c_cpp.debuggers.pipeTransport.description": "When present, this tells the debugger to connect to a remote computer using another executable as a pipe that will relay standard input/output between VS Code and the MI-enabled debugger backend executable (such as gdb).",
Expand Down
6 changes: 5 additions & 1 deletion Extension/src/SSH/TargetsView/targetNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { extensionContext, ISshConfigHostInfo, pathAccessible } from "../../comm
import { TreeItem } from "vscode";
import { LabelLeafNode } from "./common";
import { constants } from 'fs';
import * as nls from 'vscode-nls';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();

export const workspaceState_activeSshTarget: string = 'workspaceState_activeSshTarget';

Expand All @@ -32,7 +36,7 @@ export class TargetLeafNode extends LabelLeafNode {
const item: TreeItem = await super.getTreeItem();
const removable: boolean = await isWritable(this.sshConfigHostInfo.file);
if (_activeTarget === this.name) {
item.label = `* ${item.label}`;
item.label = localize('ssh.target.active.label', '{0} [Active]', this.getLabel());
xisui-MSFT marked this conversation as resolved.
Show resolved Hide resolved
if (removable) {
item.contextValue = 'CppSshTargetsView.targetLeafRemovable';
}
Expand Down
24 changes: 24 additions & 0 deletions Extension/src/SSH/commandInteractors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

import * as vscode from 'vscode';
import { stripEscapeSequences, isWindows, escapeStringForRegex, ISshHostInfo, getFullHostAddress, extensionContext } from '../common';
import { getOutputChannelLogger } from '../logger';
import * as nls from 'vscode-nls';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();

/**
* The users that we autofilled their passwords.
Expand Down Expand Up @@ -326,6 +331,25 @@ export class ContinueOnInteractor implements IInteractor {
}
}

export class ConnectionFailureInteractor implements IInteractor {
static ID = 'connectionFailure';

constructor(private readonly hostName: string) { }

get id(): string {
return ConnectionFailureInteractor.ID;
}

async onData(data: string): Promise<IInteraction> {
const result: IInteraction = { postAction: 'keep' };
if (data.includes('Connection refused') || data.includes('Could not resolve hostname')) {
bobbrow marked this conversation as resolved.
Show resolved Hide resolved
result.postAction = 'consume';
getOutputChannelLogger().showErrorMessage(localize('failed.to.connect', 'Failed to connect to {0}', this.hostName));
}
return result;
}
}

export class ComposedInteractor implements IInteractor {
constructor(private readonly interactors: IInteractor[]) { }

Expand Down
6 changes: 4 additions & 2 deletions Extension/src/SSH/sshCommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
ContinueOnInteractor,
ISystemInteractor,
IInteraction,
autoFilledPasswordForUsers
autoFilledPasswordForUsers,
ConnectionFailureInteractor
} from './commandInteractors';
import { isWindows, ISshHostInfo, splitLines, stripEscapeSequences, ProcessReturnType } from '../common';
import { getOutputChannelLogger } from '../logger';
Expand Down Expand Up @@ -203,7 +204,8 @@ export async function runSshTerminalCommandWithLogin(
new DifferingHostKeyInteractor(showDifferingHostConfirmation),
new PasswordInteractor(host, showPasswordInputBox),
new TwoFacInteractor(showVerificationCodeInputBox),
new DuoTwoFacInteractor(showVerificationCodeInputBox)
new DuoTwoFacInteractor(showVerificationCodeInputBox),
new ConnectionFailureInteractor(host.hostName)
);
}

Expand Down