Make PrometheusProviderRegistry fully injectable (#6592)

* Stop using source code in build file

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

* Add new injectable version of binaryName

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

* Add new NormalizedPlatform type

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

* Switch legacy execHelm to use legacy global DI for binaryPath

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

* Remove dead code

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

* Introduce injectable for kube auth proxy certs

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

* Introduce injectable forms of PrometheusProviders

- Remove class requirement
- Make everything injectable

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

* Update tests to not use private functions

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

* Cleanup creating binary names and paths

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-11-25 09:19:57 -05:00
1 parent 30bfd6fa88
commit 286e6c8de7
32 files changed
+589 -636

No files matched your search

+5 -2
View File
@@ -6,9 +6,10 @@
import { promiseExecFile } from "../../common/utils/promise-exec";
import type { ObjectEncodingOptions } from "fs";
import type { ExecFileOptions, ExecFileOptionsWithStringEncoding } from "child_process";
import { helmBinaryPath } from "../../common/vars";
import { UserStore } from "../../common/user-store";
import { isChildProcessError } from "../../common/utils";
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import helmBinaryPathInjectable from "./helm-binary-path.injectable";
/**
* ExecFile the bundled helm CLI
@@ -19,6 +20,8 @@ export async function execHelm(args: string[], { encoding, ...rest }: ObjectEnco
encoding: encoding ?? "utf-8",
...rest,
};
const di = getLegacyGlobalDiForExtensionApi();
const helmBinaryPath = di.inject(helmBinaryPathInjectable);
try {
const opts = { ...options };
@@ -29,7 +32,7 @@ export async function execHelm(args: string[], { encoding, ...rest }: ObjectEnco
opts.env.HTTPS_PROXY = UserStore.getInstance().httpsProxy;
}
const { stdout } = await promiseExecFile(helmBinaryPath.get(), args, opts);
const { stdout } = await promiseExecFile(helmBinaryPath, args, opts);
return stdout;
} catch (error) {
+2 -14
View File
@@ -3,23 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { getBinaryName } from "../../common/vars";
import normalizedPlatformInjectable from "../../common/vars/normalized-platform.injectable";
import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable";
import joinPathsInjectable from "../../common/path/join-paths.injectable";
import bundledBinaryPathInjectable from "../../common/utils/bundled-binary-path.injectable";
const helmBinaryPathInjectable = getInjectable({
id: "helm-binary-path",
instantiate: (di) => {
const joinPaths = di.inject(joinPathsInjectable);
const normalizedPlatform = di.inject(normalizedPlatformInjectable);
const baseBundledBinariesDirectory = di.inject(baseBundledBinariesDirectoryInjectable);
const helmBinaryName = getBinaryName("helm", { forPlatform: normalizedPlatform });
return joinPaths(baseBundledBinariesDirectory, helmBinaryName);
},
instantiate: (di) => di.inject(bundledBinaryPathInjectable, "helm"),
});
export default helmBinaryPathInjectable;