forked from kubernetes-client/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattach.ts
More file actions
38 lines (34 loc) · 1.42 KB
/
attach.ts
File metadata and controls
38 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import querystring = require('querystring');
import stream = require('stream');
import { KubeConfig } from './config';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler';
export class Attach {
public 'handler': WebSocketInterface;
public constructor(config: KubeConfig, websocketInterface?: WebSocketInterface) {
if (websocketInterface) {
this.handler = websocketInterface;
} else {
this.handler = new WebSocketHandler(config);
}
}
public async attach(namespace: string, podName: string, containerName: string,
stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any,
tty: boolean): Promise<void> {
const query = {
container: containerName,
stderr: stderr != null,
stdin: stdin != null,
stdout: stdout != null,
tty,
};
const queryStr = querystring.stringify(query);
const path = `/api/v1/namespaces/${namespace}/pods/${podName}/attach?${queryStr}`;
const conn = await this.handler.connect(path, null, (streamNum: number, buff: Buffer): boolean => {
WebSocketHandler.handleStandardStreams(streamNum, buff, stdout, stderr);
return true;
});
if (stdin != null) {
WebSocketHandler.handleStandardInput(conn, stdin);
}
}
}