Upgrade js-yaml to 4.X (#3623)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-10-18 10:03:10 -04:00
1 parent fcb3010033
commit 5998b4ca84
17 files changed
+90 -57

No files matched your search

+11 -2
View File
@@ -29,6 +29,11 @@ import { helmCli } from "./helm-cli";
import type { RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api";
import { sortCharts } from "../../common/utils";
export interface HelmCacheFile {
apiVersion: string;
entries: RepoHelmChartList;
}
export class HelmChartManager {
static #cache = new Map<string, Buffer>();
@@ -82,7 +87,11 @@ export class HelmChartManager {
protected async cachedYaml(): Promise<RepoHelmChartList> {
if (!HelmChartManager.#cache.has(this.repo.name)) {
const cacheFile = await fs.promises.readFile(this.repo.cacheFilePath, "utf-8");
const { entries } = yaml.safeLoad(cacheFile) as { entries: RepoHelmChartList };
const data = yaml.load(cacheFile) as string | number | HelmCacheFile;
if (typeof data !== "object" || !data) {
return {};
}
/**
* Do some initial preprocessing on the data, so as to avoid needing to do it later
@@ -92,7 +101,7 @@ export class HelmChartManager {
*/
const normalized = Object.fromEntries(
Object.entries(entries)
Object.entries(data.entries)
.map(([name, charts]) => [
name,
sortCharts(
+2 -2
View File
@@ -53,7 +53,7 @@ export async function installChart(chart: string, values: any, name: string | un
const helm = await helmCli.binaryPath();
const fileName = tempy.file({ name: "values.yaml" });
await fse.writeFile(fileName, yaml.safeDump(values));
await fse.writeFile(fileName, yaml.dump(values));
try {
let generateName = "";
@@ -83,7 +83,7 @@ export async function upgradeRelease(name: string, chart: string, values: any, n
const helm = await helmCli.binaryPath();
const fileName = tempy.file({ name: "values.yaml" });
await fse.writeFile(fileName, yaml.safeDump(values));
await fse.writeFile(fileName, yaml.dump(values));
try {
const proxyKubeconfig = await cluster.getProxyKubeconfigPath();
+16 -6
View File
@@ -101,18 +101,28 @@ export class HelmRepoManager extends Singleton {
return repos.find(repo => repo.name === name);
}
private async readConfig(): Promise<HelmRepoConfig> {
try {
const rawConfig = await readFile(this.helmEnv.HELM_REPOSITORY_CONFIG, "utf8");
const parsedConfig = yaml.load(rawConfig);
if (typeof parsedConfig === "object" && parsedConfig) {
return parsedConfig as HelmRepoConfig;
}
} catch { }
return {
repositories: []
};
}
public async repositories(): Promise<HelmRepo[]> {
try {
if (!this.initialized) {
await this.init();
}
const repoConfigFile = this.helmEnv.HELM_REPOSITORY_CONFIG;
const { repositories }: HelmRepoConfig = await readFile(repoConfigFile, "utf8")
.then((yamlContent: string) => yaml.safeLoad(yamlContent))
.catch(() => ({
repositories: []
}));
const { repositories } = await this.readConfig();
if (!repositories.length) {
await HelmRepoManager.addRepo({ name: "bitnami", url: "https://charts.bitnami.com/bitnami" });
+1 -1
View File
@@ -78,7 +78,7 @@ export class ResourceApplier {
resource = this.sanitizeObject(resource);
appEventBus.emit({ name: "resource", action: "apply" });
return this.kubectlApply(yaml.safeDump(resource));
return this.kubectlApply(yaml.dump(resource));
}
protected async kubectlApply(content: string): Promise<string> {