Remove global version of appEventBus (#6096)

* Remove global version of appEventBus

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Introduce a temporary but better shape of ExecFileInjectable error

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-10-31 14:59:05 +02:00
1 parent ba349e8b8d
commit 900f02fd8c
53 files changed
+330 -283

No files matched your search

@@ -3,11 +3,12 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { ExecFileException } from "child_process";
import execFileInjectable from "../../../common/fs/exec-file.injectable";
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
import type { AsyncResult } from "../../../common/utils/async-result";
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, string>>;
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, ExecFileException & { stderr: string }>>;
const execHelmInjectable = getInjectable({
id: "exec-helm",
@@ -16,20 +17,9 @@ const execHelmInjectable = getInjectable({
const execFile = di.inject(execFileInjectable);
const helmBinaryPath = di.inject(helmBinaryPathInjectable);
return async (args) => {
const response = await execFile(helmBinaryPath, args, {
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
});
if (response.callWasSuccessful) {
return response;
}
return {
callWasSuccessful: false,
error: response.error.stderr || response.error.error.message,
};
};
return async (args) => execFile(helmBinaryPath, args, {
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
});
},
});
@@ -21,7 +21,7 @@ const getHelmEnvInjectable = getInjectable({
const result = await execHelm(["env"]);
if (!result.callWasSuccessful) {
return { callWasSuccessful: false, error: result.error };
return { callWasSuccessful: false, error: result.error.stderr };
}
const lines = result.response.split(/\r?\n/); // split by new line feed
@@ -30,7 +30,7 @@ const callForHelmManifestInjectable = getInjectable({
]);
if (!result.callWasSuccessful) {
return { callWasSuccessful: false, error: result.error };
return { callWasSuccessful: false, error: result.error.message };
}
return {
@@ -4,17 +4,18 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
import type { HelmRepo } from "../../../../common/helm/helm-repo";
import loggerInjectable from "../../../../common/logger.injectable";
import type { AddHelmRepositoryChannel } from "../../../../common/helm/add-helm-repository-channel";
import type { RequestChannelHandler } from "../../../utils/channel/channel-listeners/listener-tokens";
const addHelmRepositoryInjectable = getInjectable({
id: "add-helm-repository",
instantiate: (di) => {
instantiate: (di): RequestChannelHandler<AddHelmRepositoryChannel> => {
const execHelm = di.inject(execHelmInjectable);
const logger = di.inject(loggerInjectable);
return async (repo: HelmRepo) => {
return async (repo) => {
const {
name,
url,
@@ -54,7 +55,18 @@ const addHelmRepositoryInjectable = getInjectable({
args.push("--cert-file", certFile);
}
return await execHelm(args);
const result = await execHelm(args);
if (result.callWasSuccessful) {
return {
callWasSuccessful: true,
};
}
return {
callWasSuccessful: false,
error: result.error.stderr || result.error.message,
};
};
},
});
@@ -78,10 +78,10 @@ const getActiveHelmRepositoriesInjectable = getInjectable({
const updateResult = await execHelm(["repo", "update"]);
if (!updateResult.callWasSuccessful) {
if (!updateResult.error.includes(internalHelmErrorForNoRepositoriesFound)) {
if (!updateResult.error.stderr.includes(internalHelmErrorForNoRepositoriesFound)) {
return {
callWasSuccessful: false,
error: `Error updating Helm repositories: ${updateResult.error}`,
error: `Error updating Helm repositories: ${updateResult.error.stderr}`,
};
}
const resultOfAddingDefaultRepository = await execHelm(["repo", "add", "bitnami", "https://charts.bitnami.com/bitnami"]);
@@ -89,7 +89,7 @@ const getActiveHelmRepositoriesInjectable = getInjectable({
if (!resultOfAddingDefaultRepository.callWasSuccessful) {
return {
callWasSuccessful: false,
error: `Error when adding default Helm repository: ${resultOfAddingDefaultRepository.error}`,
error: `Error when adding default Helm repository: ${resultOfAddingDefaultRepository.error.stderr}`,
};
}
}
@@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
import type { HelmRepo } from "../../../../common/helm/helm-repo";
import loggerInjectable from "../../../../common/logger.injectable";
import type { AsyncResult } from "../../../../common/utils/async-result";
const removeHelmRepositoryInjectable = getInjectable({
id: "remove-helm-repository",
@@ -14,14 +15,25 @@ const removeHelmRepositoryInjectable = getInjectable({
const execHelm = di.inject(execHelmInjectable);
const logger = di.inject(loggerInjectable);
return async (repo: HelmRepo) => {
return async (repo: HelmRepo): Promise<AsyncResult<void, string>> => {
logger.info(`[HELM]: removing repo ${repo.name} (${repo.url})`);
return execHelm([
const result = await execHelm([
"repo",
"remove",
repo.name,
]);
if (result.callWasSuccessful) {
return {
callWasSuccessful: true,
};
}
return {
callWasSuccessful: false,
error: result.error.stderr,
};
};
},
});