1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Switch to using injectable to setup route for get chart values

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-02-11 10:40:24 +02:00
parent 6729f46542
commit cca9c4b498
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
2 changed files with 35 additions and 2 deletions

View File

@ -183,8 +183,6 @@ export class Router {
this.router.add({ method: "delete", path: `${apiPrefix}/pods/port-forward/{namespace}/{resourceType}/{resourceName}` }, PortForwardRoute.routeCurrentPortForwardStop);
// Helm API
this.router.add({ method: "get", path: `${apiPrefix}/v2/charts/{repo}/{chart}/values` }, HelmApiRoute.getChartValues);
this.router.add({ method: "post", path: `${apiPrefix}/v2/releases` }, HelmApiRoute.installChart);
this.router.add({ method: `put`, path: `${apiPrefix}/v2/releases/{namespace}/{release}` }, HelmApiRoute.updateRelease);
this.router.add({ method: `put`, path: `${apiPrefix}/v2/releases/{namespace}/{release}/rollback` }, HelmApiRoute.rollbackRelease);

View File

@ -0,0 +1,35 @@
/**
* 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 } from "../../../router";
import { helmService } from "../../../helm/helm-service";
import { respondJson, respondText } from "../../../utils/http-responses";
import { apiPrefix } from "../../../../common/vars";
const getChartRouteValuesInjectable = getInjectable({
id: "get-chart-route-values",
instantiate: () => ({
method: "get",
path: `${apiPrefix}/v2/charts/{repo}/{chart}/values`,
handler: async (request: LensApiRequest) => {
const { params, query, response } = request;
try {
const values = await helmService.getChartValues(params.repo, params.chart, query.get("version"));
respondJson(response, values);
} catch (error) {
respondText(response, error?.toString() || "Error getting chart values", 422);
}
},
}),
injectionToken: routeInjectionToken,
});
export default getChartRouteValuesInjectable;