mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix integration tests failing
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2f12b78a40
commit
7c5b14123c
@ -3,12 +3,12 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import lensFetchInjectable from "../fetch/lens-fetch.injectable";
|
import lensFetchInjectable from "../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
import loggerInjectable from "../logger.injectable";
|
import loggerInjectable from "../logger.injectable";
|
||||||
import { apiPrefix } from "../vars";
|
import { apiPrefix } from "../vars";
|
||||||
import { apiBaseHostHeaderInjectionToken, apiBaseServerAddressInjectionToken } from "./api-base-configs";
|
import { apiBaseHostHeaderInjectionToken } from "./api-base-configs";
|
||||||
import isApiBaseInDebugModeInjectable from "./is-api-in-debug-mode.injectable";
|
import isApiBaseInDebugModeInjectable from "./is-api-in-debug-mode.injectable";
|
||||||
import { JsonApi } from "./json-api";
|
import { JsonApi, usingLensFetch } from "./json-api";
|
||||||
|
|
||||||
const apiBaseInjectable = getInjectable({
|
const apiBaseInjectable = getInjectable({
|
||||||
id: "api-base",
|
id: "api-base",
|
||||||
@ -16,7 +16,7 @@ const apiBaseInjectable = getInjectable({
|
|||||||
fetch: di.inject(lensFetchInjectable),
|
fetch: di.inject(lensFetchInjectable),
|
||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
}, {
|
}, {
|
||||||
serverAddress: di.inject(apiBaseServerAddressInjectionToken),
|
serverAddress: usingLensFetch,
|
||||||
apiBase: apiPrefix,
|
apiBase: apiPrefix,
|
||||||
debug: di.inject(isApiBaseInDebugModeInjectable),
|
debug: di.inject(isApiBaseInDebugModeInjectable),
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import loggerInjectable from "../logger.injectable";
|
import loggerInjectable from "../logger.injectable";
|
||||||
import { apiKubePrefix } from "../vars";
|
import { apiKubePrefix } from "../vars";
|
||||||
import isDevelopmentInjectable from "../vars/is-development.injectable";
|
import isDevelopmentInjectable from "../vars/is-development.injectable";
|
||||||
import apiBaseInjectable from "./api-base.injectable";
|
import { apiBaseServerAddressInjectionToken } from "./api-base-configs";
|
||||||
import type { KubeApiConstructor } from "./create-kube-api-for-remote-cluster.injectable";
|
import type { KubeApiConstructor } from "./create-kube-api-for-remote-cluster.injectable";
|
||||||
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
|
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
|
||||||
import { KubeApi } from "./kube-api";
|
import { KubeApi } from "./kube-api";
|
||||||
@ -34,10 +34,11 @@ export interface CreateKubeApiForCluster {
|
|||||||
const createKubeApiForClusterInjectable = getInjectable({
|
const createKubeApiForClusterInjectable = getInjectable({
|
||||||
id: "create-kube-api-for-cluster",
|
id: "create-kube-api-for-cluster",
|
||||||
instantiate: (di): CreateKubeApiForCluster => {
|
instantiate: (di): CreateKubeApiForCluster => {
|
||||||
const apiBase = di.inject(apiBaseInjectable);
|
|
||||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||||
const logger = di.inject(loggerInjectable);
|
const logger = di.inject(loggerInjectable);
|
||||||
|
const apiBaseServerAddress = di.inject(apiBaseServerAddressInjectionToken);
|
||||||
|
const { port } = new URL(apiBaseServerAddress);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
cluster: CreateKubeApiForLocalClusterConfig,
|
cluster: CreateKubeApiForLocalClusterConfig,
|
||||||
@ -46,12 +47,12 @@ const createKubeApiForClusterInjectable = getInjectable({
|
|||||||
) => {
|
) => {
|
||||||
const request = createKubeJsonApi(
|
const request = createKubeJsonApi(
|
||||||
{
|
{
|
||||||
serverAddress: apiBase.config.serverAddress,
|
serverAddress: apiBaseServerAddress,
|
||||||
apiBase: apiKubePrefix,
|
apiBase: apiKubePrefix,
|
||||||
debug: isDevelopment,
|
debug: isDevelopment,
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
"Host": `${cluster.metadata.uid}.lens.app:${new URL(apiBase.config.serverAddress).port}`,
|
"Host": `${cluster.metadata.uid}.lens.app:${port}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,14 +9,14 @@ import { Agent as HttpAgent } from "http";
|
|||||||
import { Agent as HttpsAgent } from "https";
|
import { Agent as HttpsAgent } from "https";
|
||||||
import { merge } from "lodash";
|
import { merge } from "lodash";
|
||||||
import type { Response, RequestInit } from "@k8slens/node-fetch";
|
import type { Response, RequestInit } from "@k8slens/node-fetch";
|
||||||
import { stringify } from "querystring";
|
|
||||||
import type { Patch } from "rfc6902";
|
import type { Patch } from "rfc6902";
|
||||||
import type { PartialDeep, ValueOf } from "type-fest";
|
import type { PartialDeep, SetRequired, ValueOf } from "type-fest";
|
||||||
import { EventEmitter } from "../../common/event-emitter";
|
import { EventEmitter } from "../../common/event-emitter";
|
||||||
import type { Logger } from "../../common/logger";
|
import type { Logger } from "../../common/logger";
|
||||||
import type { Fetch } from "../fetch/fetch.injectable";
|
import type { Fetch } from "../fetch/fetch.injectable";
|
||||||
import type { Defaulted } from "@k8slens/utilities";
|
import type { Defaulted } from "@k8slens/utilities";
|
||||||
import { isObject, isString, json } from "@k8slens/utilities";
|
import { object, isObject, isString, json } from "@k8slens/utilities";
|
||||||
|
import { format, parse, URLSearchParams } from "url";
|
||||||
|
|
||||||
export interface JsonApiData {}
|
export interface JsonApiData {}
|
||||||
|
|
||||||
@ -40,13 +40,19 @@ export interface JsonApiLog {
|
|||||||
|
|
||||||
export type GetRequestOptions = () => Promise<RequestInit>;
|
export type GetRequestOptions = () => Promise<RequestInit>;
|
||||||
|
|
||||||
|
export const usingLensFetch = Symbol("using-lens-fetch");
|
||||||
|
|
||||||
export interface JsonApiConfig {
|
export interface JsonApiConfig {
|
||||||
apiBase: string;
|
apiBase: string;
|
||||||
serverAddress: string;
|
serverAddress: string | typeof usingLensFetch;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
getRequestOptions?: GetRequestOptions;
|
getRequestOptions?: GetRequestOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface InternalJsonApiConfig extends JsonApiConfig {
|
||||||
|
serverAddress: string | typeof usingLensFetch;
|
||||||
|
}
|
||||||
|
|
||||||
const httpAgent = new HttpAgent({ keepAlive: true });
|
const httpAgent = new HttpAgent({ keepAlive: true });
|
||||||
const httpsAgent = new HttpsAgent({ keepAlive: true });
|
const httpsAgent = new HttpsAgent({ keepAlive: true });
|
||||||
|
|
||||||
@ -64,6 +70,11 @@ export interface JsonApiDependencies {
|
|||||||
readonly logger: Logger;
|
readonly logger: Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface RequestDetails {
|
||||||
|
reqUrl: string;
|
||||||
|
reqInit: SetRequired<RequestInit, "method">;
|
||||||
|
}
|
||||||
|
|
||||||
export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = JsonApiParams<Data>> {
|
export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = JsonApiParams<Data>> {
|
||||||
static readonly reqInitDefault = {
|
static readonly reqInitDefault = {
|
||||||
headers: {
|
headers: {
|
||||||
@ -76,7 +87,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
|||||||
debug: false,
|
debug: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(protected readonly dependencies: JsonApiDependencies, public readonly config: JsonApiConfig, reqInit?: RequestInit) {
|
constructor(protected readonly dependencies: JsonApiDependencies, public readonly config: InternalJsonApiConfig, reqInit?: RequestInit) {
|
||||||
this.config = Object.assign({}, JsonApi.configDefault, config);
|
this.config = Object.assign({}, JsonApi.configDefault, config);
|
||||||
this.reqInit = merge({}, JsonApi.reqInitDefault, reqInit);
|
this.reqInit = merge({}, JsonApi.reqInitDefault, reqInit);
|
||||||
this.parseResponse = this.parseResponse.bind(this);
|
this.parseResponse = this.parseResponse.bind(this);
|
||||||
@ -87,28 +98,53 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
|||||||
public readonly onError = new EventEmitter<[JsonApiErrorParsed, Response]>();
|
public readonly onError = new EventEmitter<[JsonApiErrorParsed, Response]>();
|
||||||
private readonly getRequestOptions: GetRequestOptions;
|
private readonly getRequestOptions: GetRequestOptions;
|
||||||
|
|
||||||
|
private async getRequestDetails(
|
||||||
|
path: string,
|
||||||
|
query: Partial<Record<string, string>> | undefined,
|
||||||
|
init: RequestInit,
|
||||||
|
): Promise<RequestDetails> {
|
||||||
|
const reqUrl = (() => {
|
||||||
|
const base = this.config.serverAddress === usingLensFetch
|
||||||
|
? parse(`${this.config.apiBase}${path}`)
|
||||||
|
: parse(`${this.config.serverAddress}${this.config.apiBase}${path}`);
|
||||||
|
const searchParams = new URLSearchParams(base.query ?? undefined);
|
||||||
|
|
||||||
|
for (const [key, value] of object.entries(query ?? {})) {
|
||||||
|
searchParams.append(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return format({ ...base, query: searchParams.toString() });
|
||||||
|
})();
|
||||||
|
const reqInit = await (async () => {
|
||||||
|
const baseInit: SetRequired<RequestInit, "method"> = { method: "get" };
|
||||||
|
|
||||||
|
if (this.config.serverAddress !== usingLensFetch) {
|
||||||
|
baseInit.agent = this.config.serverAddress.startsWith("https://")
|
||||||
|
? httpsAgent
|
||||||
|
: httpAgent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return merge(
|
||||||
|
baseInit,
|
||||||
|
this.reqInit,
|
||||||
|
await this.getRequestOptions(),
|
||||||
|
init,
|
||||||
|
);
|
||||||
|
})();
|
||||||
|
|
||||||
|
return { reqInit, reqUrl };
|
||||||
|
}
|
||||||
|
|
||||||
async getResponse<Query>(
|
async getResponse<Query>(
|
||||||
path: string,
|
path: string,
|
||||||
params?: ParamsAndQuery<Params, Query>,
|
params?: ParamsAndQuery<Params, Query>,
|
||||||
init: RequestInit = {},
|
init: RequestInit = {},
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`;
|
const { reqInit, reqUrl } = await this.getRequestDetails(
|
||||||
const reqInit = merge(
|
path,
|
||||||
{
|
params?.query as Partial<Record<string, string>>,
|
||||||
method: "get",
|
|
||||||
agent: reqUrl.startsWith("https:") ? httpsAgent : httpAgent,
|
|
||||||
},
|
|
||||||
this.reqInit,
|
|
||||||
await this.getRequestOptions(),
|
|
||||||
init,
|
init,
|
||||||
);
|
);
|
||||||
const { query } = params ?? {};
|
|
||||||
|
|
||||||
if (query && Object.keys(query).length > 0) {
|
|
||||||
const queryString = stringify(query as unknown as QueryParams);
|
|
||||||
|
|
||||||
reqUrl += (reqUrl.includes("?") ? "&" : "?") + queryString;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.dependencies.fetch(reqUrl, reqInit);
|
return this.dependencies.fetch(reqUrl, reqInit);
|
||||||
}
|
}
|
||||||
@ -155,35 +191,27 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
|||||||
|
|
||||||
protected async request<OutData, Query = QueryParams>(
|
protected async request<OutData, Query = QueryParams>(
|
||||||
path: string,
|
path: string,
|
||||||
params: (ParamsAndQuery<Omit<Params, "data">, Query> & { data?: unknown }) | undefined,
|
rawParams: (ParamsAndQuery<Omit<Params, "data">, Query> & { data?: unknown }) | undefined,
|
||||||
init: Defaulted<RequestInit, "method">,
|
init: Defaulted<RequestInit, "method">,
|
||||||
) {
|
) {
|
||||||
let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`;
|
const { data, query } = rawParams ?? {};
|
||||||
const reqInit = merge(
|
const { reqInit, reqUrl } = await this.getRequestDetails(
|
||||||
{},
|
path,
|
||||||
this.reqInit,
|
query as Partial<Record<string, string>>,
|
||||||
await this.getRequestOptions(),
|
|
||||||
init,
|
init,
|
||||||
);
|
);
|
||||||
const { data, query } = params || {};
|
|
||||||
|
|
||||||
if (data && !reqInit.body) {
|
if (data && !reqInit.body) {
|
||||||
reqInit.body = JSON.stringify(data);
|
reqInit.body = JSON.stringify(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query && Object.keys(query).length > 0) {
|
const res = await this.dependencies.fetch(reqUrl, reqInit);
|
||||||
const queryString = stringify(query as unknown as QueryParams);
|
|
||||||
|
|
||||||
reqUrl += (reqUrl.includes("?") ? "&" : "?") + queryString;
|
|
||||||
}
|
|
||||||
const infoLog: JsonApiLog = {
|
const infoLog: JsonApiLog = {
|
||||||
method: reqInit.method.toUpperCase(),
|
method: reqInit.method.toUpperCase(),
|
||||||
reqUrl,
|
reqUrl,
|
||||||
reqInit,
|
reqInit,
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await this.dependencies.fetch(reqUrl, reqInit);
|
|
||||||
|
|
||||||
return await this.parseResponse(res, infoLog) as OutData;
|
return await this.parseResponse(res, infoLog) as OutData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
|
export const lensFetchBaseUrlInjectionToken = getInjectionToken<string>({
|
||||||
|
id: "lens-fetch-base-url-token",
|
||||||
|
});
|
||||||
@ -5,9 +5,9 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { Agent } from "https";
|
import { Agent } from "https";
|
||||||
import type { RequestInit, Response } from "@k8slens/node-fetch";
|
import type { RequestInit, Response } from "@k8slens/node-fetch";
|
||||||
import lensProxyPortInjectable from "../../main/lens-proxy/lens-proxy-port.injectable";
|
import lensProxyCertificateInjectable from "../../../common/certificate/lens-proxy-certificate.injectable";
|
||||||
import lensProxyCertificateInjectable from "../certificate/lens-proxy-certificate.injectable";
|
|
||||||
import fetch from "@k8slens/node-fetch";
|
import fetch from "@k8slens/node-fetch";
|
||||||
|
import { lensFetchBaseUrlInjectionToken } from "./lens-fetch-base-url";
|
||||||
|
|
||||||
export type LensRequestInit = Omit<RequestInit, "agent">;
|
export type LensRequestInit = Omit<RequestInit, "agent">;
|
||||||
|
|
||||||
@ -16,15 +16,15 @@ export type LensFetch = (pathnameAndQuery: string, init?: LensRequestInit) => Pr
|
|||||||
const lensFetchInjectable = getInjectable({
|
const lensFetchInjectable = getInjectable({
|
||||||
id: "lens-fetch",
|
id: "lens-fetch",
|
||||||
instantiate: (di): LensFetch => {
|
instantiate: (di): LensFetch => {
|
||||||
const lensProxyPort = di.inject(lensProxyPortInjectable);
|
|
||||||
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
|
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
|
||||||
|
|
||||||
return async (pathnameAndQuery, init = {}) => {
|
return async (pathnameAndQuery, init = {}) => {
|
||||||
const agent = new Agent({
|
const agent = new Agent({
|
||||||
ca: lensProxyCertificate.get().cert,
|
ca: lensProxyCertificate.get().cert,
|
||||||
|
keepAlive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return fetch(`https://127.0.0.1:${lensProxyPort.get()}${pathnameAndQuery}`, {
|
return fetch(`${di.inject(lensFetchBaseUrlInjectionToken)}${pathnameAndQuery}`, {
|
||||||
...init,
|
...init,
|
||||||
agent,
|
agent,
|
||||||
});
|
});
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import lensProxyPortInjectable from "../../../main/lens-proxy/lens-proxy-port.injectable";
|
||||||
|
import { lensFetchBaseUrlInjectionToken } from "../common/lens-fetch-base-url";
|
||||||
|
|
||||||
|
const lensFetchBaseUrlInjectable = getInjectable({
|
||||||
|
id: "lens-fetch-base-url",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const lensProxyPort = di.inject(lensProxyPortInjectable);
|
||||||
|
|
||||||
|
return `https://127.0.0.1:${lensProxyPort.get()}`;
|
||||||
|
},
|
||||||
|
injectionToken: lensFetchBaseUrlInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default lensFetchBaseUrlInjectable;
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import windowLocationInjectable from "../../../common/k8s-api/window-location.injectable";
|
||||||
|
import { lensFetchBaseUrlInjectionToken } from "../common/lens-fetch-base-url";
|
||||||
|
|
||||||
|
const lensFetchBaseUrlInjectable = getInjectable({
|
||||||
|
id: "lens-fetch-base-url",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const { port } = di.inject(windowLocationInjectable);
|
||||||
|
|
||||||
|
return `https://127.0.0.1:${port}`;
|
||||||
|
},
|
||||||
|
injectionToken: lensFetchBaseUrlInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default lensFetchBaseUrlInjectable;
|
||||||
@ -3,9 +3,9 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { LensRequestInit } from "../common/fetch/lens-fetch.injectable";
|
|
||||||
import lensFetchInjectable from "../common/fetch/lens-fetch.injectable";
|
|
||||||
import { withTimeout } from "../common/fetch/timeout-controller";
|
import { withTimeout } from "../common/fetch/timeout-controller";
|
||||||
|
import type { LensRequestInit } from "../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
import lensFetchInjectable from "../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
|
||||||
export interface K8sRequestInit extends LensRequestInit {
|
export interface K8sRequestInit extends LensRequestInit {
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { beforeApplicationIsLoadingInjectionToken } from "@k8slens/application";
|
|||||||
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
|
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
|
||||||
import initializeBuildVersionInjectable from "../../vars/build-version/init.injectable";
|
import initializeBuildVersionInjectable from "../../vars/build-version/init.injectable";
|
||||||
import startLensProxyListeningInjectable from "../../lens-proxy/start-listening.injectable";
|
import startLensProxyListeningInjectable from "../../lens-proxy/start-listening.injectable";
|
||||||
import lensFetchInjectable from "../../../common/fetch/lens-fetch.injectable";
|
import lensFetchInjectable from "../../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
|
||||||
const setupLensProxyInjectable = getInjectable({
|
const setupLensProxyInjectable = getInjectable({
|
||||||
id: "setup-lens-proxy",
|
id: "setup-lens-proxy",
|
||||||
|
|||||||
@ -7,24 +7,27 @@ import assert from "assert";
|
|||||||
import { apiKubePrefix } from "../../common/vars";
|
import { apiKubePrefix } from "../../common/vars";
|
||||||
import { apiKubeInjectionToken } from "../../common/k8s-api/api-kube";
|
import { apiKubeInjectionToken } from "../../common/k8s-api/api-kube";
|
||||||
import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token";
|
import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token";
|
||||||
import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-api.injectable";
|
|
||||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||||
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
||||||
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
|
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
|
||||||
import { apiBaseServerAddressInjectionToken } from "../../common/k8s-api/api-base-configs";
|
import { KubeJsonApi } from "../../common/k8s-api/kube-json-api";
|
||||||
|
import lensFetchInjectable from "../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
import loggerInjectable from "../../common/logger.injectable";
|
||||||
|
import { usingLensFetch } from "../../common/k8s-api/json-api";
|
||||||
|
|
||||||
const apiKubeInjectable = getInjectable({
|
const apiKubeInjectable = getInjectable({
|
||||||
id: "api-kube",
|
id: "api-kube",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "apiKube is only available in certain environments");
|
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "apiKube is only available in certain environments");
|
||||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
|
||||||
const apiBaseServerAddress = di.inject(apiBaseServerAddressInjectionToken);
|
|
||||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||||
const { host } = di.inject(windowLocationInjectable);
|
const { host } = di.inject(windowLocationInjectable);
|
||||||
|
|
||||||
const apiKube = createKubeJsonApi({
|
const apiKube = new KubeJsonApi({
|
||||||
serverAddress: apiBaseServerAddress,
|
fetch: di.inject(lensFetchInjectable),
|
||||||
|
logger: di.inject(loggerInjectable),
|
||||||
|
}, {
|
||||||
|
serverAddress: usingLensFetch,
|
||||||
apiBase: apiKubePrefix,
|
apiBase: apiKubePrefix,
|
||||||
debug: isDevelopment,
|
debug: isDevelopment,
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import lensFetchInjectable from "../common/fetch/lens-fetch.injectable";
|
import lensFetchInjectable from "../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
import { Headers, Response } from "@k8slens/node-fetch";
|
import { Headers, Response } from "@k8slens/node-fetch";
|
||||||
import handleRouteRequestInjectable from "../main/lens-proxy/handle-route-request.injectable";
|
import handleRouteRequestInjectable from "../main/lens-proxy/handle-route-request.injectable";
|
||||||
import fetchInjectable from "../common/fetch/fetch.injectable";
|
import fetchInjectable from "../common/fetch/fetch.injectable";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user