|
1 | 1 | import querystring = require('querystring');
|
2 | 2 | import stream = require('stream');
|
3 | 3 |
|
4 |
| -import { WebSocketHandler } from './web-socket-handler'; |
5 | 4 | import { KubeConfig } from './config';
|
| 5 | +import { WebSocketHandler } from './web-socket-handler'; |
6 | 6 |
|
7 | 7 | export class Attach {
|
8 |
| - 'handler': WebSocketHandler; |
| 8 | + public 'handler': WebSocketHandler; |
9 | 9 |
|
10 | 10 | public constructor(config: KubeConfig) {
|
11 | 11 | this.handler = new WebSocketHandler(config);
|
12 |
| - } |
| 12 | + } |
13 | 13 |
|
14 |
| - public attach(namespace: string, podName: string, containerName: string, stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any, tty: boolean) { |
15 |
| - var query = { |
16 |
| - stdout: stdout != null, |
| 14 | + public attach(namespace: string, podName: string, containerName: string, |
| 15 | + stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any, |
| 16 | + tty: boolean) { |
| 17 | + const query = { |
| 18 | + container: containerName, |
17 | 19 | stderr: stderr != null,
|
18 | 20 | stdin: stdin != null,
|
19 |
| - tty: tty, |
20 |
| - container: containerName |
21 |
| - } |
22 |
| - var queryStr = querystring.stringify(query); |
23 |
| - var path = `/api/v1/namespaces/${namespace}/pods/${podName}/attach?${queryStr}`; |
24 |
| - this.handler.connect(path, null, (stream: number, buff: Buffer) => { |
25 |
| - WebSocketHandler.handleStandardStreams(stream, buff, stdout, stderr); |
| 21 | + stdout: stdout != null, |
| 22 | + tty, |
| 23 | + }; |
| 24 | + const queryStr = querystring.stringify(query); |
| 25 | + const path = `/api/v1/namespaces/${namespace}/pods/${podName}/attach?${queryStr}`; |
| 26 | + this.handler.connect(path, null, (streamNum: number, buff: Buffer) => { |
| 27 | + WebSocketHandler.handleStandardStreams(streamNum, buff, stdout, stderr); |
26 | 28 | });
|
27 | 29 | }
|
28 | 30 | }
|
0 commit comments