@kubernetesjs/cli 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +54 -55
- package/commands/apply.d.ts +4 -0
- package/commands/apply.js +171 -0
- package/commands/cluster-info.d.ts +4 -0
- package/commands/cluster-info.js +26 -0
- package/commands/config-handler.d.ts +11 -0
- package/commands/config-handler.js +81 -0
- package/commands/config.d.ts +4 -0
- package/commands/config.js +72 -0
- package/commands/delete.d.ts +4 -0
- package/commands/delete.js +256 -0
- package/commands/deploy.d.ts +6 -0
- package/commands/deploy.js +209 -0
- package/commands/describe.d.ts +4 -0
- package/commands/describe.js +216 -0
- package/commands/exec.d.ts +4 -0
- package/commands/exec.js +145 -0
- package/commands/get.d.ts +4 -0
- package/commands/get.js +164 -0
- package/commands/logs.d.ts +4 -0
- package/commands/logs.js +110 -0
- package/commands/port-forward.d.ts +4 -0
- package/commands/port-forward.js +143 -0
- package/commands.d.ts +3 -0
- package/commands.js +93 -0
- package/config.d.ts +22 -0
- package/config.js +113 -0
- package/esm/commands/apply.js +133 -0
- package/esm/commands/cluster-info.js +21 -0
- package/esm/commands/config-handler.js +43 -0
- package/esm/commands/config.js +67 -0
- package/esm/commands/delete.js +218 -0
- package/esm/commands/deploy.js +207 -0
- package/esm/commands/describe.js +211 -0
- package/esm/commands/exec.js +140 -0
- package/esm/commands/get.js +159 -0
- package/esm/commands/logs.js +105 -0
- package/esm/commands/port-forward.js +138 -0
- package/esm/commands.js +86 -0
- package/esm/config.js +74 -0
- package/esm/index.js +19 -0
- package/esm/package.js +26 -0
- package/esm/utils.js +49 -0
- package/index.d.ts +3 -0
- package/index.js +22 -0
- package/package.d.ts +1 -0
- package/package.js +29 -0
- package/package.json +37 -61
- package/utils.d.ts +11 -0
- package/utils.js +58 -0
- package/main/client.js +0 -156
- package/main/index.js +0 -2598
- package/module/client.js +0 -129
- package/module/index.js +0 -2594
- package/src/client.ts +0 -156
- package/src/index.ts +0 -14187
- package/types/client.d.ts +0 -31
- package/types/index.d.ts +0 -11331
package/src/client.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import * as http from 'http';
|
|
2
|
-
import * as querystring from 'querystring';
|
|
3
|
-
import { URLSearchParams } from 'url';
|
|
4
|
-
|
|
5
|
-
interface RequestOptions<Params> {
|
|
6
|
-
hostname: string;
|
|
7
|
-
path: string;
|
|
8
|
-
headers?: { [key: string]: string };
|
|
9
|
-
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
10
|
-
params?: Params;
|
|
11
|
-
timeout?: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface APIClientOptions {
|
|
15
|
-
restEndpoint: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class APIClient {
|
|
19
|
-
private hostname: string;
|
|
20
|
-
private port: number = 8001; // Default Kubernetes proxy port
|
|
21
|
-
private defaultTimeout: number = 10000; // 10 seconds
|
|
22
|
-
|
|
23
|
-
constructor(options: APIClientOptions) {
|
|
24
|
-
const url = new URL(options.restEndpoint);
|
|
25
|
-
this.hostname = url.hostname;
|
|
26
|
-
this.port = url.port ? parseInt(url.port) : this.port;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get<Resp = unknown>(endpoint: string, query?: { [key: string]: any }, opts: http.RequestOptions & { timeout?: number } = {}): Promise<Resp> {
|
|
30
|
-
const queryString = query ? `?${querystring.stringify(query)}` : '';
|
|
31
|
-
const fullPath = endpoint + queryString;
|
|
32
|
-
return this.request<Resp, void>({
|
|
33
|
-
path: fullPath,
|
|
34
|
-
method: 'GET',
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
headers: opts.headers,
|
|
37
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
post<Resp = unknown, Params = any>(endpoint: string, params: Params, opts: http.RequestOptions & { timeout?: number, isFormData?: boolean } = {}): Promise<Resp> {
|
|
42
|
-
const headers = opts.isFormData ? {
|
|
43
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
44
|
-
...opts.headers
|
|
45
|
-
} : {
|
|
46
|
-
'Content-Type': 'application/json',
|
|
47
|
-
...opts.headers
|
|
48
|
-
};
|
|
49
|
-
const body = opts.isFormData ? new URLSearchParams(params as any).toString() : JSON.stringify(params);
|
|
50
|
-
headers['Content-Length'] = Buffer.byteLength(body).toString();
|
|
51
|
-
|
|
52
|
-
return this.request<Resp, Params>({
|
|
53
|
-
path: endpoint,
|
|
54
|
-
method: 'POST',
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
headers,
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
params: body,
|
|
59
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
patch<Resp = unknown, Params = any>(endpoint: string, params: Params, opts: http.RequestOptions & { timeout?: number, isFormData?: boolean } = {}): Promise<Resp> {
|
|
64
|
-
const headers = opts.isFormData ? {
|
|
65
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
66
|
-
...opts.headers
|
|
67
|
-
} : {
|
|
68
|
-
'Content-Type': 'application/json',
|
|
69
|
-
...opts.headers
|
|
70
|
-
};
|
|
71
|
-
const body = opts.isFormData ? new URLSearchParams(params as any).toString() : JSON.stringify(params);
|
|
72
|
-
headers['Content-Length'] = Buffer.byteLength(body).toString();
|
|
73
|
-
|
|
74
|
-
return this.request<Resp, Params>({
|
|
75
|
-
path: endpoint,
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
method: 'PATCH',
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
headers,
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
params: body,
|
|
82
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
put<Resp = unknown, Params = any>(endpoint: string, params: Params, opts: http.RequestOptions & { timeout?: number } = {}): Promise<Resp> {
|
|
87
|
-
const stringParams = JSON.stringify(params);
|
|
88
|
-
const defaultHeaders = {
|
|
89
|
-
'Content-Type': 'application/json',
|
|
90
|
-
'Content-Length': Buffer.byteLength(stringParams).toString(),
|
|
91
|
-
...opts.headers
|
|
92
|
-
};
|
|
93
|
-
return this.request<Resp, Params>({
|
|
94
|
-
path: endpoint,
|
|
95
|
-
method: 'PUT',
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
headers: defaultHeaders,
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
params: stringParams,
|
|
100
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
delete<Resp = unknown>(endpoint: string, opts: http.RequestOptions & { timeout?: number } = {}): Promise<Resp> {
|
|
105
|
-
return this.request<Resp, void>({
|
|
106
|
-
path: endpoint,
|
|
107
|
-
method: 'DELETE',
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
headers: opts.headers,
|
|
110
|
-
timeout: opts.timeout || this.defaultTimeout,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private request<Resp, Params>(options: RequestOptions<Params>): Promise<Resp> {
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
const requestOptions: http.RequestOptions = {
|
|
117
|
-
hostname: this.hostname,
|
|
118
|
-
port: this.port,
|
|
119
|
-
path: options.path,
|
|
120
|
-
method: options.method,
|
|
121
|
-
headers: options.headers,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const req = http.request(requestOptions, res => {
|
|
125
|
-
let data = '';
|
|
126
|
-
res.on('data', chunk => {
|
|
127
|
-
data += chunk;
|
|
128
|
-
});
|
|
129
|
-
res.on('end', () => {
|
|
130
|
-
try {
|
|
131
|
-
const parsedData: Resp = JSON.parse(data);
|
|
132
|
-
resolve(parsedData);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
reject(error);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
req.on('error', error => {
|
|
140
|
-
reject(error);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
req.setTimeout(options.timeout, () => {
|
|
145
|
-
req.abort();
|
|
146
|
-
reject(new Error('Request timeout'));
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
if (options.params && (options.method === 'POST' || options.method === 'PUT')) {
|
|
150
|
-
req.write(options.params);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
req.end();
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|