Fixup uses of AsyncResult and autoBind

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and Janne Savolainen committed 2023-03-10 09:39:23 +02:00
1 parent 9546e55961
commit f8aa389930
37 files changed
+72 -71

No files matched your search

@@ -10,11 +10,11 @@ import type { Cluster } from "../../common/cluster/cluster";
import { requestApiVersionsInjectionToken } from "./request-api-versions";
import { withConcurrencyLimit } from "@k8slens/utilities";
import requestKubeApiResourcesForInjectable from "./request-kube-api-resources-for.injectable";
import type { AsyncResult } from "../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
import { backoffCaller } from "../../common/utils/backoff-caller";
import broadcastConnectionUpdateInjectable from "./broadcast-connection-update.injectable";
export type RequestApiResources = (cluster: Cluster) => Promise<AsyncResult<KubeApiResource[], Error>>;
export type RequestApiResources = (cluster: Cluster) => AsyncResult<KubeApiResource[], Error>;
export interface KubeResourceListGroup {
group: string;
@@ -4,7 +4,7 @@
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { AsyncResult } from "../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
export interface KubeResourceListGroup {
group: string;
@@ -15,7 +15,7 @@ export interface ClusterData {
readonly id: string;
}
export type RequestApiVersions = (cluster: ClusterData) => Promise<AsyncResult<KubeResourceListGroup[], Error>>;
export type RequestApiVersions = (cluster: ClusterData) => AsyncResult<KubeResourceListGroup[], Error>;
export const requestApiVersionsInjectionToken = getInjectionToken<RequestApiVersions>({
id: "request-api-versions-token",
@@ -6,11 +6,11 @@ import type { V1APIResourceList } from "@kubernetes/client-node";
import { getInjectable } from "@ogre-tools/injectable";
import type { Cluster } from "../../common/cluster/cluster";
import type { KubeApiResource } from "../../common/rbac";
import type { AsyncResult } from "../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
import k8sRequestInjectable from "../k8s-request.injectable";
import type { KubeResourceListGroup } from "./request-api-versions";
export type RequestKubeApiResources = (grouping: KubeResourceListGroup) => Promise<AsyncResult<KubeApiResource[], Error>>;
export type RequestKubeApiResources = (grouping: KubeResourceListGroup) => AsyncResult<KubeApiResource[], Error>;
export type RequestKubeApiResourcesFor = (cluster: Cluster) => RequestKubeApiResources;
@@ -5,11 +5,11 @@
import { getInjectable } from "@ogre-tools/injectable";
import type { ExecFileException } from "child_process";
import execFileInjectable from "../../../common/fs/exec-file.injectable";
import type { AsyncResult } from "../../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
import execHelmEnvInjectable from "./exec-env.injectable";
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, ExecFileException & { stderr: string }>>;
export type ExecHelm = (args: string[]) => AsyncResult<string, ExecFileException & { stderr: string }>;
const execHelmInjectable = getInjectable({
id: "exec-helm",
@@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import execHelmInjectable from "../exec-helm/exec-helm.injectable";
import type { AsyncResult } from "../../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
export type HelmEnv = Record<string, string> & {
HELM_REPOSITORY_CACHE?: string;
@@ -17,7 +17,7 @@ const getHelmEnvInjectable = getInjectable({
instantiate: (di) => {
const execHelm = di.inject(execHelmInjectable);
return async (): Promise<AsyncResult<HelmEnv>> => {
return async (): AsyncResult<HelmEnv> => {
const result = await execHelm(["env"]);
if (!result.callWasSuccessful) {
@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { AsyncResult } from "../../../../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
import execHelmInjectable from "../../../exec-helm/exec-helm.injectable";
import yaml from "js-yaml";
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../../common/k8s-api/kube-json-api";
@@ -18,7 +18,7 @@ const callForHelmManifestInjectable = getInjectable({
name: string,
namespace: string,
kubeconfigPath: string,
): Promise<AsyncResult<(KubeJsonApiData | KubeJsonApiDataList)[]>> => {
): AsyncResult<(KubeJsonApiData | KubeJsonApiDataList)[]> => {
const result = await execHelm([
"get",
"manifest",
@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { AsyncResult } from "../../../../../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
import { isNumber } from "@k8slens/utilities";
import assert from "assert";
@@ -13,7 +13,7 @@ export type ExecFileWithInput = (options: {
filePath: string;
commandArguments: string[];
input: string;
}) => Promise<AsyncResult<string, unknown>>;
}) => AsyncResult<string, unknown>;
const execFileWithInputInjectable = getInjectable({
id: "exec-file-with-input",
@@ -5,7 +5,7 @@
import { getDiForUnitTesting } from "../../../../../getDiForUnitTesting";
import type { ExecFileWithInput } from "./exec-file-with-input.injectable";
import execFileWithInputInjectable from "./exec-file-with-input.injectable";
import type { AsyncResult } from "../../../../../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
import { getPromiseStatus } from "@k8slens/test-utils";
import EventEmitter from "events";
@@ -56,7 +56,7 @@ describe("exec-file-with-input", () => {
});
describe("when called", () => {
let actualPromise: Promise<AsyncResult<string, unknown>>;
let actualPromise: AsyncResult<string, unknown>;
beforeEach(() => {
actualPromise = execFileWithInput({
@@ -5,13 +5,13 @@
import { getInjectable } from "@ogre-tools/injectable";
import callForHelmManifestInjectable from "./call-for-helm-manifest/call-for-helm-manifest.injectable";
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../common/k8s-api/kube-json-api";
import type { AsyncResult } from "../../../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
export type GetHelmReleaseResources = (
name: string,
namespace: string,
kubeconfigPath: string,
) => Promise<AsyncResult<KubeJsonApiData[], string>>;
) => AsyncResult<KubeJsonApiData[], string>;
const getHelmReleaseResourcesInjectable = getInjectable({
id: "get-helm-release-resources",
@@ -12,7 +12,7 @@ import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { ExecFileWithInput } from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
import execFileWithInputInjectable from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
import type { AsyncResult } from "../../../../common/utils/async-result";
import type { AsyncResult } from "@k8slens/utilities";
import type { KubeJsonApiData } from "../../../../common/k8s-api/kube-json-api";
describe("get helm release resources", () => {
@@ -37,7 +37,7 @@ describe("get helm release resources", () => {
});
describe("when called", () => {
let actualPromise: Promise<AsyncResult<KubeJsonApiData[], string>>;
let actualPromise: AsyncResult<KubeJsonApiData[], string>;
beforeEach(() => {
actualPromise = getHelmReleaseResources(
@@ -6,7 +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";
import type { AsyncResult } from "@k8slens/utilities";
const removeHelmRepositoryInjectable = getInjectable({
id: "remove-helm-repository",
@@ -15,7 +15,7 @@ const removeHelmRepositoryInjectable = getInjectable({
const execHelm = di.inject(execHelmInjectable);
const logger = di.inject(loggerInjectable);
return async (repo: HelmRepo): Promise<AsyncResult<void, string>> => {
return async (repo: HelmRepo): AsyncResult<void, string> => {
logger.info(`[HELM]: removing repo ${repo.name} (${repo.url})`);
const result = await execHelm([
@@ -14,9 +14,9 @@ import type { WriteFile } from "../../common/fs/write-file.injectable";
import type { RemovePath } from "../../common/fs/remove.injectable";
import type { ExecFile } from "../../common/fs/exec-file.injectable";
import type { JoinPaths } from "../../common/path/join-paths.injectable";
import type { AsyncResult } from "../../common/utils/async-result";
import type { CreateKubectl } from "../kubectl/create-kubectl.injectable";
import type { KubeconfigManager } from "../kubeconfig-manager/kubeconfig-manager";
import type { AsyncResult } from "@k8slens/utilities";
export interface ResourceApplierDependencies {
emitAppEvent: EmitAppEvent;
@@ -81,13 +81,13 @@ export class ResourceApplier {
throw result.error.stderr || result.error.message;
}
async create(resource: string): Promise<AsyncResult<string, string>> {
async create(resource: string): AsyncResult<string, string> {
this.dependencies.emitAppEvent({ name: "resource", action: "apply" });
return this.kubectlApply(this.sanitizeObject(resource));
}
protected async kubectlApply(content: string): Promise<AsyncResult<string, string>> {
protected async kubectlApply(content: string): AsyncResult<string, string> {
const kubectlPath = await this.getKubectlPath();
const proxyKubeconfigPath = await this.dependencies.proxyKubeconfigManager.ensurePath();
const fileName = tempy.file({ name: "resource.yaml" });
@@ -125,15 +125,15 @@ export class ResourceApplier {
}
}
public async kubectlApplyAll(resources: string[], extraArgs = ["-o", "json"]): Promise<AsyncResult<string, string>> {
public async kubectlApplyAll(resources: string[], extraArgs = ["-o", "json"]): AsyncResult<string, string> {
return this.kubectlCmdAll("apply", resources, extraArgs);
}
public async kubectlDeleteAll(resources: string[], extraArgs?: string[]): Promise<AsyncResult<string, string>> {
public async kubectlDeleteAll(resources: string[], extraArgs?: string[]): AsyncResult<string, string> {
return this.kubectlCmdAll("delete", resources, extraArgs);
}
protected async kubectlCmdAll(subCmd: string, resources: string[], parentArgs: string[] = []): Promise<AsyncResult<string, string>> {
protected async kubectlCmdAll(subCmd: string, resources: string[], parentArgs: string[] = []): AsyncResult<string, string> {
const kubectlPath = await this.getKubectlPath();
const proxyKubeconfigPath = await this.dependencies.proxyKubeconfigManager.ensurePath();
const tmpDir = tempy.directory();