Skip to content

Commit db4ec8d

Browse files
committed
use LineBuffer for handling ssh input, just as we do for telnet
1 parent 2718645 commit db4ec8d

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/cloud/install/installer.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
/// <reference path='../../../../third_party/typings/node/node.d.ts' />
44
/// <reference path='../../../../third_party/typings/ssh2/ssh2.d.ts' />
55

6+
import arraybuffers = require('../../arraybuffers/arraybuffers');
7+
import linefeeder = require('../../net/linefeeder');
68
import logging = require('../../logging/logging');
9+
import queue = require('../../handler/queue');
710

811
// https://github.com/borisyankov/DefinitelyTyped/blob/master/ssh2/ssh2-tests.ts
912
import * as ssh2 from 'ssh2';
@@ -45,6 +48,23 @@ class CloudInstaller {
4548
return new Promise<string>((F, R) => {
4649
connection.on('ready', () => {
4750
log.debug('logged into server');
51+
52+
var stdout = new queue.Queue<ArrayBuffer, void>();
53+
new linefeeder.LineFeeder(stdout).setSyncHandler((line: string) => {
54+
log.debug('STDOUT: %1', line);
55+
// Search for the URL anywhere in the line so we will
56+
// continue to work in the face of minor changes
57+
// to the install script.
58+
if (line.indexOf(INVITATION_URL_PREFIX) === 0) {
59+
F(line.substring(INVITATION_URL_PREFIX.length));
60+
}
61+
});
62+
63+
var stderr = new queue.Queue<ArrayBuffer, void>();
64+
new linefeeder.LineFeeder(stderr).setSyncHandler((line: string) => {
65+
log.error('STDERR: %1', line);
66+
});
67+
4868
connection.exec(INSTALL_COMMAND, (e: Error, stream: ssh2.Channel) => {
4969
if (e) {
5070
connection.end();
@@ -58,17 +78,10 @@ class CloudInstaller {
5878
R({
5979
message: 'invitation URL not found'
6080
});
61-
}).on('data', function(data: Buffer) {
62-
const output = data.toString();
63-
log.debug('STDOUT: %1', output);
64-
// Search for the URL anywhere in the line so we will
65-
// continue to work in the face of minor changes
66-
// to the install script.
67-
if (output.indexOf(INVITATION_URL_PREFIX) === 0) {
68-
F(output.substring(INVITATION_URL_PREFIX.length));
69-
}
70-
}).stderr.on('data', function(data: Buffer) {
71-
log.error(data.toString());
81+
}).on('data', (data:Buffer) => {
82+
stdout.handle(arraybuffers.bufferToArrayBuffer(data));
83+
}).stderr.on('data', (data: Buffer) => {
84+
stderr.handle(arraybuffers.bufferToArrayBuffer(data));
7285
});
7386
});
7487
}).on('error', (e: Error) => {

0 commit comments

Comments
 (0)