Skip to content

Commit 69fa6b8

Browse files
committed
fix: remove unused request dependency
1 parent fb88d4c commit 69fa6b8

File tree

9 files changed

+214
-103
lines changed

9 files changed

+214
-103
lines changed

FETCH_MIGRATION.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ Code will be on the `master` branch.
5151
- [x] Match src/gen/api.ts to new generated layout (it changes slightly)
5252
- [ ] Fix errors in /src folder (due to new api)
5353
- [x] migrate src/auth.ts, the dependent implementations (ex: azure_auth, gcp_auth etc) and tests to fetch api from request
54-
- [ ] migrate src/log.ts and its tests to fetch api from request
55-
- major remaining work is fixing up async signatures and return piping
56-
- [ ] migrate src/watch.ts and its tests to fetch api from request
57-
- remove decprecated requestImpl and RequestInterface
58-
- implement queryParams parameter in watch method by injecting them into the fetch call
59-
- update tests in src/watch_test.ts
54+
- [x] migrate src/log.ts and its tests to fetch api from request
55+
- [x] major remaining work is fixing up async signatures and return piping
56+
- [x] migrate src/watch.ts and its tests to fetch api from request
57+
- [x] remove decprecated requestImpl and RequestInterface
58+
- [x] implement queryParams parameter in watch method by injecting them into the fetch call
59+
- [ ] update tests in src/watch_test.ts
6060
- [ ] Fix errors in test (due to new api)
6161
- [ ] Test all features
6262
- [ ] Fix examples and validate their param signatures (due to new api)

package-lock.json

Lines changed: 142 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@
5656
"dependencies": {
5757
"@types/js-yaml": "^4.0.1",
5858
"@types/node": "^10.12.0",
59+
"@types/node-fetch": "^2.6.3",
5960
"@types/stream-buffers": "^3.0.3",
6061
"@types/tar": "^6.1.1",
6162
"@types/underscore": "^1.8.9",
6263
"@types/ws": "^6.0.1",
6364
"abort-controller": "^3.0.0",
6465
"byline": "^5.0.0",
6566
"execa": "5.0.0",
67+
"form-data": "^4.0.0",
6668
"isomorphic-ws": "^4.0.1",
6769
"js-yaml": "^4.1.0",
6870
"jsonpath-plus": "^0.19.0",

src/cache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import AbortController from 'abort-controller';
12
import {
23
ADD,
34
CHANGE,
@@ -12,7 +13,7 @@ import {
1213
} from './informer';
1314
import { KubernetesObject } from './types';
1415
import { ObjectSerializer } from './util';
15-
import { RequestResult, Watch } from './watch';
16+
import { Watch } from './watch';
1617

1718
export interface ObjectCache<T> {
1819
get(name: string, namespace?: string): T | undefined;
@@ -25,7 +26,7 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
2526
private resourceVersion: string;
2627
private readonly indexCache: { [key: string]: T[] } = {};
2728
private readonly callbackCache: { [key: string]: Array<ObjectCallback<T> | ErrorCallback> } = {};
28-
private request: RequestResult | undefined;
29+
private request: AbortController | undefined;
2930
private stopped: boolean = false;
3031

3132
public constructor(

src/config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path = require('path');
77

88
import shelljs = require('shelljs');
99

10+
import { Headers, RequestInit } from 'node-fetch';
1011
import * as api from './api';
1112
import { Authenticator } from './auth';
1213
import { AzureAuth } from './azure_auth';
@@ -146,6 +147,26 @@ export class KubeConfig implements SecurityAuthentication {
146147
this.makePathsAbsolute(rootDirectory);
147148
}
148149

150+
public async applytoFetchOptions(opts: https.RequestOptions): Promise<RequestInit> {
151+
await this.applytoHTTPSOptions(opts);
152+
const headers = new Headers();
153+
for (const [key, val] of Object.entries(opts.headers || {})) {
154+
if (Array.isArray(val)) {
155+
val.forEach((innerVal) => {
156+
headers.append(key, innerVal);
157+
});
158+
} else if (typeof val === 'number' || typeof val === 'string') {
159+
headers.set(key, val.toString());
160+
}
161+
}
162+
return {
163+
agent: opts.agent,
164+
headers,
165+
method: opts.method,
166+
timeout: opts.timeout,
167+
};
168+
}
169+
149170
public async applytoHTTPSOptions(opts: https.RequestOptions): Promise<void> {
150171
const user = this.getCurrentUser();
151172

src/gen/apis/exception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*/
1010
export class ApiException<T> extends Error {
11-
public constructor(public code: number, message: string, public body: T, public headers: { [key: string]: string; }) {
11+
public constructor(public code: number, message: string, public body: T, public headers: { [key: string]: string | string[]; }) {
1212
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body) + "\nHeaders: " +
1313
JSON.stringify(headers))
1414
}

0 commit comments

Comments
 (0)