Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cmosgh committed Aug 8, 2018
2 parents 0fad2e5 + ee37f81 commit 988be1b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ node_modules
/node-client/src/git_push.sh
/node-client/src/tsconfig.json
/node-client/src/typings.json
.vscode/*
examples/package-lock.json

2 changes: 1 addition & 1 deletion node-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kubernetes/client-node",
"version": "0.4.0",
"version": "0.5.0",
"description": "NodeJS client for kubernetes",
"repository": {
"type": "git",
Expand Down
10 changes: 8 additions & 2 deletions node-client/src/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import stream = require('stream');

import { KubeConfig } from './config';
import { WebSocketHandler } from './web-socket-handler';
import { connection } from 'websocket';
import { resolve } from 'url';

export class Attach {
public 'handler': WebSocketHandler;
Expand All @@ -13,7 +15,7 @@ export class Attach {

public attach(namespace: string, podName: string, containerName: string,
stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any,
tty: boolean) {
tty: boolean): Promise<void> {
const query = {
container: containerName,
stderr: stderr != null,
Expand All @@ -23,8 +25,12 @@ export class Attach {
};
const queryStr = querystring.stringify(query);
const path = `/api/v1/namespaces/${namespace}/pods/${podName}/attach?${queryStr}`;
this.handler.connect(path, null, (streamNum: number, buff: Buffer) => {
const promise = this.handler.connect(path, null, (streamNum: number, buff: Buffer) => {
WebSocketHandler.handleStandardStreams(streamNum, buff, stdout, stderr);
});
const result = new Promise<void>((resolvePromise, reject) => {
promise.then(() => resolvePromise(), (err) => reject(err));
});
return result;
}
}
26 changes: 14 additions & 12 deletions node-client/src/config_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,24 @@ function userIterator(): u.ListIterator<any, User> {
throw new Error(`users[${i}].name is missing`);
}
let token = null;
if (elt.user.token) {
token = elt.user.token;
}
if (elt.user['token-file']) {
token = fs.readFileSync(elt.user['token-file']);
if (elt.user) {
if (elt.user.token) {
token = elt.user.token;
}
if (elt.user['token-file']) {
token = fs.readFileSync(elt.user['token-file']);
}
}
return {
authProvider: elt.user['auth-provider'],
certData: elt.user['client-certificate-data'],
certFile: elt.user['client-certificate'],
keyData: elt.user['client-key-data'],
keyFile: elt.user['client-key'],
authProvider: elt.user ? elt.user['auth-provider'] : null,
certData: elt.user ? elt.user['client-certificate-data'] : null,
certFile: elt.user ? elt.user['client-certificate'] : null,
keyData: elt.user ? elt.user['client-key-data'] : null,
keyFile: elt.user ? elt.user['client-key'] : null,
name: elt.name,
password: elt.user.password,
password: elt.user ? elt.user.password : null,
token,
username: elt.user.username,
username: elt.user ? elt.user.username : null,
};
};
}
Expand Down
9 changes: 5 additions & 4 deletions node-client/src/web-socket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ export class WebSocketHandler {
binaryHandler: (stream: number, buff: Buffer) => void): Promise<ws.connection> {

const server = this.config.getCurrentCluster().server;
const target = server.startsWith('https://') ? server.substr(8) : server.substr(7);
const uri = `wss://${target}${path}`;
const ssl = server.startsWith('https://');
const target = ssl ? server.substr(8) : server.substr(7);
const proto = ssl ? 'wss' : 'ws';
const uri = `${proto}://${target}${path}`;

const opts: https.RequestOptions = {};
this.config.applytoHTTPSOptions(opts);
Expand All @@ -97,8 +99,7 @@ export class WebSocketHandler {
client.on('connectFailed', (err) => {
reject(err);
});

client.connect(uri, protocols);
client.connect(uri, protocols);
});
}
}

0 comments on commit 988be1b

Please sign in to comment.