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

@@ -0,0 +1,24 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import normalizedPlatformInjectable from "../vars/normalized-platform.injectable";
const binaryNameInjectable = getInjectable({
id: "binary-name",
instantiate: (di, binaryName) => {
const normalizedPlatform = di.inject(normalizedPlatformInjectable);
if (normalizedPlatform === "windows") {
return `${binaryName}.exe`;
}
return binaryName;
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, binaryName: string) => binaryName,
}),
});
export default binaryNameInjectable;
@@ -0,0 +1,24 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import joinPathsInjectable from "../path/join-paths.injectable";
import baseBundledBinariesDirectoryInjectable from "../vars/base-bundled-binaries-dir.injectable";
import binaryNameInjectable from "./binary-name.injectable";
const bundledBinaryPathInjectable = getInjectable({
id: "bundled-binary-path",
instantiate: (di, name) => {
const joinPaths = di.inject(joinPathsInjectable);
const binaryName = di.inject(binaryNameInjectable, name);
const baseBundledBinariesDirectory = di.inject(baseBundledBinariesDirectoryInjectable);
return joinPaths(baseBundledBinariesDirectory, binaryName);
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, binaryName: string) => binaryName,
}),
});
export default bundledBinaryPathInjectable;
-36
View File
@@ -1,36 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
/**
* A OnceCell is an object that wraps some function that produces a value.
*
* It then only calls the function on the first call to `get()` and returns the
* same instance/value on every subsequent call.
*/
export interface LazyInitialized<T> {
get(): T;
}
/**
* A function to make a `OnceCell<T>`
*/
export function lazyInitialized<T>(builder: () => T): LazyInitialized<T> {
let value: T | undefined;
let called = false;
return {
get() {
if (called) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return value!;
}
value = builder();
called = true;
return value;
},
};
}