mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove depricated package request from our code
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
1 parent
33c405bdcf
commit
47fbf629ea
19 files changed
+397
-269
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { Options } from "got/dist/source";
|
||||
import { HttpsProxyAgent } from "hpagent";
|
||||
import { userStore } from "./user-store";
|
||||
|
||||
declare type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
||||
declare type Merge<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
|
||||
export type GotStreamFunctionOptions = Merge<Options, {
|
||||
isStream?: true;
|
||||
}>;
|
||||
|
||||
export function defaultGotOptions(): Options {
|
||||
const { httpsProxy, allowUntrustedCAs } = userStore.preferences;
|
||||
const rejectUnauthorized = !allowUntrustedCAs;
|
||||
|
||||
if (!httpsProxy) {
|
||||
return { rejectUnauthorized };
|
||||
}
|
||||
|
||||
const https = new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
proxy: httpsProxy,
|
||||
});
|
||||
|
||||
return {
|
||||
agent: { https },
|
||||
rejectUnauthorized,
|
||||
};
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import request from "request";
|
||||
import requestPromise from "request-promise-native";
|
||||
import { userStore } from "./user-store";
|
||||
|
||||
// todo: get rid of "request" (deprecated)
|
||||
// https://github.com/lensapp/lens/issues/459
|
||||
|
||||
function getDefaultRequestOpts(): Partial<request.Options> {
|
||||
const { httpsProxy, allowUntrustedCAs } = userStore.preferences;
|
||||
|
||||
return {
|
||||
proxy: httpsProxy || undefined,
|
||||
rejectUnauthorized: !allowUntrustedCAs,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export function customRequest(opts: request.Options) {
|
||||
return request.defaults(getDefaultRequestOpts())(opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export function customRequestPromise(opts: requestPromise.Options) {
|
||||
return requestPromise.defaults(getDefaultRequestOpts())(opts);
|
||||
}
|
||||
Reference in new issue
Block a user