mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove last uses of loadConfigFromFile
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
f0f06f53d2
commit
7e4de0a74e
@ -10,7 +10,7 @@ import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { HttpError } from "@kubernetes/client-node";
|
||||
import type { Kubectl } from "../../main/kubectl/kubectl";
|
||||
import type { KubeconfigManager } from "../../main/kubeconfig-manager/kubeconfig-manager";
|
||||
import { loadConfigFromFile } from "../kube-helpers";
|
||||
import { loadConfigFromString } from "../kube-helpers";
|
||||
import type { KubeApiResource, KubeResource } from "../rbac";
|
||||
import { apiResourceRecord, apiResources } from "../rbac";
|
||||
import type { VersionDetector } from "../../main/cluster-detectors/version-detector";
|
||||
@ -25,6 +25,7 @@ import type { CanI } from "./authorization-review.injectable";
|
||||
import type { ListNamespaces } from "./list-namespaces.injectable";
|
||||
import assert from "assert";
|
||||
import type { Logger } from "../logger";
|
||||
import type { ReadFile } from "../fs/read-file.injectable";
|
||||
|
||||
export interface ClusterDependencies {
|
||||
readonly directoryForKubeConfigs: string;
|
||||
@ -36,6 +37,7 @@ export interface ClusterDependencies {
|
||||
createAuthorizationReview: (config: KubeConfig) => CanI;
|
||||
createListNamespaces: (config: KubeConfig) => ListNamespaces;
|
||||
createVersionDetector: (cluster: Cluster) => VersionDetector;
|
||||
readFile: ReadFile;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -486,7 +488,8 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
}
|
||||
|
||||
async getKubeconfig(): Promise<KubeConfig> {
|
||||
const { config } = await loadConfigFromFile(this.kubeConfigPath);
|
||||
const configData = await this.dependencies.readFile(this.kubeConfigPath);
|
||||
const { config } = loadConfigFromString(configData);
|
||||
|
||||
return config;
|
||||
}
|
||||
@ -496,7 +499,8 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
*/
|
||||
async getProxyKubeconfig(): Promise<KubeConfig> {
|
||||
const proxyKCPath = await this.getProxyKubeconfigPath();
|
||||
const { config } = await loadConfigFromFile(proxyKCPath);
|
||||
const configData = await this.dependencies.readFile(proxyKCPath);
|
||||
const { config } = loadConfigFromString(configData);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -5,11 +5,16 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
export type ReadFile = (filePath: string) => Promise<string>;
|
||||
|
||||
const readFileInjectable = getInjectable({
|
||||
id: "read-file",
|
||||
|
||||
instantiate: (di) => (filePath: string) =>
|
||||
di.inject(fsInjectable).readFile(filePath, "utf-8"),
|
||||
instantiate: (di): ReadFile => {
|
||||
const { readFile } = di.inject(fsInjectable);
|
||||
|
||||
return (filePath) => readFile(filePath, "utf-8");
|
||||
},
|
||||
});
|
||||
|
||||
export default readFileInjectable;
|
||||
|
||||
@ -4,25 +4,18 @@
|
||||
*/
|
||||
|
||||
import { KubeConfig } from "@kubernetes/client-node";
|
||||
import fse from "fs-extra";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import yaml from "js-yaml";
|
||||
import logger from "../main/logger";
|
||||
import type { Cluster, Context, User } from "@kubernetes/client-node/dist/config_types";
|
||||
import { newClusters, newContexts, newUsers } from "@kubernetes/client-node/dist/config_types";
|
||||
import { isDefined, resolvePath } from "./utils";
|
||||
import { isDefined } from "./utils";
|
||||
import Joi from "joi";
|
||||
import type { PartialDeep } from "type-fest";
|
||||
|
||||
export const kubeConfigDefaultPath = path.join(os.homedir(), ".kube", "config");
|
||||
|
||||
export async function loadConfigFromFile(filePath: string): Promise<ConfigResult> {
|
||||
const content = await fse.readFile(resolvePath(filePath), "utf-8");
|
||||
|
||||
return loadConfigFromString(content);
|
||||
}
|
||||
|
||||
const clusterSchema = Joi.object({
|
||||
name: Joi
|
||||
.string()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user