mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make apiBase not an InjectionToken and make openNodeShellSession not special (#6774)
* Replace apiBaseInjectionToken with tokens for configuration instead Signed-off-by: Sebastian Malton <sebastian@malton.name> * Use new ordering to make openNodeShellSession non-special Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
de789ff955
commit
5c6402b60a
14
src/common/k8s-api/api-base-configs.ts
Normal file
14
src/common/k8s-api/api-base-configs.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 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 apiBaseServerAddressInjectionToken = getInjectionToken<string>({
|
||||
id: "api-base-config-server-address-token",
|
||||
});
|
||||
|
||||
export const apiBaseHostHeaderInjectionToken = getInjectionToken<string>({
|
||||
id: "api-base-host-header-token",
|
||||
});
|
||||
33
src/common/k8s-api/api-base.injectable.ts
Normal file
33
src/common/k8s-api/api-base.injectable.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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 { apiPrefix } from "../vars";
|
||||
import isDebuggingInjectable from "../vars/is-debugging.injectable";
|
||||
import isDevelopmentInjectable from "../vars/is-development.injectable";
|
||||
import { apiBaseHostHeaderInjectionToken, apiBaseServerAddressInjectionToken } from "./api-base-configs";
|
||||
import createJsonApiInjectable from "./create-json-api.injectable";
|
||||
|
||||
const apiBaseInjectable = getInjectable({
|
||||
id: "api-base",
|
||||
instantiate: (di) => {
|
||||
const createJsonApi = di.inject(createJsonApiInjectable);
|
||||
const isDebugging = di.inject(isDebuggingInjectable);
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const serverAddress = di.inject(apiBaseServerAddressInjectionToken);
|
||||
const hostHeaderValue = di.inject(apiBaseHostHeaderInjectionToken);
|
||||
|
||||
return createJsonApi({
|
||||
serverAddress,
|
||||
apiBase: apiPrefix,
|
||||
debug: isDevelopment || isDebugging,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": hostHeaderValue,
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default apiBaseInjectable;
|
||||
@ -1,11 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { JsonApi } from "./json-api";
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
|
||||
export const apiBaseInjectionToken = getInjectionToken<JsonApi>({
|
||||
id: "api-base-token",
|
||||
});
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiKubePrefix } from "../vars";
|
||||
import isDevelopmentInjectable from "../vars/is-development.injectable";
|
||||
import { apiBaseInjectionToken } from "./api-base";
|
||||
import apiBaseInjectable from "./api-base.injectable";
|
||||
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
|
||||
import type { KubeApiOptions } from "./kube-api";
|
||||
import { KubeApi } from "./kube-api";
|
||||
@ -33,7 +33,7 @@ export interface CreateKubeApiForCluster {
|
||||
const createKubeApiForClusterInjectable = getInjectable({
|
||||
id: "create-kube-api-for-cluster",
|
||||
instantiate: (di): CreateKubeApiForCluster => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiKubePrefix } from "../vars";
|
||||
import isDebuggingInjectable from "../vars/is-debugging.injectable";
|
||||
import { apiBaseInjectionToken } from "./api-base";
|
||||
import { apiBaseHostHeaderInjectionToken, apiBaseServerAddressInjectionToken } from "./api-base-configs";
|
||||
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
|
||||
import type { KubeJsonApi } from "./kube-json-api";
|
||||
|
||||
@ -14,19 +14,18 @@ export type CreateKubeJsonApiForCluster = (clusterId: string) => KubeJsonApi;
|
||||
const createKubeJsonApiForClusterInjectable = getInjectable({
|
||||
id: "create-kube-json-api-for-cluster",
|
||||
instantiate: (di): CreateKubeJsonApiForCluster => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
const isDebugging = di.inject(isDebuggingInjectable);
|
||||
|
||||
return (clusterId) => createKubeJsonApi(
|
||||
{
|
||||
serverAddress: apiBase.config.serverAddress,
|
||||
serverAddress: di.inject(apiBaseServerAddressInjectionToken),
|
||||
apiBase: apiKubePrefix,
|
||||
debug: isDebugging,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"Host": `${clusterId}.localhost:${new URL(apiBase.config.serverAddress).port}`,
|
||||
"Host": `${clusterId}.${di.inject(apiBaseHostHeaderInjectionToken)}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import type { RawHelmChart } from "../helm-charts.api";
|
||||
import { HelmChart } from "../helm-charts.api";
|
||||
import { isDefined } from "../../../utils";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmCharts = () => Promise<HelmChart[]>;
|
||||
export type RepoHelmChartList = Record<string, RawHelmChart[]>;
|
||||
@ -17,7 +17,7 @@ export type RepoHelmChartList = Record<string, RawHelmChart[]>;
|
||||
const requestHelmChartsInjectable = getInjectable({
|
||||
id: "request-helm-charts",
|
||||
instantiate: (di) => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return async () => {
|
||||
const data = await apiBase.get<Record<string, RepoHelmChartList>>("/v2/charts");
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestReadmeEndpoint = urlBuilderFor("/v2/charts/:repo/:name/readme");
|
||||
|
||||
@ -13,7 +13,7 @@ export type RequestHelmChartReadme = (repo: string, name: string, version?: stri
|
||||
const requestHelmChartReadmeInjectable = getInjectable({
|
||||
id: "request-helm-chart-readme",
|
||||
instantiate: (di): RequestHelmChartReadme => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (repo, name, version) => (
|
||||
apiBase.get(requestReadmeEndpoint.compile({ name, repo }, { version }))
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values");
|
||||
|
||||
@ -13,7 +13,7 @@ export type RequestHelmChartValues = (repo: string, name: string, version: strin
|
||||
const requestHelmChartValuesInjectable = getInjectable({
|
||||
id: "request-helm-chart-values",
|
||||
instantiate: (di): RequestHelmChartValues => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (repo, name, version) => (
|
||||
apiBase.get(requestValuesEndpoint.compile({ repo, name }, { version }))
|
||||
|
||||
@ -4,10 +4,10 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import { HelmChart } from "../helm-charts.api";
|
||||
import type { RawHelmChart } from "../helm-charts.api";
|
||||
import { isDefined } from "../../../utils";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestVersionsEndpoint = urlBuilderFor("/v2/charts/:repo/:name/versions");
|
||||
|
||||
@ -16,7 +16,7 @@ export type RequestHelmChartVersions = (repo: string, chartName: string) => Prom
|
||||
const requestHelmChartVersionsInjectable = getInjectable({
|
||||
id: "request-helm-chart-versions",
|
||||
instantiate: (di): RequestHelmChartVersions => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return async (repo, name) => {
|
||||
const rawVersions = await apiBase.get(requestVersionsEndpoint.compile({ name, repo })) as RawHelmChart[];
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseConfiguration = (
|
||||
name: string,
|
||||
@ -18,7 +18,7 @@ const requestHelmReleaseConfigurationInjectable = getInjectable({
|
||||
id: "request-helm-release-configuration",
|
||||
|
||||
instantiate: (di): RequestHelmReleaseConfiguration => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (name, namespace, all: boolean) => (
|
||||
apiBase.get(requestConfigurationEnpoint.compile({ name, namespace }, { all }))
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
import yaml from "js-yaml";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { HelmReleaseUpdateDetails } from "../helm-releases.api";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
interface HelmReleaseCreatePayload {
|
||||
name?: string;
|
||||
@ -25,7 +25,7 @@ const requestCreateHelmReleaseInjectable = getInjectable({
|
||||
id: "request-create-helm-release",
|
||||
|
||||
instantiate: (di): RequestCreateHelmRelease => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return ({ repo, chart, values, ...data }) => {
|
||||
return apiBase.post(requestCreateEndpoint.compile({}), {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestDeleteHelmRelease = (name: string, namespace: string) => Promise<void>;
|
||||
|
||||
@ -13,7 +13,7 @@ const requestDeleteEndpoint = urlBuilderFor("/v2/releases/:namespace/:name");
|
||||
const requestDeleteHelmReleaseInjectable = getInjectable({
|
||||
id: "request-delete-helm-release",
|
||||
instantiate: (di): RequestDeleteHelmRelease => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (name, namespace) => apiBase.del(requestDeleteEndpoint.compile({ name, namespace }));
|
||||
},
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export interface HelmReleaseDetails {
|
||||
resources: KubeJsonApiData[];
|
||||
@ -32,7 +32,7 @@ const requestHelmReleaseDetailsInjectable = getInjectable({
|
||||
id: "call-for-helm-release-details",
|
||||
|
||||
instantiate: (di): CallForHelmReleaseDetails => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (name, namespace) => apiBase.get(requestDetailsEnpoint.compile({ name, namespace }));
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export interface HelmReleaseRevision {
|
||||
revision: number;
|
||||
@ -22,7 +22,7 @@ const requestHistoryEnpoint = urlBuilderFor("/v2/releases/:namespace/:name/histo
|
||||
const requestHelmReleaseHistoryInjectable = getInjectable({
|
||||
id: "request-helm-release-history",
|
||||
instantiate: (di): RequestHelmReleaseHistory => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (name, namespace) => apiBase.get(requestHistoryEnpoint.compile({ name, namespace }));
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { HelmReleaseDto } from "../helm-releases.api";
|
||||
|
||||
export type RequestHelmReleases = (namespace?: string) => Promise<HelmReleaseDto[]>;
|
||||
@ -15,7 +15,7 @@ const requestHelmReleasesInjectable = getInjectable({
|
||||
id: "request-helm-releases",
|
||||
|
||||
instantiate: (di): RequestHelmReleases => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (namespace) => apiBase.get(requestHelmReleasesEndpoint.compile({ namespace }));
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseRollback = (name: string, namespace: string, revision: number) => Promise<void>;
|
||||
|
||||
@ -13,7 +13,7 @@ const requestRollbackEndpoint = urlBuilderFor("/v2/releases/:namespace/:name");
|
||||
const requestHelmReleaseRollbackInjectable = getInjectable({
|
||||
id: "request-helm-release-rollback",
|
||||
instantiate: (di): RequestHelmReleaseRollback => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return async (name, namespace, revision) => {
|
||||
await apiBase.put(
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
interface HelmReleaseUpdatePayload {
|
||||
repo: string;
|
||||
@ -26,7 +26,7 @@ const requestHelmReleaseUpdateInjectable = getInjectable({
|
||||
id: "request-helm-release-update",
|
||||
|
||||
instantiate: (di): RequestHelmReleaseUpdate => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return async (name, namespace, { repo, chart, values, version }) => {
|
||||
try {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseValues = (name: string, namespace: string, all?: boolean) => Promise<string>;
|
||||
|
||||
@ -13,7 +13,7 @@ const requestValuesEndpoint = urlBuilderFor("/v2/release/:namespace/:name/values
|
||||
const requestHelmReleaseValuesInjectable = getInjectable({
|
||||
id: "request-helm-release-values",
|
||||
instantiate: (di): RequestHelmReleaseValues => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (name, namespace, all) => apiBase.get(requestValuesEndpoint.compile({ name, namespace }, { all }));
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getSecondsFromUnixEpoch } from "../../../utils/date/get-current-date-time";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ export interface RequestMetrics {
|
||||
const requestMetricsInjectable = getInjectable({
|
||||
id: "request-metrics",
|
||||
instantiate: (di) => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (async (query: object, params: RequestMetricsParams = {}) => {
|
||||
const { range = 3600, step = 60, namespace } = params;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export interface MetricProviderInfo {
|
||||
name: string;
|
||||
@ -17,7 +17,7 @@ export type RequestMetricsProviders = () => Promise<MetricProviderInfo[]>;
|
||||
const requestMetricsProvidersInjectable = getInjectable({
|
||||
id: "request-metrics-providers",
|
||||
instantiate: (di): RequestMetricsProviders => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return () => apiBase.get("/metrics/providers");
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Patch } from "rfc6902";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => Promise<KubeJsonApiData>;
|
||||
@ -12,7 +12,7 @@ export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | u
|
||||
const requestKubeObjectPatchInjectable = getInjectable({
|
||||
id: "request-kube-object-patch",
|
||||
instantiate: (di): RequestKubeObjectPatch => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (name, kind, ns, patch) => (
|
||||
apiBase.patch("/stack", {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<KubeJsonApiData>;
|
||||
@ -11,7 +11,7 @@ export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<
|
||||
const requestKubeObjectCreationInjectable = getInjectable({
|
||||
id: "request-kube-object-creation",
|
||||
instantiate: (di): RequestKubeObjectCreation => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (data) => apiBase.post("/stack", { data });
|
||||
},
|
||||
|
||||
19
src/main/k8s/api-base-host-header.injectable.ts
Normal file
19
src/main/k8s/api-base-host-header.injectable.ts
Normal file
@ -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 { apiBaseHostHeaderInjectionToken } from "../../common/k8s-api/api-base-configs";
|
||||
import lensProxyPortInjectable from "../lens-proxy/lens-proxy-port.injectable";
|
||||
|
||||
const apiBaseHostHeaderInjectable = getInjectable({
|
||||
id: "api-base-host-header",
|
||||
instantiate: (di) => {
|
||||
const lensProxyPort = di.inject(lensProxyPortInjectable);
|
||||
|
||||
return `localhost:${lensProxyPort.get()}`;
|
||||
},
|
||||
injectionToken: apiBaseHostHeaderInjectionToken,
|
||||
});
|
||||
|
||||
export default apiBaseHostHeaderInjectable;
|
||||
19
src/main/k8s/api-base-server-address.injectable.ts
Normal file
19
src/main/k8s/api-base-server-address.injectable.ts
Normal file
@ -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 { apiBaseServerAddressInjectionToken } from "../../common/k8s-api/api-base-configs";
|
||||
import lensProxyPortInjectable from "../lens-proxy/lens-proxy-port.injectable";
|
||||
|
||||
const apiBaseServerAddressInjectable = getInjectable({
|
||||
id: "api-base-server-address",
|
||||
instantiate: (di) => {
|
||||
const lensProxyPort = di.inject(lensProxyPortInjectable);
|
||||
|
||||
return `http://127.0.0.1:${lensProxyPort.get()}`;
|
||||
},
|
||||
injectionToken: apiBaseServerAddressInjectionToken,
|
||||
});
|
||||
|
||||
export default apiBaseServerAddressInjectable;
|
||||
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* 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 { apiBaseInjectionToken } from "../../common/k8s-api/api-base";
|
||||
import createJsonApiInjectable from "../../common/k8s-api/create-json-api.injectable";
|
||||
import { apiPrefix } from "../../common/vars";
|
||||
import isDebuggingInjectable from "../../common/vars/is-debugging.injectable";
|
||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||
import lensProxyPortInjectable from "../lens-proxy/lens-proxy-port.injectable";
|
||||
|
||||
const apiBaseInjectable = getInjectable({
|
||||
id: "api-base",
|
||||
instantiate: (di) => {
|
||||
const proxyPort = di.inject(lensProxyPortInjectable);
|
||||
const createJsonApi = di.inject(createJsonApiInjectable);
|
||||
const isDebugging = di.inject(isDebuggingInjectable);
|
||||
|
||||
return createJsonApi({
|
||||
serverAddress: `http://127.0.0.1:${proxyPort.get()}`,
|
||||
apiBase: apiPrefix,
|
||||
debug: di.inject(isDevelopmentInjectable) || isDebugging,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": `localhost:${proxyPort.get()}`,
|
||||
},
|
||||
});
|
||||
},
|
||||
injectionToken: apiBaseInjectionToken,
|
||||
});
|
||||
|
||||
export default apiBaseInjectable;
|
||||
@ -22,10 +22,11 @@ const openShellSessionInjectable = getInjectable({
|
||||
|
||||
instantiate: (di): OpenShellSession => {
|
||||
const openLocalShellSession = di.inject(openLocalShellSessionInjectable);
|
||||
const openNodeShellSession = di.inject(openNodeShellSessionInjectable);
|
||||
|
||||
return ({ nodeName, ...args }) => (
|
||||
nodeName
|
||||
? di.inject(openNodeShellSessionInjectable, { nodeName, ...args })
|
||||
? openNodeShellSession({ nodeName, ...args })
|
||||
: openLocalShellSession(args)
|
||||
);
|
||||
},
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import type WebSocket from "ws";
|
||||
import createKubectlInjectable from "../../kubectl/create-kubectl.injectable";
|
||||
@ -27,9 +27,11 @@ export interface NodeShellSessionArgs {
|
||||
nodeName: string;
|
||||
}
|
||||
|
||||
export type OpenNodeShellSession = (args: NodeShellSessionArgs) => Promise<void>;
|
||||
|
||||
const openNodeShellSessionInjectable = getInjectable({
|
||||
id: "open-node-shell-session",
|
||||
instantiate: (di, params: NodeShellSessionArgs) => {
|
||||
instantiate: (di): OpenNodeShellSession => {
|
||||
const createKubectl = di.inject(createKubectlInjectable);
|
||||
const dependencies: NodeShellSessionDependencies = {
|
||||
isMac: di.inject(isMacInjectable),
|
||||
@ -44,13 +46,14 @@ const openNodeShellSessionInjectable = getInjectable({
|
||||
emitAppEvent: di.inject(emitAppEventInjectable),
|
||||
stat: di.inject(statInjectable),
|
||||
};
|
||||
const kubectl = createKubectl(params.cluster.version);
|
||||
const session = new NodeShellSession(dependencies, { kubectl, ...params });
|
||||
|
||||
return session.open();
|
||||
return async (args) => {
|
||||
const kubectl = createKubectl(args.cluster.version);
|
||||
const session = new NodeShellSession(dependencies, { kubectl, ...args });
|
||||
|
||||
return session.open();
|
||||
};
|
||||
},
|
||||
// NOTE: this must be transient to bypass the circular dependency of `createKubeJsonApiForClusterInjectable` on the lens proxy port
|
||||
lifecycle: lifecycleEnum.transient,
|
||||
});
|
||||
|
||||
export default openNodeShellSessionInjectable;
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import apiBaseInjectable from "../../../common/k8s-api/api-base.injectable";
|
||||
import type { ServiceAccount } from "../../../common/k8s-api/endpoints";
|
||||
import { urlBuilderFor } from "../../../common/utils/buildUrl";
|
||||
import apiBaseInjectable from "../../k8s/api-base.injectable";
|
||||
import openKubeconfigDialogInjectable from "./open.injectable";
|
||||
|
||||
export type OpenServiceAccountKubeConfigDialog = (account: ServiceAccount) => void;
|
||||
|
||||
15
src/renderer/k8s/api-base-host-header.injectable.ts
Normal file
15
src/renderer/k8s/api-base-host-header.injectable.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 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 { apiBaseHostHeaderInjectionToken } from "../../common/k8s-api/api-base-configs";
|
||||
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
|
||||
|
||||
const apiBaseHostHeaderInjectable = getInjectable({
|
||||
id: "api-base-host-header",
|
||||
instantiate: (di) => di.inject(windowLocationInjectable).host,
|
||||
injectionToken: apiBaseHostHeaderInjectionToken,
|
||||
});
|
||||
|
||||
export default apiBaseHostHeaderInjectable;
|
||||
19
src/renderer/k8s/api-base-server-address.injectable.ts
Normal file
19
src/renderer/k8s/api-base-server-address.injectable.ts
Normal file
@ -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 { apiBaseServerAddressInjectionToken } from "../../common/k8s-api/api-base-configs";
|
||||
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
|
||||
|
||||
const apiBaseServerAddressInjectable = getInjectable({
|
||||
id: "api-base-server-address",
|
||||
instantiate: (di) => {
|
||||
const { port } = di.inject(windowLocationInjectable);
|
||||
|
||||
return `http://127.0.0.1:${port}`;
|
||||
},
|
||||
injectionToken: apiBaseServerAddressInjectionToken,
|
||||
});
|
||||
|
||||
export default apiBaseServerAddressInjectable;
|
||||
@ -1,36 +0,0 @@
|
||||
/**
|
||||
* 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 { apiBaseInjectionToken } from "../../common/k8s-api/api-base";
|
||||
import createJsonApiInjectable from "../../common/k8s-api/create-json-api.injectable";
|
||||
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
|
||||
import { apiPrefix } from "../../common/vars";
|
||||
import isDebuggingInjectable from "../../common/vars/is-debugging.injectable";
|
||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||
|
||||
const apiBaseInjectable = getInjectable({
|
||||
id: "api-base",
|
||||
instantiate: (di) => {
|
||||
const createJsonApi = di.inject(createJsonApiInjectable);
|
||||
const isDebugging = di.inject(isDebuggingInjectable);
|
||||
const { port, host } = di.inject(windowLocationInjectable);
|
||||
|
||||
return createJsonApi(
|
||||
{
|
||||
serverAddress: `http://127.0.0.1:${port}`,
|
||||
apiBase: apiPrefix,
|
||||
debug: di.inject(isDevelopmentInjectable) || isDebugging,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"Host": host,
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
injectionToken: apiBaseInjectionToken,
|
||||
});
|
||||
|
||||
export default apiBaseInjectable;
|
||||
@ -7,8 +7,8 @@ import { PortForwardStore } from "./port-forward-store";
|
||||
import type { ForwardedPort } from "../port-forward-item";
|
||||
import createStorageInjectable from "../../utils/create-storage/create-storage.injectable";
|
||||
import notifyErrorPortForwardingInjectable from "../notify-error-port-forwarding.injectable";
|
||||
import { apiBaseInjectionToken } from "../../../common/k8s-api/api-base";
|
||||
import requestActivePortForwardInjectable from "./request-active-port-forward.injectable";
|
||||
import apiBaseInjectable from "../../../common/k8s-api/api-base.injectable";
|
||||
|
||||
const portForwardStoreInjectable = getInjectable({
|
||||
id: "port-forward-store",
|
||||
@ -22,7 +22,7 @@ const portForwardStoreInjectable = getInjectable({
|
||||
undefined,
|
||||
),
|
||||
notifyErrorPortForwarding: di.inject(notifyErrorPortForwardingInjectable),
|
||||
apiBase: di.inject(apiBaseInjectionToken),
|
||||
apiBase: di.inject(apiBaseInjectable),
|
||||
requestActivePortForward: di.inject(requestActivePortForwardInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiBaseInjectionToken } from "../../../common/k8s-api/api-base";
|
||||
import apiBaseInjectable from "../../../common/k8s-api/api-base.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import { urlBuilderFor } from "../../../common/utils/buildUrl";
|
||||
import type { ForwardedPort } from "../port-forward-item";
|
||||
@ -16,7 +16,7 @@ const requestActiveEndpoint = urlBuilderFor("/pods/port-forward/:namespace/:kind
|
||||
const requestActivePortForwardInjectable = getInjectable({
|
||||
id: "request-active-port-forward",
|
||||
instantiate: (di): RequestActivePortForward => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return async ({ port, forwardPort, namespace, kind, name, ...rest }) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user