Skip to content

Commit

Permalink
Cleanup creating binary names and paths
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Malton <sebastian@malton.name>
  • Loading branch information
Nokel81 committed Nov 25, 2022
1 parent 285c9f2 commit eb5d3b1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import normalizedPlatformInjectable from "../vars/normalized-platform.injectable";

const binaryNameInjectable = getInjectable({
id: "get-binary-name",
id: "binary-name",
instantiate: (di, binaryName) => {
const normalizedPlatform = di.inject(normalizedPlatformInjectable);

Expand Down
24 changes: 24 additions & 0 deletions src/common/utils/bundled-binary-path.injectable.ts
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 2 additions & 11 deletions src/main/helm/helm-binary-path.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable";
import joinPathsInjectable from "../../common/path/join-paths.injectable";
import binaryNameInjectable from "../../common/utils/get-binary-name.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 binaryName = di.inject(binaryNameInjectable, "helm");
const baseBundledBinariesDirectory = di.inject(baseBundledBinariesDirectoryInjectable);

return joinPaths(baseBundledBinariesDirectory, binaryName);
},
instantiate: (di) => di.inject(bundledBinaryPathInjectable, "helm"),
});

export default helmBinaryPathInjectable;
12 changes: 2 additions & 10 deletions src/main/kube-auth-proxy/lens-k8s-proxy-path.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import joinPathsInjectable from "../../common/path/join-paths.injectable";
import binaryNameInjectable from "../../common/utils/get-binary-name.injectable";
import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable";
import bundledBinaryPathInjectable from "../../common/utils/bundled-binary-path.injectable";

const lensK8sProxyPathInjectable = getInjectable({
id: "lens-k8s-proxy-path",
instantiate: (di) => {
const joinPaths = di.inject(joinPathsInjectable);
const binaryName = di.inject(binaryNameInjectable, "lens-k8s-proxy");
const baseBundledBinariesDirectory = di.inject(baseBundledBinariesDirectoryInjectable);

return joinPaths(baseBundledBinariesDirectory, binaryName);
},
instantiate: (di) => di.inject(bundledBinaryPathInjectable, "lens-k8s-proxy"),
});

export default lensK8sProxyPathInjectable;
2 changes: 1 addition & 1 deletion src/main/kubectl/binary-name.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import binaryNameInjectable from "../../common/utils/get-binary-name.injectable";
import binaryNameInjectable from "../../common/utils/binary-name.injectable";

const kubectlBinaryNameInjectable = getInjectable({
id: "kubectl-binary-name",
Expand Down
13 changes: 2 additions & 11 deletions src/main/kubectl/bundled-binary-path.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import joinPathsInjectable from "../../common/path/join-paths.injectable";
import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable";
import kubectlBinaryNameInjectable from "./binary-name.injectable";
import bundledBinaryPathInjectable from "../../common/utils/bundled-binary-path.injectable";

const bundledKubectlBinaryPathInjectable = getInjectable({
id: "bundled-kubectl-binary-path",
instantiate: (di) => {
const joinPaths = di.inject(joinPathsInjectable);

return joinPaths(
di.inject(baseBundledBinariesDirectoryInjectable),
di.inject(kubectlBinaryNameInjectable),
);
},
instantiate: (di) => di.inject(bundledBinaryPathInjectable, "kubectl"),
});

export default bundledKubectlBinaryPathInjectable;

0 comments on commit eb5d3b1

Please sign in to comment.