Better handling setting/getting config data for authentication (issue #3)

pull/13/head
Kelvin Schoofs 7 years ago
parent c2d99ad5da
commit d6519d6535

@ -176,23 +176,30 @@ export class Manager implements vscode.FileSystemProvider, vscode.TreeDataProvid
const session = await getPuttySession(config.putty, config.host, config.username, nameOnly);
if (!session) return reject(new Error(`Couldn't find the requested PuTTY session`));
if (session.protocol !== 'ssh') return reject(new Error(`The requested PuTTY session isn't a SSH session`));
config.username = session.username;
config.host = session.hostname;
config.port = session.portnumber;
config.agent = session.tryagent ? 'pageant' : undefined;
config.username = config.username || session.username;
config.host = config.host || session.hostname;
config.port = config.port || session.portnumber;
config.agent = config.agent || (session.tryagent ? 'pageant' : undefined);
if (session.usernamefromenvironment) {
session.username = process.env.USERNAME;
if (!session.username) return reject(new Error(`No username specified in the session (nor is using the system username enabled)`));
config.username = process.env.USERNAME;
if (!config.username) return reject(new Error(`Trying to use the system username, but process.env.USERNAME is missing`));
}
if (!config.agent && session.publickeyfile) {
try {
const key = await toPromise<Buffer>(cb => readFile(session.publickeyfile, cb));
const key = await toPromise<Buffer>(cb => readFile(session.publickeyfile!, cb));
config.privateKey = key;
} catch (e) {
return reject(new Error(`Error while reading the keyfile at:\n${session.publickeyfile}`));
}
}
}
if (!config.username || (config.username as any) === true) {
config.username = await vscode.window.showInputBox({
ignoreFocusOut: true,
placeHolder: 'Username',
prompt: 'Username to log in with',
});
}
if ((config.password as any) === true) {
config.password = await vscode.window.showInputBox({
password: true,

@ -10,15 +10,15 @@ const winreg = new Winreg({
export type NumberAsBoolean = 0 | 1;
export interface PuttySession {
[key: string]: string | number;
[key: string]: string | number | undefined;
name: string;
hostname: string;
protocol: string;
portnumber: number;
username: string;
username?: string;
usernamefromenvironment: NumberAsBoolean;
tryagent: NumberAsBoolean;
publickeyfile: string;
publickeyfile?: string;
}
function valueFromItem(item: Winreg.RegistryItem) {
@ -57,5 +57,5 @@ export async function getSession(name?: string, host?: string, username?: string
const hosts = sessions.filter(s => s.hostname.toLowerCase() === host);
if (!username) return hosts[0] || null;
username = username.toLowerCase();
return hosts.find(s => s.username.toLowerCase() === username) || null;
return hosts.find(s => !s.username || s.username.toLowerCase() === username) || null;
}

Loading…
Cancel
Save