1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/k8s-api/kube-api/get-kube-api-from-path.injectable.ts
Janne Savolainen dcb344afcb
Introduce a way to get KubeApi with selfLink using DI
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-07-27 09:22:41 +03:00

27 lines
805 B
TypeScript

/**
* 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 { parseKubeApi } from "../kube-api-parse";
import { kubeApiInjectionToken } from "./kube-api-injection-token";
import type { KubeApi } from "../kube-api";
const getKubeApiFromPathInjectable = getInjectable({
id: "get-kube-api-from-path",
instantiate: (di) => {
const kubeApis = di.injectMany(kubeApiInjectionToken);
return (apiPath: string) => {
const parsed = parseKubeApi(apiPath);
const kubeApi = kubeApis.find((api) => api.apiBase === parsed.apiBase);
return (kubeApi as KubeApi) || undefined;
};
},
});
export default getKubeApiFromPathInjectable;