mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Refactor out Cluster.apiUrl to direct reading - Should help prevent using stale data - Removes some uses of synchronous FS operations Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Rename helper function to better communicate intent Signed-off-by: Sebastian Malton <sebastian@malton.name> * Improve prometheus handler tests to override less things Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
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 type { Cluster } from "../cluster/cluster";
|
|
import readFileInjectable from "../fs/read-file.injectable";
|
|
import type { ValidateKubeConfigResult } from "../kube-helpers";
|
|
import { loadValidatedConfig } from "../kube-helpers";
|
|
import resolveTildeInjectable from "../path/resolve-tilde.injectable";
|
|
|
|
export type LoadValidatedClusterConfig = (cluster: Cluster) => Promise<ValidateKubeConfigResult>;
|
|
|
|
const loadValidatedClusterConfigInjectable = getInjectable({
|
|
id: "load-validated-cluster-config",
|
|
instantiate: (di): LoadValidatedClusterConfig => {
|
|
const readFile = di.inject(readFileInjectable);
|
|
const resolveTilde = di.inject(resolveTildeInjectable);
|
|
|
|
return async (cluster) => {
|
|
const data = await readFile(resolveTilde(cluster.kubeConfigPath.get()));
|
|
|
|
return loadValidatedConfig(data, cluster.contextName.get());
|
|
};
|
|
},
|
|
});
|
|
|
|
export default loadValidatedClusterConfigInjectable;
|