mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Turn on strict mode in tsconfig.json, some helpful lints, and required cleanup where strictness necessitates it (#5195)
* Turn on strict mode in tsconfig.json - Add route, clusterRoute, and payloadValidatedClusterRoute helper functions to improve types with backend routes - Turn on the following new lints: - react/jsx-first-prop-new-line - react/jsx-wrap-multilines - react/jsx-one-expression-per-line - react/jsx-max-props-per-line - react/jsx-indent - react/jsx-indent-props Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix build Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace KubeObject scope strings with enum Signed-off-by: Sebastian Malton <sebastian@malton.name> * Revert package.json version changes Signed-off-by: Sebastian Malton <sebastian@malton.name> * revert move hostedCluster(Id) Signed-off-by: Sebastian Malton <sebastian@malton.name> * change some type param names to be not single letters Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove copy-extension-themes Signed-off-by: Sebastian Malton <sebastian@malton.name> * add new make clean action Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix build to not use webpack for generating types Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube-object-menu.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix select.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * revert move fileNameMigration to index Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix ref logic error Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix log-resource-selector.test.tsx tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-store.test.ts test by overriding createStorage to not touch file system Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cluster.test.ts tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube=api.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fixed hotbar-store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kubeconfig-manager.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cluster-role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix pods.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix delete-cluster-dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix daemonset.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix replicaset.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix statefulsets/dialog/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix replicasets/scale-dialog/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix deployments.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix deployments/scale/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cronjob.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix stateful-set.api.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix deployment.api.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix api-manager.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix statefulset.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix job.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix pods.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix scroll-spy.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix hotbar-remove-command.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog-entity-registry.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix welcome.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix verify-that-all-routes-have-route-component.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix pod-tolerations.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * better fix for previous 3 fixes, plus also select.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube-object-menu.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix app-paths.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-tabs.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix isReactNode typing Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix sub-title.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix drawer.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix list-layout.tsx and header.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix error-boundary.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix upgrade-chart/store.ts and dock-tab.store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix install-chart/store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix edit-resource/store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix create-resource/store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix namespace-select.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix namespace-select-filter.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix crd-list.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix wrong types for extensions Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix circular dependency Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix circular dependency on catalogCategoryRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix api-kube Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix type errors, most <Select /> errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * fixing more type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * some more fixing type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * convert all KubeApis to injectable with legacy global backups Signed-off-by: Sebastian Malton <sebastian@malton.name> * factor out into a common file all the exports Signed-off-by: Sebastian Malton <sebastian@malton.name> * convert all KubeObjectStores to injectable with legacy global backups Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove unused legacy KubeApi globals Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix bad previous commit Signed-off-by: Sebastian Malton <sebastian@malton.name> * more crash fixing Signed-off-by: Sebastian Malton <sebastian@malton.name> * try and fix behavioural tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix sidebar-and-tab-navigation-for-core.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix sidebar-and-tab-navigation-for-extensions.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-using-application-menu.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make ThemeStore non-singleton and fix navigation-to-terminal-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * extensions.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog-entity-registry.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-using-application-menu.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix log-resource-selector.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-tabs.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix delete-cluster-dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-kubernetes-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-editor-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-proxy-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-using-application-menu.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-application-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix select.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix hotbar-remove-command.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cluster-role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-extension-specific-preferences.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-telemetry-preferences.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix closing-preferences.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-editor-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-proxy-preferences.test.ts - Fix other type errors too Signed-off-by: Sebastian Malton <sebastian@malton.name> * final tweaks Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add more tsconfig files, fix bug in <Catalog> - Make all of history, navigation injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert all of kube-details-params/ and navigate/ to injectable - This fixes a runtime error that was encountered during testing Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix runtime errors on renderer - remove all static uses of `createPageParam` (and then removed the legacy global) - Made LensRendererExtension and LensMainExtension just used dependencies and not the getLegacyDi - Fixed circular dep in extension-loader Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move registerStore calls to after injectMany Signed-off-by: Sebastian Malton <sebastian@malton.name> * replace all the rest of the legacy uses of apiManager Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix stack overflow and cycles in DI Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix NamespaceSelectFilter not opening Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix WizardStep and AddNamespaceDialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix KubeApi's not being registered Signed-off-by: Sebastian Malton <sebastian@malton.name> * cleanup WindowManager Signed-off-by: Sebastian Malton <sebastian@malton.name> * Proper fix for Wizard, fix NamespaceStore.subscribe Signed-off-by: Sebastian Malton <sebastian@malton.name> * Rewrite withTooltip to be more type correct - Fixes mobx related "too many recursive actions" error - Change all the uses of withTooltips to be functional components Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add e2e test to cover kube api registration Signed-off-by: Sebastian Malton <sebastian@malton.name> * cleanup internal-commands Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove cast in <Animate> Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix command-palette e2e test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error after rebase Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix test name Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix code to help CodeQL scanner Signed-off-by: Sebastian Malton <sebastian@malton.name> * update intree extension lock files Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix build-extensions picking wrong @types/react Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix tests from rebase Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make KubeconfigSyncManager more injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix crash in test mode for Dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * make Select snapshots deterministic Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix new type error Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube-object.store.test.ts typing Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix merge build issues Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix snapshots after merge Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix lint after merge Signed-off-by: Sebastian Malton <sebastian@malton.name> * reexport BaseKubeJsonApiObjectMetadata Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix typo in terminalSpawningPool Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove duplicate license header Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix typo to waitUntilDefined Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove iter use from getLegacyGlobalDiForExtensionApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove complex createStorage override Signed-off-by: Sebastian Malton <sebastian@malton.name> * override logger with mocks only when needed for tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove specialized overrideStore flags for getDiForUnitTesting Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove unnecessary | undefined types from the exactOptionalFieldTypes experiment Signed-off-by: Sebastian Malton <sebastian@malton.name> * use more descriptive name for local test mocks Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove unnecessary addition to 'make clean' target Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove oddity of KubeObjectStore.getById(undefined) being allowed Signed-off-by: Sebastian Malton <sebastian@malton.name> * rename KubeObject.getDescriptor in favour of name without fundemental JS meaning Signed-off-by: Sebastian Malton <sebastian@malton.name> * Simplify legacyRegisterApi when working in behaviour unit tests - Don't emit within main environment as there should be no auto registering there Signed-off-by: Sebastian Malton <sebastian@malton.name> * change confusing variable name in ReactiveDuration Signed-off-by: Sebastian Malton <sebastian@malton.name> * make visitor pattern more explicit for Entity contextMenuOpen Signed-off-by: Sebastian Malton <sebastian@malton.name> * toggleDetails -> toggleKubeDetailsPane is more specific Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove outdated comment Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix bug where LensExtension dependencies are not set Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests from the revert of react 18 Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix more tests from merge Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix typings with new is-compatible-extension tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * more type fixing Signed-off-by: Sebastian Malton <sebastian@malton.name> * Revert in-tree extension versions Signed-off-by: Sebastian Malton <sebastian@malton.name> * Improve name of guarding injectable for stores and apis - New name better implies that it is just a guard state and does not do anything Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add helper for <Select>.isMulti for storing in a Set<Value> Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix is-compatible-extension.test.ts types Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
381d77c633
commit
dfcb7c3330
1062 files changed
+26512
-28689
No files matched your search
@@ -2,35 +2,28 @@
|
||||
* 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 { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { RawHelmChart } from "../../../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { route } from "../../../router/route";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
|
||||
interface GetChartResponse {
|
||||
readme: string;
|
||||
versions: RawHelmChart[];
|
||||
}
|
||||
|
||||
const getChartRouteInjectable = getInjectable({
|
||||
const getChartRouteInjectable = getRouteInjectable({
|
||||
id: "get-chart-route",
|
||||
|
||||
instantiate: (): Route<GetChartResponse> => ({
|
||||
instantiate: () => route({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/charts/{repo}/{chart}`,
|
||||
})(async ({ params, query }) => {
|
||||
const { repo, chart } = params;
|
||||
|
||||
handler: async ({ params, query }) => ({
|
||||
return {
|
||||
response: await helmService.getChart(
|
||||
params.repo,
|
||||
params.chart,
|
||||
query.get("version"),
|
||||
repo,
|
||||
chart,
|
||||
query.get("version") ?? undefined,
|
||||
),
|
||||
}),
|
||||
};
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
});
|
||||
|
||||
export default getChartRouteInjectable;
|
||||
@@ -2,32 +2,24 @@
|
||||
* 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 { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import { route } from "../../../router/route";
|
||||
|
||||
const getChartRouteValuesInjectable = getInjectable({
|
||||
const getChartRouteValuesInjectable = getRouteInjectable({
|
||||
id: "get-chart-route-values",
|
||||
|
||||
instantiate: (): Route<string> => ({
|
||||
instantiate: () => route({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/charts/{repo}/{chart}/values`,
|
||||
|
||||
handler: async ({
|
||||
params,
|
||||
query,
|
||||
}) => ({
|
||||
response: await helmService.getChartValues(
|
||||
params.repo,
|
||||
params.chart,
|
||||
query.get("version"),
|
||||
),
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(async ({ params, query }) => ({
|
||||
response: await helmService.getChartValues(
|
||||
params.repo,
|
||||
params.chart,
|
||||
query.get("version") ?? undefined,
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
export default getChartRouteValuesInjectable;
|
||||
@@ -2,25 +2,20 @@
|
||||
* 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 { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import { route } from "../../../router/route";
|
||||
|
||||
const listChartsRouteInjectable = getInjectable({
|
||||
const listChartsRouteInjectable = getRouteInjectable({
|
||||
id: "list-charts-route",
|
||||
|
||||
instantiate: (): Route<any> => ({
|
||||
instantiate: () => route({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/charts`,
|
||||
|
||||
handler: async () => ({
|
||||
response: await helmService.listCharts(),
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(async () => ({
|
||||
response: await helmService.listCharts(),
|
||||
})),
|
||||
});
|
||||
|
||||
export default listChartsRouteInjectable;
|
||||
@@ -3,32 +3,23 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { clusterRoute } from "../../../router/route";
|
||||
|
||||
const deleteReleaseRouteInjectable = getInjectable({
|
||||
const deleteReleaseRouteInjectable = getRouteInjectable({
|
||||
id: "delete-release-route",
|
||||
|
||||
instantiate: (): Route<string> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "delete",
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}`,
|
||||
|
||||
handler: async (request) => {
|
||||
const { cluster, params } = request;
|
||||
|
||||
return {
|
||||
response: await helmService.deleteRelease(
|
||||
cluster,
|
||||
params.release,
|
||||
params.namespace,
|
||||
),
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(async ({ cluster, params: { release, namespace }}) => ({
|
||||
response: await helmService.deleteRelease(
|
||||
cluster,
|
||||
release,
|
||||
namespace,
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
export default deleteReleaseRouteInjectable;
|
||||
@@ -3,32 +3,23 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { clusterRoute } from "../../../router/route";
|
||||
|
||||
const getReleaseRouteHistoryInjectable = getInjectable({
|
||||
const getReleaseRouteHistoryInjectable = getRouteInjectable({
|
||||
id: "get-release-history-route",
|
||||
|
||||
instantiate: (): Route<any> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}/history`,
|
||||
|
||||
handler: async (request) => {
|
||||
const { cluster, params } = request;
|
||||
|
||||
return {
|
||||
response: await helmService.getReleaseHistory(
|
||||
cluster,
|
||||
params.release,
|
||||
params.namespace,
|
||||
),
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(async ({ cluster, params }) => ({
|
||||
response: await helmService.getReleaseHistory(
|
||||
cluster,
|
||||
params.release,
|
||||
params.namespace,
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
export default getReleaseRouteHistoryInjectable;
|
||||
@@ -3,32 +3,23 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { clusterRoute } from "../../../router/route";
|
||||
|
||||
const getReleaseRouteInjectable = getInjectable({
|
||||
const getReleaseRouteInjectable = getRouteInjectable({
|
||||
id: "get-release-route",
|
||||
|
||||
instantiate: (): Route<any> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}`,
|
||||
|
||||
handler: async (request) => {
|
||||
const { cluster, params } = request;
|
||||
|
||||
return {
|
||||
response: await helmService.getRelease(
|
||||
cluster,
|
||||
params.release,
|
||||
params.namespace,
|
||||
),
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(async ({ cluster, params }) => ({
|
||||
response: await helmService.getRelease(
|
||||
cluster,
|
||||
params.release,
|
||||
params.namespace,
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
export default getReleaseRouteInjectable;
|
||||
@@ -3,37 +3,27 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { getBoolean } from "../../../utils/parse-query";
|
||||
import { contentTypes } from "../../../router/router-content-types";
|
||||
import { clusterRoute } from "../../../router/route";
|
||||
|
||||
const getReleaseRouteValuesInjectable = getInjectable({
|
||||
const getReleaseRouteValuesInjectable = getRouteInjectable({
|
||||
id: "get-release-values-route",
|
||||
|
||||
instantiate: (): Route<string> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}/values`,
|
||||
})(async ({ cluster, params: { namespace, release }, query }) => ({
|
||||
response: await helmService.getReleaseValues(release, {
|
||||
cluster,
|
||||
namespace,
|
||||
all: getBoolean(query, "all"),
|
||||
}),
|
||||
|
||||
handler: async (request) => {
|
||||
const { cluster, params: { namespace, release }, query } = request;
|
||||
const all = getBoolean(query, "all");
|
||||
|
||||
return {
|
||||
response: await helmService.getReleaseValues(release, {
|
||||
cluster,
|
||||
namespace,
|
||||
all,
|
||||
}),
|
||||
|
||||
contentType: contentTypes.txt,
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
contentType: contentTypes.txt,
|
||||
})),
|
||||
});
|
||||
|
||||
export default getReleaseRouteValuesInjectable;
|
||||
@@ -3,34 +3,42 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import type { InstallChartArgs } from "../../../helm/helm-service";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import Joi from "joi";
|
||||
import { payloadValidatedClusterRoute } from "../../../router/route";
|
||||
|
||||
interface InstallChartResponse {
|
||||
log: string;
|
||||
release: { name: string; namespace: string };
|
||||
}
|
||||
const installChartArgsValidator = Joi.object<InstallChartArgs, true, InstallChartArgs>({
|
||||
chart: Joi
|
||||
.string()
|
||||
.required(),
|
||||
values: Joi
|
||||
.object()
|
||||
.required()
|
||||
.unknown(true),
|
||||
name: Joi
|
||||
.string()
|
||||
.required(),
|
||||
namespace: Joi
|
||||
.string()
|
||||
.required(),
|
||||
version: Joi
|
||||
.string()
|
||||
.required(),
|
||||
});
|
||||
|
||||
const installChartRouteInjectable = getInjectable({
|
||||
const installChartRouteInjectable = getRouteInjectable({
|
||||
id: "install-chart-route",
|
||||
|
||||
instantiate: () : Route<InstallChartResponse> => ({
|
||||
instantiate: () => payloadValidatedClusterRoute({
|
||||
method: "post",
|
||||
path: `${apiPrefix}/v2/releases`,
|
||||
|
||||
handler: async (request) => {
|
||||
const { payload, cluster } = request;
|
||||
|
||||
return {
|
||||
response: await helmService.installChart(cluster, payload),
|
||||
statusCode: 201,
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
payloadValidator: installChartArgsValidator,
|
||||
})(async ({ payload, cluster }) => ({
|
||||
response: await helmService.installChart(cluster, payload),
|
||||
statusCode: 201,
|
||||
})),
|
||||
});
|
||||
|
||||
export default installChartRouteInjectable;
|
||||
@@ -3,28 +3,19 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { clusterRoute } from "../../../router/route";
|
||||
|
||||
const listReleasesRouteInjectable = getInjectable({
|
||||
const listReleasesRouteInjectable = getRouteInjectable({
|
||||
id: "list-releases-route",
|
||||
|
||||
instantiate: (): Route<Record<string, any>> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/releases/{namespace?}`,
|
||||
|
||||
handler: async (request) => {
|
||||
const { cluster, params } = request;
|
||||
|
||||
return {
|
||||
response: await helmService.listReleases(cluster, params.namespace),
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(async ({ cluster, params }) => ({
|
||||
response: await helmService.listReleases(cluster, params.namespace),
|
||||
})),
|
||||
});
|
||||
|
||||
export default listReleasesRouteInjectable;
|
||||
@@ -3,26 +3,31 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import Joi from "joi";
|
||||
import { payloadValidatedClusterRoute } from "../../../router/route";
|
||||
|
||||
const rollbackReleaseRouteInjectable = getInjectable({
|
||||
interface RollbackReleasePayload {
|
||||
revision: number;
|
||||
}
|
||||
|
||||
const rollbackReleasePayloadValidator = Joi.object<RollbackReleasePayload, true, RollbackReleasePayload>({
|
||||
revision: Joi
|
||||
.number()
|
||||
.required(),
|
||||
});
|
||||
|
||||
const rollbackReleaseRouteInjectable = getRouteInjectable({
|
||||
id: "rollback-release-route",
|
||||
|
||||
instantiate: (): Route<void> => ({
|
||||
instantiate: () => payloadValidatedClusterRoute({
|
||||
method: "put",
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}/rollback`,
|
||||
|
||||
handler: async (request) => {
|
||||
const { cluster, params, payload } = request;
|
||||
|
||||
await helmService.rollback(cluster, params.release, params.namespace, payload.revision);
|
||||
},
|
||||
payloadValidator: rollbackReleasePayloadValidator,
|
||||
})(async ({ cluster, params: { release, namespace }, payload }) => {
|
||||
await helmService.rollback(cluster, release, namespace, payload.revision);
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
});
|
||||
|
||||
export default rollbackReleaseRouteInjectable;
|
||||
@@ -3,38 +3,39 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import type { Route } from "../../../router/router";
|
||||
import type { UpdateChartArgs } from "../../../helm/helm-service";
|
||||
import { helmService } from "../../../helm/helm-service";
|
||||
import { routeInjectionToken } from "../../../router/router.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { payloadValidatedClusterRoute } from "../../../router/route";
|
||||
import Joi from "joi";
|
||||
|
||||
interface UpdateReleaseResponse {
|
||||
log: string;
|
||||
release: { name: string; namespace: string };
|
||||
}
|
||||
const updateChartArgsValidator = Joi.object<UpdateChartArgs, true, UpdateChartArgs>({
|
||||
chart: Joi
|
||||
.string()
|
||||
.required(),
|
||||
version: Joi
|
||||
.string()
|
||||
.required(),
|
||||
values: Joi
|
||||
.object()
|
||||
.unknown(true),
|
||||
});
|
||||
|
||||
const updateReleaseRouteInjectable = getInjectable({
|
||||
const updateReleaseRouteInjectable = getRouteInjectable({
|
||||
id: "update-release-route",
|
||||
|
||||
instantiate: (): Route<UpdateReleaseResponse> => ({
|
||||
instantiate: () => payloadValidatedClusterRoute({
|
||||
method: "put",
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}`,
|
||||
|
||||
handler: async ({
|
||||
payloadValidator: updateChartArgsValidator,
|
||||
})(async ({ cluster, params, payload }) => ({
|
||||
response: await helmService.updateRelease(
|
||||
cluster,
|
||||
params,
|
||||
params.release,
|
||||
params.namespace,
|
||||
payload,
|
||||
}) => ({
|
||||
response: await helmService.updateRelease(
|
||||
cluster,
|
||||
params.release,
|
||||
params.namespace,
|
||||
payload,
|
||||
),
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
export default updateReleaseRouteInjectable;
|
||||
@@ -3,43 +3,88 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import type { Route } from "../../router/router";
|
||||
import { routeInjectionToken } from "../../router/router.injectable";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import type { V1Secret } from "@kubernetes/client-node";
|
||||
import { CoreV1Api } from "@kubernetes/client-node";
|
||||
import { clusterRoute } from "../../router/route";
|
||||
|
||||
const getServiceAccountRouteInjectable = getInjectable({
|
||||
const getServiceAccountRouteInjectable = getRouteInjectable({
|
||||
id: "get-service-account-route",
|
||||
|
||||
instantiate: (): Route<ReturnType<typeof generateKubeConfig>> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}`,
|
||||
})(async ({ params, cluster }) => {
|
||||
const client = (await cluster.getProxyKubeconfig()).makeApiClient(CoreV1Api);
|
||||
const secretList = await client.listNamespacedSecret(params.namespace);
|
||||
|
||||
handler: async (request) => {
|
||||
const { params, cluster } = request;
|
||||
const client = (await cluster.getProxyKubeconfig()).makeApiClient(CoreV1Api);
|
||||
const secretList = await client.listNamespacedSecret(params.namespace);
|
||||
const secret = secretList.body.items.find(secret => {
|
||||
const { annotations } = secret.metadata ?? {};
|
||||
|
||||
const secret = secretList.body.items.find(secret => {
|
||||
const { annotations } = secret.metadata;
|
||||
return annotations?.["kubernetes.io/service-account.name"] === params.account;
|
||||
});
|
||||
|
||||
return annotations && annotations["kubernetes.io/service-account.name"] == params.account;
|
||||
});
|
||||
if (!secret) {
|
||||
return {
|
||||
error: "No secret found",
|
||||
statusCode: 404,
|
||||
};
|
||||
}
|
||||
|
||||
return { response: generateKubeConfig(params.account, secret, cluster) };
|
||||
},
|
||||
const kubeconfig = generateKubeConfig(params.account, secret, cluster);
|
||||
|
||||
if (!kubeconfig) {
|
||||
return {
|
||||
error: "No secret found",
|
||||
statusCode: 404,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
response: kubeconfig,
|
||||
};
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
});
|
||||
|
||||
export default getServiceAccountRouteInjectable;
|
||||
|
||||
function generateKubeConfig(username: string, secret: V1Secret, cluster: Cluster) {
|
||||
const tokenData = Buffer.from(secret.data["token"], "base64");
|
||||
interface ServiceAccountKubeConfig {
|
||||
apiVersion: string;
|
||||
kind: string;
|
||||
clusters: {
|
||||
name: string;
|
||||
cluster: {
|
||||
server: string;
|
||||
"certificate-authority-data": string;
|
||||
};
|
||||
}[];
|
||||
users: {
|
||||
name: string;
|
||||
user: {
|
||||
token: string;
|
||||
};
|
||||
}[];
|
||||
contexts: {
|
||||
name: string;
|
||||
context: {
|
||||
user: string;
|
||||
cluster: string;
|
||||
namespace: string | undefined;
|
||||
};
|
||||
}[];
|
||||
"current-context": string;
|
||||
}
|
||||
|
||||
function generateKubeConfig(username: string, secret: V1Secret, cluster: Cluster): ServiceAccountKubeConfig | undefined {
|
||||
if (!secret.data || !secret.metadata) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { token, "ca.crt": caCrt } = secret.data;
|
||||
|
||||
const tokenData = Buffer.from(token, "base64");
|
||||
|
||||
return {
|
||||
"apiVersion": "v1",
|
||||
@@ -49,7 +94,7 @@ function generateKubeConfig(username: string, secret: V1Secret, cluster: Cluster
|
||||
"name": cluster.contextName,
|
||||
"cluster": {
|
||||
"server": cluster.apiUrl,
|
||||
"certificate-authority-data": secret.data["ca.crt"],
|
||||
"certificate-authority-data": caCrt,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import type { LensApiRequest, Route } from "../../router/router";
|
||||
import { routeInjectionToken } from "../../router/router.injectable";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import type { ClusterPrometheusMetadata } from "../../../common/cluster-types";
|
||||
import { ClusterMetadataKey } from "../../../common/cluster-types";
|
||||
import logger from "../../logger";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import { getMetrics } from "../../k8s-request";
|
||||
import type { IMetricsQuery } from "./metrics-query";
|
||||
import { clusterRoute } from "../../router/route";
|
||||
import { isObject } from "lodash";
|
||||
import { isRequestError } from "../../../common/utils";
|
||||
|
||||
// This is used for backoff retry tracking.
|
||||
const ATTEMPTS = [false, false, false, false, true];
|
||||
@@ -27,8 +28,13 @@ async function loadMetrics(promQueries: string[], cluster: Cluster, prometheusPa
|
||||
try {
|
||||
return await getMetrics(cluster, prometheusPath, { query, ...queryParams });
|
||||
} catch (error) {
|
||||
if (lastAttempt || (error?.statusCode >= 400 && error?.statusCode < 500)) {
|
||||
logger.error("[Metrics]: metrics not available", error?.response ? error.response?.body : error);
|
||||
if (isRequestError(error)) {
|
||||
if (lastAttempt || (error.statusCode && error.statusCode >= 400 && error.statusCode < 500)) {
|
||||
logger.error("[Metrics]: metrics not available", error?.response ? error.response?.body : error);
|
||||
throw new Error("Metrics not available");
|
||||
}
|
||||
} else {
|
||||
logger.error("[Metrics]: metrics not available", error);
|
||||
throw new Error("Metrics not available");
|
||||
}
|
||||
|
||||
@@ -43,67 +49,66 @@ async function loadMetrics(promQueries: string[], cluster: Cluster, prometheusPa
|
||||
return Promise.all(queries.map(loadMetric));
|
||||
}
|
||||
|
||||
const addMetricsRoute = async ({ cluster, payload, query }: LensApiRequest) => {
|
||||
const queryParams: IMetricsQuery = Object.fromEntries(query.entries());
|
||||
const prometheusMetadata: ClusterPrometheusMetadata = {};
|
||||
|
||||
try {
|
||||
const { prometheusPath, provider } = await cluster.contextHandler.getPrometheusDetails();
|
||||
|
||||
prometheusMetadata.provider = provider?.id;
|
||||
prometheusMetadata.autoDetected = !cluster.preferences.prometheusProvider?.type;
|
||||
|
||||
if (!prometheusPath) {
|
||||
prometheusMetadata.success = false;
|
||||
|
||||
return { response: {}};
|
||||
}
|
||||
|
||||
// return data in same structure as query
|
||||
if (typeof payload === "string") {
|
||||
const [data] = await loadMetrics([payload], cluster, prometheusPath, queryParams);
|
||||
|
||||
return { response: data };
|
||||
}
|
||||
|
||||
if (Array.isArray(payload)) {
|
||||
const data = await loadMetrics(payload, cluster, prometheusPath, queryParams);
|
||||
|
||||
return { response: data };
|
||||
}
|
||||
|
||||
const queries = Object.entries<Record<string, string>>(payload)
|
||||
.map(([queryName, queryOpts]) => (
|
||||
provider.getQuery(queryOpts, queryName)
|
||||
));
|
||||
|
||||
const result = await loadMetrics(queries, cluster, prometheusPath, queryParams);
|
||||
const data = Object.fromEntries(Object.keys(payload).map((metricName, i) => [metricName, result[i]]));
|
||||
|
||||
prometheusMetadata.success = true;
|
||||
|
||||
return { response: data };
|
||||
} catch (error) {
|
||||
prometheusMetadata.success = false;
|
||||
|
||||
logger.warn(`[METRICS-ROUTE]: failed to get metrics for clusterId=${cluster.id}:`, error);
|
||||
|
||||
return { response: {}};
|
||||
} finally {
|
||||
cluster.metadata[ClusterMetadataKey.PROMETHEUS] = prometheusMetadata;
|
||||
}
|
||||
};
|
||||
|
||||
const addMetricsRouteInjectable = getInjectable({
|
||||
const addMetricsRouteInjectable = getRouteInjectable({
|
||||
id: "add-metrics-route",
|
||||
|
||||
instantiate: (): Route<any> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "post",
|
||||
path: `${apiPrefix}/metrics`,
|
||||
handler: addMetricsRoute,
|
||||
}),
|
||||
})(async ({ cluster, payload, query }) => {
|
||||
const queryParams: IMetricsQuery = Object.fromEntries(query.entries());
|
||||
const prometheusMetadata: ClusterPrometheusMetadata = {};
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
try {
|
||||
const { prometheusPath, provider } = await cluster.contextHandler.getPrometheusDetails();
|
||||
|
||||
prometheusMetadata.provider = provider?.id;
|
||||
prometheusMetadata.autoDetected = !cluster.preferences.prometheusProvider?.type;
|
||||
|
||||
if (!prometheusPath) {
|
||||
prometheusMetadata.success = false;
|
||||
|
||||
return { response: {}};
|
||||
}
|
||||
|
||||
// return data in same structure as query
|
||||
if (typeof payload === "string") {
|
||||
const [data] = await loadMetrics([payload], cluster, prometheusPath, queryParams);
|
||||
|
||||
return { response: data };
|
||||
}
|
||||
|
||||
if (Array.isArray(payload)) {
|
||||
const data = await loadMetrics(payload, cluster, prometheusPath, queryParams);
|
||||
|
||||
return { response: data };
|
||||
}
|
||||
|
||||
if (isObject(payload)) {
|
||||
const queries = Object.entries(payload as Record<string, Record<string, string>>)
|
||||
.map(([queryName, queryOpts]) => (
|
||||
provider.getQuery(queryOpts, queryName)
|
||||
));
|
||||
|
||||
const result = await loadMetrics(queries, cluster, prometheusPath, queryParams);
|
||||
const data = Object.fromEntries(Object.keys(payload).map((metricName, i) => [metricName, result[i]]));
|
||||
|
||||
prometheusMetadata.success = true;
|
||||
|
||||
return { response: data };
|
||||
}
|
||||
|
||||
return { response: {}};
|
||||
} catch (error) {
|
||||
prometheusMetadata.success = false;
|
||||
|
||||
logger.warn(`[METRICS-ROUTE]: failed to get metrics for clusterId=${cluster.id}:`, error);
|
||||
|
||||
return { response: {}};
|
||||
} finally {
|
||||
cluster.metadata[ClusterMetadataKey.PROMETHEUS] = prometheusMetadata;
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export default addMetricsRouteInjectable;
|
||||
@@ -3,32 +3,26 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import type { Route } from "../../router/router";
|
||||
import { routeInjectionToken } from "../../router/router.injectable";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import { PrometheusProviderRegistry } from "../../prometheus";
|
||||
import type { MetricProviderInfo } from "../../../common/k8s-api/endpoints/metrics.api";
|
||||
import { route } from "../../router/route";
|
||||
|
||||
const getMetricProvidersRouteInjectable = getInjectable({
|
||||
const getMetricProvidersRouteInjectable = getRouteInjectable({
|
||||
id: "get-metric-providers-route",
|
||||
|
||||
instantiate: (): Route<MetricProviderInfo[]> => ({
|
||||
instantiate: () => route({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/metrics/providers`,
|
||||
|
||||
handler: () => {
|
||||
const providers: MetricProviderInfo[] = [];
|
||||
|
||||
for (const { name, id, isConfigurable } of PrometheusProviderRegistry.getInstance().providers.values()) {
|
||||
providers.push({ name, id, isConfigurable });
|
||||
}
|
||||
|
||||
return { response: providers };
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(() => ({
|
||||
response: Array.from(
|
||||
PrometheusProviderRegistry
|
||||
.getInstance()
|
||||
.providers
|
||||
.values(),
|
||||
({ name, id, isConfigurable }) => ({ name, id, isConfigurable }),
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
export default getMetricProvidersRouteInjectable;
|
||||
@@ -7,8 +7,9 @@ import { getPortFrom } from "../../../utils/get-port";
|
||||
import type { ChildProcessWithoutNullStreams } from "child_process";
|
||||
import { spawn } from "child_process";
|
||||
import * as tcpPortUsed from "tcp-port-used";
|
||||
import { TypedRegEx } from "typed-regex";
|
||||
|
||||
const internalPortRegex = /^forwarding from (?<address>.+) ->/i;
|
||||
const internalPortRegex = TypedRegEx("^forwarding from (?<address>.+) ->", "i");
|
||||
|
||||
export interface PortForwardArgs {
|
||||
clusterId: string;
|
||||
@@ -36,7 +37,7 @@ export class PortForward {
|
||||
));
|
||||
}
|
||||
|
||||
public process: ChildProcessWithoutNullStreams;
|
||||
public process?: ChildProcessWithoutNullStreams;
|
||||
public clusterId: string;
|
||||
public kind: string;
|
||||
public namespace: string;
|
||||
@@ -98,6 +99,6 @@ export class PortForward {
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
this.process.kill();
|
||||
this.process?.kill();
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,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 { routeInjectionToken } from "../../router/router.injectable";
|
||||
import type { LensApiRequest, Route } from "../../router/router";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import { PortForward } from "./functionality/port-forward";
|
||||
import { clusterRoute } from "../../router/route";
|
||||
|
||||
const getCurrentPortForward = async (request: LensApiRequest) => {
|
||||
const { params, query, cluster } = request;
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
|
||||
const portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||
namespace, port, forwardPort,
|
||||
});
|
||||
|
||||
return { response: { port: portForward?.forwardPort ?? null }};
|
||||
};
|
||||
|
||||
const getCurrentPortForwardRouteInjectable = getInjectable({
|
||||
const getCurrentPortForwardRouteInjectable = getRouteInjectable({
|
||||
id: "get-current-port-forward-route",
|
||||
|
||||
instantiate: (): Route<{ port: number }> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/pods/port-forward/{namespace}/{resourceType}/{resourceName}`,
|
||||
handler: getCurrentPortForward,
|
||||
}),
|
||||
})(async ({ params, query, cluster }) => {
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
const portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||
namespace, port, forwardPort,
|
||||
});
|
||||
|
||||
return {
|
||||
response: {
|
||||
port: portForward?.forwardPort ?? null,
|
||||
},
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
export default getCurrentPortForwardRouteInjectable;
|
||||
@@ -2,97 +2,90 @@
|
||||
* 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 { routeInjectionToken } from "../../router/router.injectable";
|
||||
import type { LensApiRequest, Route } from "../../router/router";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import type { PortForwardArgs } from "./functionality/port-forward";
|
||||
import { PortForward } from "./functionality/port-forward";
|
||||
import logger from "../../logger";
|
||||
import createPortForwardInjectable from "./functionality/create-port-forward.injectable";
|
||||
import { clusterRoute } from "../../router/route";
|
||||
|
||||
interface Dependencies {
|
||||
createPortForward: (pathToKubeConfig: string, args: PortForwardArgs) => PortForward;
|
||||
}
|
||||
const startPortForwardRouteInjectable = getRouteInjectable({
|
||||
id: "start-current-port-forward-route",
|
||||
|
||||
const startPortForward = ({ createPortForward }: Dependencies) => async (request: LensApiRequest) => {
|
||||
const { params, query, cluster } = request;
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
instantiate: (di) => {
|
||||
const createPortForward = di.inject(createPortForwardInjectable);
|
||||
|
||||
try {
|
||||
let portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id,
|
||||
kind: resourceType,
|
||||
name: resourceName,
|
||||
namespace,
|
||||
port,
|
||||
forwardPort,
|
||||
});
|
||||
return clusterRoute({
|
||||
method: "post",
|
||||
path: `${apiPrefix}/pods/port-forward/{namespace}/{resourceType}/{resourceName}`,
|
||||
})(async ({ params, query, cluster }) => {
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
|
||||
if (!portForward) {
|
||||
logger.info(
|
||||
`Creating a new port-forward ${namespace}/${resourceType}/${resourceName}:${port}`,
|
||||
);
|
||||
|
||||
const thePort =
|
||||
0 < forwardPort && forwardPort < 65536 ? forwardPort : 0;
|
||||
|
||||
portForward = createPortForward(await cluster.getProxyKubeconfigPath(), {
|
||||
clusterId: cluster.id,
|
||||
kind: resourceType,
|
||||
namespace,
|
||||
name: resourceName,
|
||||
port,
|
||||
forwardPort: thePort,
|
||||
});
|
||||
|
||||
const started = await portForward.start();
|
||||
|
||||
if (!started) {
|
||||
logger.error("[PORT-FORWARD-ROUTE]: failed to start a port-forward", {
|
||||
try {
|
||||
let portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id,
|
||||
kind: resourceType,
|
||||
name: resourceName,
|
||||
namespace,
|
||||
port,
|
||||
resourceType,
|
||||
resourceName,
|
||||
forwardPort,
|
||||
});
|
||||
|
||||
if (!portForward) {
|
||||
logger.info(
|
||||
`Creating a new port-forward ${namespace}/${resourceType}/${resourceName}:${port}`,
|
||||
);
|
||||
|
||||
const thePort = 0 < forwardPort && forwardPort < 65536
|
||||
? forwardPort
|
||||
: 0;
|
||||
|
||||
portForward = createPortForward(await cluster.getProxyKubeconfigPath(), {
|
||||
clusterId: cluster.id,
|
||||
kind: resourceType,
|
||||
namespace,
|
||||
name: resourceName,
|
||||
port,
|
||||
forwardPort: thePort,
|
||||
});
|
||||
|
||||
const started = await portForward.start();
|
||||
|
||||
if (!started) {
|
||||
logger.error("[PORT-FORWARD-ROUTE]: failed to start a port-forward", {
|
||||
namespace,
|
||||
port,
|
||||
resourceType,
|
||||
resourceName,
|
||||
});
|
||||
|
||||
return {
|
||||
error: {
|
||||
message: `Failed to forward port ${port} to ${
|
||||
thePort ? forwardPort : "random port"
|
||||
}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return { response: { port: portForward.forwardPort }};
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`[PORT-FORWARD-ROUTE]: failed to open a port-forward: ${error}`,
|
||||
{ namespace, port, resourceType, resourceName },
|
||||
);
|
||||
|
||||
return {
|
||||
error: {
|
||||
message: `Failed to forward port ${port} to ${
|
||||
thePort ? forwardPort : "random port"
|
||||
}`,
|
||||
message: `Failed to forward port ${port}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return { response: { port: portForward.forwardPort }};
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`[PORT-FORWARD-ROUTE]: failed to open a port-forward: ${error}`,
|
||||
{ namespace, port, resourceType, resourceName },
|
||||
);
|
||||
|
||||
return {
|
||||
error: {
|
||||
message: `Failed to forward port ${port}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const startPortForwardRouteInjectable = getInjectable({
|
||||
id: "start-current-port-forward-route",
|
||||
|
||||
instantiate: (di): Route<{ port: number }> => ({
|
||||
method: "post",
|
||||
path: `${apiPrefix}/pods/port-forward/{namespace}/{resourceType}/{resourceName}`,
|
||||
handler: startPortForward({ createPortForward: di.inject(createPortForwardInjectable) }),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default startPortForwardRouteInjectable;
|
||||
@@ -2,50 +2,42 @@
|
||||
* 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 { routeInjectionToken } from "../../router/router.injectable";
|
||||
import type { LensApiRequest, Route } from "../../router/router";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import { PortForward } from "./functionality/port-forward";
|
||||
import logger from "../../logger";
|
||||
import { clusterRoute } from "../../router/route";
|
||||
|
||||
const stopCurrentPortForward = async (request: LensApiRequest) => {
|
||||
const { params, query, cluster } = request;
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
|
||||
const portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||
namespace, port, forwardPort,
|
||||
});
|
||||
|
||||
try {
|
||||
await portForward.stop();
|
||||
|
||||
return { response: { status: true }};
|
||||
} catch (error) {
|
||||
logger.error("[PORT-FORWARD-ROUTE]: error stopping a port-forward", { namespace, port, forwardPort, resourceType, resourceName });
|
||||
|
||||
return {
|
||||
error: {
|
||||
message: `error stopping a forward port ${port}`,
|
||||
},
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const stopCurrentPortForwardRouteInjectable = getInjectable({
|
||||
const stopCurrentPortForwardRouteInjectable = getRouteInjectable({
|
||||
id: "stop-current-port-forward-route",
|
||||
|
||||
instantiate: (): Route<{ status: boolean }> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "delete",
|
||||
path: `${apiPrefix}/pods/port-forward/{namespace}/{resourceType}/{resourceName}`,
|
||||
handler: stopCurrentPortForward,
|
||||
}),
|
||||
})(async ({ params, query, cluster }) => {
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
const portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||
namespace, port, forwardPort,
|
||||
});
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
try {
|
||||
await portForward?.stop();
|
||||
|
||||
return { response: { status: true }};
|
||||
} catch (error) {
|
||||
logger.error("[PORT-FORWARD-ROUTE]: error stopping a port-forward", { namespace, port, forwardPort, resourceType, resourceName });
|
||||
|
||||
return {
|
||||
error: {
|
||||
message: `error stopping a forward port ${port}`,
|
||||
},
|
||||
};
|
||||
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
export default stopCurrentPortForwardRouteInjectable;
|
||||
@@ -2,25 +2,20 @@
|
||||
* 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 { routeInjectionToken } from "../../router/router.injectable";
|
||||
import type { Route } from "../../router/router";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import { ResourceApplier } from "../../resource-applier";
|
||||
import { clusterRoute } from "../../router/route";
|
||||
|
||||
const applyResourceRouteInjectable = getInjectable({
|
||||
const applyResourceRouteInjectable = getRouteInjectable({
|
||||
id: "apply-resource-route",
|
||||
|
||||
instantiate: (): Route<string> => ({
|
||||
instantiate: () => clusterRoute({
|
||||
method: "post",
|
||||
path: `${apiPrefix}/stack`,
|
||||
|
||||
handler: async ({ cluster, payload }) => ({
|
||||
response: await new ResourceApplier(cluster).apply(payload),
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(async ({ cluster, payload }) => ({
|
||||
response: await new ResourceApplier(cluster).apply(payload),
|
||||
})),
|
||||
});
|
||||
|
||||
export default applyResourceRouteInjectable;
|
||||
@@ -2,30 +2,56 @@
|
||||
* 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 { routeInjectionToken } from "../../router/router.injectable";
|
||||
import type { Route } from "../../router/router";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import { apiPrefix } from "../../../common/vars";
|
||||
import { ResourceApplier } from "../../resource-applier";
|
||||
import { payloadValidatedClusterRoute } from "../../router/route";
|
||||
import Joi from "joi";
|
||||
import type { Patch } from "rfc6902";
|
||||
|
||||
const patchResourceRouteInjectable = getInjectable({
|
||||
interface PatchResourcePayload {
|
||||
name: string;
|
||||
kind: string;
|
||||
patch: Patch;
|
||||
ns?: string;
|
||||
}
|
||||
|
||||
const patchResourcePayloadValidator = Joi.object<PatchResourcePayload, true, PatchResourcePayload>({
|
||||
name: Joi
|
||||
.string()
|
||||
.required(),
|
||||
kind: Joi
|
||||
.string()
|
||||
.required(),
|
||||
ns: Joi
|
||||
.string()
|
||||
.optional(),
|
||||
patch: Joi
|
||||
.array()
|
||||
.allow(
|
||||
Joi.object({
|
||||
op: Joi
|
||||
.string()
|
||||
.required(),
|
||||
}).unknown(true),
|
||||
),
|
||||
});
|
||||
|
||||
const patchResourceRouteInjectable = getRouteInjectable({
|
||||
id: "patch-resource-route",
|
||||
|
||||
instantiate: (): Route<string> => ({
|
||||
instantiate: () => payloadValidatedClusterRoute({
|
||||
method: "patch",
|
||||
path: `${apiPrefix}/stack`,
|
||||
|
||||
handler: async ({ cluster, payload }) => ({
|
||||
response: await new ResourceApplier(cluster).patch(
|
||||
payload.name,
|
||||
payload.kind,
|
||||
payload.patch,
|
||||
payload.ns,
|
||||
),
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
payloadValidator: patchResourcePayloadValidator,
|
||||
})(async ({ cluster, payload }) => ({
|
||||
response: await new ResourceApplier(cluster).patch(
|
||||
payload.name,
|
||||
payload.kind,
|
||||
payload.patch,
|
||||
payload.ns,
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
export default patchResourceRouteInjectable;
|
||||
@@ -2,12 +2,10 @@
|
||||
* 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 type { LensApiRequest, Route } from "../router/router";
|
||||
import type { SupportedFileExtension } from "../router/router-content-types";
|
||||
import { contentTypes } from "../router/router-content-types";
|
||||
import logger from "../logger";
|
||||
import { routeInjectionToken } from "../router/router.injectable";
|
||||
import { getRouteInjectable } from "../router/router.injectable";
|
||||
import { appName, publicPath, staticFilesDirectory } from "../../common/vars";
|
||||
import path from "path";
|
||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||
@@ -18,6 +16,8 @@ import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injec
|
||||
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
||||
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
||||
import { webpackDevServerPort } from "../../../webpack/vars";
|
||||
import type { LensApiRequest, RouteResponse } from "../router/route";
|
||||
import { route } from "../router/route";
|
||||
|
||||
interface ProductionDependencies {
|
||||
readFileBuffer: (path: string) => Promise<Buffer>;
|
||||
@@ -27,7 +27,7 @@ interface ProductionDependencies {
|
||||
|
||||
const handleStaticFileInProduction =
|
||||
({ readFileBuffer, getAbsolutePath, joinPaths }: ProductionDependencies) =>
|
||||
async ({ params }: LensApiRequest) => {
|
||||
async ({ params }: LensApiRequest<"/{path*}">): Promise<RouteResponse<Buffer>> => {
|
||||
const staticPath = getAbsolutePath(staticFilesDirectory);
|
||||
let filePath = params.path;
|
||||
|
||||
@@ -49,7 +49,7 @@ const handleStaticFileInProduction =
|
||||
return { response: await readFileBuffer(asset), contentType };
|
||||
} catch (err) {
|
||||
if (retryCount > 5) {
|
||||
logger.error("handleStaticFile:", err.toString());
|
||||
logger.error("handleStaticFile:", String(err));
|
||||
|
||||
return { statusCode: 404 };
|
||||
}
|
||||
@@ -67,10 +67,8 @@ interface DevelopmentDependencies {
|
||||
|
||||
const handleStaticFileInDevelopment =
|
||||
({ proxy }: DevelopmentDependencies) =>
|
||||
(apiReq: LensApiRequest) => {
|
||||
const { req, res } = apiReq.raw;
|
||||
|
||||
if (req.url === "/" || !req.url.startsWith("/build/")) {
|
||||
({ raw: { req, res }}: LensApiRequest<"/{path*}">): RouteResponse<Buffer> => {
|
||||
if (req.url === "/" || !req.url?.startsWith("/build/")) {
|
||||
req.url = `${publicPath}/${appName}.html`;
|
||||
}
|
||||
|
||||
@@ -81,25 +79,27 @@ const handleStaticFileInDevelopment =
|
||||
return { proxy };
|
||||
};
|
||||
|
||||
const staticFileRouteInjectable = getInjectable({
|
||||
const staticFileRouteInjectable = getRouteInjectable({
|
||||
id: "static-file-route",
|
||||
|
||||
instantiate: (di): Route<Buffer> => {
|
||||
instantiate: (di) => {
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const readFileBuffer = di.inject(readFileBufferInjectable);
|
||||
const getAbsolutePath = di.inject(getAbsolutePathInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
|
||||
return {
|
||||
return route({
|
||||
method: "get",
|
||||
path: `/{path*}`,
|
||||
handler: isDevelopment
|
||||
? handleStaticFileInDevelopment({ proxy: httpProxy.createProxy() })
|
||||
: handleStaticFileInProduction({ readFileBuffer, getAbsolutePath, joinPaths }),
|
||||
};
|
||||
})(
|
||||
isDevelopment
|
||||
? handleStaticFileInDevelopment({
|
||||
proxy: httpProxy.createProxy(),
|
||||
})
|
||||
: handleStaticFileInProduction({
|
||||
readFileBuffer: di.inject(readFileBufferInjectable),
|
||||
getAbsolutePath: di.inject(getAbsolutePathInjectable),
|
||||
joinPaths: di.inject(joinPathsInjectable),
|
||||
}),
|
||||
);
|
||||
},
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
});
|
||||
|
||||
export default staticFileRouteInjectable;
|
||||
@@ -2,22 +2,21 @@
|
||||
* 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 type { Route } from "../../router/router";
|
||||
import { routeInjectionToken } from "../../router/router.injectable";
|
||||
import { getRouteInjectable } from "../../router/router.injectable";
|
||||
import { getAppVersion } from "../../../common/utils";
|
||||
import { route } from "../../router/route";
|
||||
|
||||
const getVersionRouteInjectable = getInjectable({
|
||||
const getVersionRouteInjectable = getRouteInjectable({
|
||||
id: "get-version-route",
|
||||
|
||||
instantiate: (): Route<{ version: string }> => ({
|
||||
instantiate: () => route({
|
||||
method: "get",
|
||||
path: `/version`,
|
||||
|
||||
handler: () => ({ response: { version: getAppVersion() }}),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
})(() => ({
|
||||
response: {
|
||||
version: getAppVersion(),
|
||||
},
|
||||
})),
|
||||
});
|
||||
|
||||
export default getVersionRouteInjectable;
|
||||
Reference in new issue
Block a user