Skip to content

Commit

Permalink
Run prettier on code base
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonkwok committed Feb 14, 2019
1 parent b501093 commit 2519742
Show file tree
Hide file tree
Showing 19 changed files with 267 additions and 219 deletions.
24 changes: 17 additions & 7 deletions src/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ export class Attach {
}
}

public async attach(namespace: string, podName: string, containerName: string,
stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any,
tty: boolean): Promise<WebSocket> {
public async attach(
namespace: string,
podName: string,
containerName: string,
stdout: stream.Writable | any,
stderr: stream.Writable | any,
stdin: stream.Readable | any,
tty: boolean,
): Promise<WebSocket> {
const query = {
container: containerName,
stderr: stderr != null,
Expand All @@ -28,10 +34,14 @@ export class Attach {
};
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;
});
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);
}
Expand Down
18 changes: 6 additions & 12 deletions src/attach_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,25 @@ describe('Attach', () => {
const pod = 'somepod';
const container = 'somecontainer';

await attach.attach(
namespace, pod, container, osStream, errStream, isStream, false);
await attach.attach(namespace, pod, container, osStream, errStream, isStream, false);

const path = `/api/v1/namespaces/${namespace}/pods/${pod}/attach`;
let args = `container=${container}&stderr=true&stdin=true&stdout=true&tty=false`;
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();

await attach.attach(
namespace, pod, container, null, null, null, false);
await attach.attach(namespace, pod, container, null, null, null, false);
args = `container=${container}&stderr=false&stdin=false&stdout=false&tty=false`;
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();

await attach.attach(
namespace, pod, container, osStream, null, null, false);
await attach.attach(namespace, pod, container, osStream, null, null, false);
args = `container=${container}&stderr=false&stdin=false&stdout=true&tty=false`;
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();

await attach.attach(
namespace, pod, container, osStream, errStream, null, false);
await attach.attach(namespace, pod, container, osStream, errStream, null, false);
args = `container=${container}&stderr=true&stdin=false&stdout=true&tty=false`;
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();

await attach.attach(
namespace, pod, container, osStream, errStream, null, true);
await attach.attach(namespace, pod, container, osStream, errStream, null, true);
args = `container=${container}&stderr=true&stdin=false&stdout=true&tty=true`;
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();
});
Expand All @@ -67,8 +62,7 @@ describe('Attach', () => {
const fakeConn: WebSocket = mock(WebSocket);
when(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).thenResolve(fakeConn);

await attach.attach(
namespace, pod, container, osStream, errStream, isStream, false);
await attach.attach(namespace, pod, container, osStream, errStream, isStream, false);
const [, , outputFn] = capture(fakeWebSocket.connect).last();

/* tslint:disable:no-unused-expression */
Expand Down
20 changes: 11 additions & 9 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T> {
private objects: T[] = [];
private readonly indexCache: { [key: string]: T[] } = {};

public constructor(private readonly path: string,
private readonly watch: Watch,
private readonly listFn: (callback: ListCallback<T>) => void) {
public constructor(
private readonly path: string,
private readonly watch: Watch,
private readonly listFn: (callback: ListCallback<T>) => void,
) {
this.watch = watch;
this.listFn = listFn;
this.doneHandler(null);
}

public get(name: string, namespace?: string): T | undefined {
return this.objects.find((obj: T): boolean => {
return (obj.metadata.name === name &&
(!namespace || obj.metadata.namespace === namespace));
});
return this.objects.find(
(obj: T): boolean => {
return obj.metadata.name === name && (!namespace || obj.metadata.namespace === namespace);
},
);
}

public list(namespace?: string | undefined): ReadonlyArray<T> {
Expand Down Expand Up @@ -86,8 +89,7 @@ export function addOrUpdateObject<T extends KubernetesObject>(objects: T[], obj:
}

function isSameObject<T extends KubernetesObject>(o1: T, o2: T): boolean {
return o1.metadata.name === o2.metadata.name &&
o1.metadata.namespace === o2.metadata.namespace;
return o1.metadata.name === o2.metadata.name && o1.metadata.namespace === o2.metadata.namespace;
}

function findKubernetesObject<T extends KubernetesObject>(objects: T[], obj: T): number {
Expand Down
8 changes: 4 additions & 4 deletions src/cache_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ListWatchCache', () => {
expect(cache.get('name1')).to.equal(list[0]);
expect(cache.get('name2')).to.equal(list[1]);

watchHandler('ADDED', {
watchHandler('ADDED', {
metadata: {
name: 'name3',
} as V1ObjectMeta,
Expand All @@ -40,7 +40,7 @@ describe('ListWatchCache', () => {
expect(cache.list().length).to.equal(3);
expect(cache.get('name3')).to.not.equal(null);

watchHandler('MODIFIED', {
watchHandler('MODIFIED', {
metadata: {
name: 'name3',
resourceVersion: 'baz',
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('ListWatchCache', () => {
expect(cache.list('ns2').length).to.equal(1);
expect(cache.list('ns2')[0].metadata.name).to.equal('name2');

watchHandler('ADDED', {
watchHandler('ADDED', {
metadata: {
name: 'name3',
namespace: 'ns3',
Expand All @@ -106,7 +106,7 @@ describe('ListWatchCache', () => {
expect(cache.list().length).to.equal(3);
expect(cache.get('name3', 'ns3')).to.not.equal(null);

watchHandler('MODIFIED', {
watchHandler('MODIFIED', {
metadata: {
name: 'name3',
namespace: 'ns3',
Expand Down
5 changes: 1 addition & 4 deletions src/cloud_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ interface Config {
}
export class CloudAuth implements Authenticator {
public isAuthProvider(user: User): boolean {
return (
user.authProvider.name === 'azure' ||
user.authProvider.name === 'gcp'
);
return user.authProvider.name === 'azure' || user.authProvider.name === 'gcp';
}

public getToken(user: User): string | null {
Expand Down
43 changes: 19 additions & 24 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ function fileExists(filepath: string): boolean {
try {
fs.accessSync(filepath);
return true;
// tslint:disable-next-line:no-empty
} catch (ignore) { }
// tslint:disable-next-line:no-empty
} catch (ignore) {}
return false;
}

export class KubeConfig {
private static authenticators: Authenticator[] = [
new CloudAuth(),
new ExecAuth(),
];
private static authenticators: Authenticator[] = [new CloudAuth(), new ExecAuth()];

/**
* The list of all known clusters
Expand Down Expand Up @@ -213,7 +210,9 @@ export class KubeConfig {
}
if (process.platform === 'win32' && shelljs.which('wsl.exe')) {
// TODO: Handle if someome set $KUBECONFIG in wsl here...
const result = shelljs.exec('wsl.exe cat $HOME/.kube/config', { silent: true });
const result = shelljs.exec('wsl.exe cat $HOME/.kube/config', {
silent: true,
});
if (result.code === 0) {
this.loadFromString(result.stdout);
return;
Expand Down Expand Up @@ -278,12 +277,11 @@ export class KubeConfig {
let token: string | null = null;

if (user.authProvider && user.authProvider.config) {
KubeConfig.authenticators.forEach(
(authenticator: Authenticator) => {
if (authenticator.isAuthProvider(user)) {
token = authenticator.getToken(user);
}
});
KubeConfig.authenticators.forEach((authenticator: Authenticator) => {
if (authenticator.isAuthProvider(user)) {
token = authenticator.getToken(user);
}
});
}

if (user.token) {
Expand All @@ -309,17 +307,14 @@ export interface ApiType {
}

export interface ApiConstructor<T extends ApiType> {
new(server: string): T;
new (server: string): T;
}

// This class is deprecated and will eventually be removed.
export class Config {
public static SERVICEACCOUNT_ROOT =
'/var/run/secrets/kubernetes.io/serviceaccount';
public static SERVICEACCOUNT_CA_PATH =
Config.SERVICEACCOUNT_ROOT + '/ca.crt';
public static SERVICEACCOUNT_TOKEN_PATH =
Config.SERVICEACCOUNT_ROOT + '/token';
public static SERVICEACCOUNT_ROOT = '/var/run/secrets/kubernetes.io/serviceaccount';
public static SERVICEACCOUNT_CA_PATH = Config.SERVICEACCOUNT_ROOT + '/ca.crt';
public static SERVICEACCOUNT_TOKEN_PATH = Config.SERVICEACCOUNT_ROOT + '/token';

public static fromFile(filename: string): api.Core_v1Api {
return Config.apiFromFile(filename, api.Core_v1Api);
Expand Down Expand Up @@ -362,7 +357,7 @@ export class Config {
}

// This is public really only for testing.
export function bufferFromFileOrString(file ?: string, data ?: string): Buffer | null {
export function bufferFromFileOrString(file?: string, data?: string): Buffer | null {
if (file) {
return fs.readFileSync(file);
}
Expand All @@ -379,7 +374,7 @@ export function findHomeDir(): string | null {
fs.accessSync(process.env.HOME);
return process.env.HOME;
// tslint:disable-next-line:no-empty
} catch (ignore) { }
} catch (ignore) {}
}
if (process.platform !== 'win32') {
return null;
Expand All @@ -390,13 +385,13 @@ export function findHomeDir(): string | null {
fs.accessSync(dir);
return dir;
// tslint:disable-next-line:no-empty
} catch (ignore) { }
} catch (ignore) {}
}
if (process.env.USERPROFILE) {
try {
fs.accessSync(process.env.USERPROFILE);
return process.env.USERPROFILE;
// tslint:disable-next-line:no-empty
// tslint:disable-next-line:no-empty
} catch (ignore) {}
}
return null;
Expand Down
Loading

0 comments on commit 2519742

Please sign in to comment.