Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { VsCodeConfig } from "./config/Configuration";
import { getEnvConfig } from "./filesystems/local/env";
import { ConnectionConfig, ConnectionData, IBMiEvent } from "./typings";
import { VscodeTools } from "./ui/Tools";
import { handleConnectionResults, messageCallback } from "./ui/connection";
import { handleConnectionResults, inputBoxCallback, messageCallback } from "./ui/connection";


type IBMiEventSubscription = {
Expand Down Expand Up @@ -124,6 +124,9 @@ export default class Instance {
uiErrorHandler: handleConnectionResults,
progress: (message) => { p.report(message) },
message: messageCallback,
inputBox: async (prompt: string, placeHolder: string, ignoreFocusOut: boolean) => {
return await inputBoxCallback(prompt, placeHolder, ignoreFocusOut, cancelToken)
},
cancelEmitter
},
reconnecting: options.reconnecting,
Expand Down
48 changes: 33 additions & 15 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface ConnectionCallbacks {
uiErrorHandler: (connection: IBMi, error: ConnectionErrorCode, data?: any) => Promise<boolean>,
progress: (detail: { message: string }) => void,
message: (type: ConnectionMessageType, message: string) => void,
inputBox: (prompt: string, placeHolder: string, ignoreFocusOut: boolean) => Promise<string | undefined>,
cancelEmitter?: EventEmitter,
}

Expand Down Expand Up @@ -188,7 +189,7 @@ export default class IBMi {
async loadRemoteConfigs() {
for (const configFile in this.configFiles) {
const currentConfig = this.configFiles[configFile as keyof ConnectionConfigFiles];

currentConfig.reset();

try {
Expand Down Expand Up @@ -285,6 +286,8 @@ export default class IBMi {
const currentExtensionVersion = process.env.VSCODEIBMI_VERSION;
const callbacks = options.callbacks;

let wasCancelled = false;

try {
connectionObject.keepaliveInterval = 35000;

Expand All @@ -294,28 +297,39 @@ export default class IBMi {
message: `Connecting via SSH.`
});

const delayedOperations: Function[] = callbacks.onConnectedOperations ? [...callbacks.onConnectedOperations] : [];
if (callbacks.cancelEmitter) {
callbacks.cancelEmitter.once('cancel', () => {
wasCancelled = true;
this.dispose();
});
}

if (options.customClient) {
this.client = options.customClient;
} else {
this.client = new node_ssh.NodeSSH;
}

if (connectionObject.enableMfa) {
delete connectionObject.enableMfa;

if (connectionObject.password) {
callbacks.progress({
message: `Prompting for one-time password.`
});
const oneTimePassword = await options.callbacks.inputBox(`Enter your one-time password or press "Enter" if within your TOTP interval`, `One-Time Password`, true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the terminology should be reviewed.
'one-time password' is not completely correct since it is actually 'time-based one-time password' (TOTP) value.
We should consider what is shown in 5250 and ACS which I think is 'Additional factor'. Consistency would be easier on users.

if (oneTimePassword) {
connectionObject.password = `${connectionObject.password}:${oneTimePassword}`;
}
}
}

await this.client.connect({
...connectionObject,
privateKeyPath: connectionObject.privateKeyPath ? Tools.resolvePath(connectionObject.privateKeyPath) : undefined,
debug: connectionObject.sshDebug ? (message: string) => this.appendOutput(`\n[SSH debug] ${message}`) : undefined
} as node_ssh.Config);

let wasCancelled = false;

if (callbacks.cancelEmitter) {
callbacks.cancelEmitter.once('cancel', () => {
wasCancelled = true;
this.dispose();
});
}

this.currentConnectionName = connectionObject.name;
this.currentHost = connectionObject.host;
this.currentPort = connectionObject.port;
Expand Down Expand Up @@ -997,6 +1011,7 @@ export default class IBMi {
}

if (!options.reconnecting) {
const delayedOperations: Function[] = callbacks.onConnectedOperations ? [...callbacks.onConnectedOperations] : [];
for (const operation of delayedOperations) {
await operation();
}
Expand Down Expand Up @@ -1026,14 +1041,17 @@ export default class IBMi {
this.disconnect(true);

let error = e.message;
if (e.code === "ENOTFOUND") {
error = `host is unreachable. Check the connection's hostname/IP address.`;
if(wasCancelled) {
error = `Connection attempt cancelled.`;
}
else if (e.code === "ENOTFOUND") {
error = `Host is unreachable. Check the connection's hostname/IP address.`;
}
else if (e.code === "ECONNREFUSED") {
error = `port ${connectionObject.port} is unreachable. Check the connection's port number or run command STRTCPSVR SERVER(*SSHD) on the host.`
error = `Port ${connectionObject.port} is unreachable. Check the connection's port number or run command STRTCPSVR SERVER(*SSHD) on the host.`
}
else if (e.level === "client-authentication") {
error = `check your credentials${e.message ? ` (${e.message})` : ''}.`;
error = `Check your credentials${e.message ? ` (${e.message})` : ''}.`;
}

this.appendOutput(`${JSON.stringify(e)}`);
Expand Down
6 changes: 6 additions & 0 deletions src/api/tests/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export async function newConnection(reloadSettings?: boolean) {
message: (type: string, message: string) => {
// console.log(`${type.padEnd(10)} ${message}`);
},
inputBox: async (prompt: string, placeHolder: string, ignoreFocusOut: boolean) => {
// console.log(`PROMPT: ${prompt}`);
// console.log(`PLACEHOLDER: ${placeHolder}`);
// console.log(`IGNORE FOCUS OUT: ${ignoreFocusOut}`);
return undefined;
},
progress: ({ message }) => {
// console.log(`PROGRESS: ${message}`);
},
Expand Down
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface ConnectionData {
keepaliveInterval?: number;
readyTimeout?: number;
sshDebug?: boolean;
enableMfa?: boolean;
}

export interface Server {
Expand Down
Loading
Loading