UNPKG

snips-sam

Version:

The Snips Assistant Manager

81 lines 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const process = require("process"); const cli_1 = require("../cli"); const utils_1 = require("../utils"); const session_1 = require("../session"); exports.command = 'connect <HOSTNAME_OR_IP>'; exports.desc = 'Connect to a device'; exports.handler = (argv) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const hostname = argv['HOSTNAME_OR_IP']; let username = ''; let password = ''; try { const response = yield cli_1.default.prompt.promptQuestions([utils_1.Config.usernameQuestion, utils_1.Config.passwordQuestion]); username = response['username']; password = response['password']; } catch (e) { cli_1.default.stream.println(); cli_1.default.stream.error(`Error connecting to device: ${e.message}`, true); process.exit(); } if (password.length === 0) { cli_1.default.stream.error('Password cannot be blank'); process.exit(); } const onConnected = () => { cli_1.default.stream.stopAndClear(); cli_1.default.stream.success(`Connected to ${hostname}`, true); }; const onSSHCopyId = () => { cli_1.default.stream.hint(`A public key has been generated and copied to the device at ${hostname}:${session_1.snipsRemoteAuthorizedKeysFilename}`); }; const onSSHKeygenNotFound = (sshKeygenPath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { cli_1.default.stream.error(`Didn't find the ssh-keygen.exe located in ${sshKeygenPath}`); const isGitInstalled = yield cli_1.default.prompt.promptQuestions([ { name: 'isInstalled', type: 'confirm', message: 'Do you have Git already installed on your computer?', }, ]); if (isGitInstalled['isInstalled'] === false) { cli_1.default.stream.hint('You need to install Git https://git-scm.com/downloads. Aborting'); ssh.disconnect(); process.exit(); } else { const path = yield cli_1.default.prompt.promptQuestions([ { name: 'path', type: 'string', message: "Specify the path to Git's ssh-keygen.exe", }, ]); return path['path']; } }); const onCredentialsSaved = () => { }; const ssh = new session_1.SSHService(); let error = false; cli_1.default.stream.loading(`Connecting to ${hostname}`); let initialError = undefined; yield ssh.newConnection({ hostname, username }, password, onConnected, onSSHCopyId, onCredentialsSaved, onSSHKeygenNotFound).catch(e => { error = true; initialError = e.message; }); if (error) { yield ssh.newConnection({ username, hostname: `${hostname}.local` }, password, onConnected, onSSHCopyId, onCredentialsSaved, onSSHKeygenNotFound) .catch(e => { cli_1.default.stream.stopAndClear(); cli_1.default.stream.println(); cli_1.default.stream.error((initialError !== undefined) ? initialError : e.message, true); process.exit(); }); } ssh.disconnect(); process.exit(); }); //# sourceMappingURL=connect.js.map