Skip to content

Commit

Permalink
wip: refactoring dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
  • Loading branch information
Ivo-Yankov committed Dec 18, 2024
1 parent a4ef700 commit c582f12
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 262 deletions.
191 changes: 13 additions & 178 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"stream-buffers": "^3.0.3",
"tar": "^7.4.3",
"tsx": "^4.19.2",
"tsyringe-neo": "^5.1.0",
"uuid": "^11.0.3",
"validator": "^13.12.0",
"winston": "^3.17.0",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {type CommandFlag} from '../types/flag_types.js';
import {type Lease} from '../core/lease/lease.js';
import {Listr} from 'listr2';
import path from 'path';
import {container, injectable} from "tsyringe-neo";

export interface CommandHandlers {
parent: BaseCommand;
Expand All @@ -48,7 +49,7 @@ export abstract class BaseCommand extends ShellRunner {
protected readonly remoteConfigManager: RemoteConfigManager;

constructor(opts: Opts) {
if (!opts || !opts.logger) throw new Error('An instance of core/SoloLogger is required');
// if (!opts || !opts.logger) throw new Error('An instance of core/SoloLogger is required');
if (!opts || !opts.helm) throw new Error('An instance of core/Helm is required');
if (!opts || !opts.k8) throw new Error('An instance of core/K8 is required');
if (!opts || !opts.chartManager) throw new Error('An instance of core/ChartManager is required');
Expand All @@ -57,8 +58,7 @@ export abstract class BaseCommand extends ShellRunner {
if (!opts || !opts.localConfig) throw new Error('An instance of core/LocalConfig is required');
if (!opts || !opts.remoteConfigManager)
throw new Error('An instance of core/config/RemoteConfigManager is required');

super(opts.logger);
super();

this.helm = opts.helm;
this.k8 = opts.k8;
Expand Down
43 changes: 43 additions & 0 deletions src/core/container_init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {container} from "tsyringe-neo";
import {SoloLogger} from "./logging.js";
import {PackageDownloader} from "./package_downloader.js";
import {Zippy} from "./zippy.js";
import {DependencyManager, HelmDependencyManager} from "./dependency_managers/index.js";
import * as constants from "./constants.js";
import {Helm} from "./helm.js";
import {ChartManager} from "./chart_manager.js";
import {ConfigManager} from "./config_manager.js";
import {K8} from "./k8.js";
import {AccountManager} from "./account_manager.js";
import {PlatformInstaller} from "./platform_installer.js";
import {KeyManager} from "./key_manager.js";
import {ProfileManager} from "./profile_manager.js";
import type {LeaseRenewalService} from "./lease/lease.js";
import {IntervalLeaseRenewalService} from "./lease/interval_lease_renewal.js";
import {LeaseManager} from "./lease/lease_manager.js";
import {CertificateManager} from "./certificate_manager.js";
import path from "path";
import {LocalConfig} from "./config/local_config.js";
import {RemoteConfigManager} from "./config/remote/remote_config_manager.js";

container.register<SoloLogger>(SoloLogger, {useValue: new SoloLogger('debug', false)});
container.register<PackageDownloader>(PackageDownloader, {useValue: new PackageDownloader()});
container.register<Zippy>(Zippy, {useValue: new Zippy()});
container.register<HelmDependencyManager>(HelmDependencyManager, {useValue: new HelmDependencyManager()});
container.register<DependencyManager>(DependencyManager, {useValue: new DependencyManager()});
container.register<Helm>(Helm, {useValue: new Helm()});


// const chartManager = new ChartManager(helm, logger);
// const configManager = new ConfigManager(logger);
// const k8 = new K8(configManager, logger);
// const accountManager = new AccountManager(logger, k8);
// const platformInstaller = new PlatformInstaller(logger, k8, configManager);
// const keyManager = new KeyManager(logger);
// const profileManager = new ProfileManager(logger, configManager);
// const leaseRenewalService: LeaseRenewalService = new IntervalLeaseRenewalService();
// const leaseManager = new LeaseManager(k8, configManager, logger, leaseRenewalService);
// const certificateManager = new CertificateManager(k8, logger, configManager);
// const localConfigPath = path.join(constants.SOLO_CACHE_DIR, constants.DEFAULT_LOCAL_CONFIG_FILE);
// const localConfig = new LocalConfig(localConfigPath, logger, configManager);
// const remoteConfigManager = new RemoteConfigManager(k8, logger, localConfig, configManager);
20 changes: 10 additions & 10 deletions src/core/dependency_managers/dependency_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
*
*/
import os from 'os';
import {SoloError, MissingArgumentError} from '../errors.js';
import {SoloError} from '../errors.js';
import {ShellRunner} from '../shell_runner.js';
import {type SoloLogger} from '../logging.js';
import {type HelmDependencyManager} from './helm_dependency_manager.js';
import {HelmDependencyManager} from './helm_dependency_manager.js';
import {type ListrTask} from 'listr2';
import {autoInjectable} from "tsyringe-neo";
import * as constants from "../constants.js";

@autoInjectable()
export class DependencyManager extends ShellRunner {
constructor(
logger: SoloLogger,
private readonly depManagerMap: Map<string, HelmDependencyManager>,
) {
if (!logger) throw new MissingArgumentError('an instance of core/SoloLogger is required', logger);
super(logger);
if (!depManagerMap) throw new MissingArgumentError('A map of dependency managers are required');
private readonly depManagerMap: Map<string, HelmDependencyManager>;

constructor(helmDepManager?: HelmDependencyManager) {
super();
this.depManagerMap = new Map().set(constants.HELM, helmDepManager);
}

/**
Expand Down
20 changes: 9 additions & 11 deletions src/core/dependency_managers/helm_dependency_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import * as util from 'util';
import {IllegalArgumentError, MissingArgumentError} from '../errors.js';
import * as helpers from '../helpers.js';
import * as constants from '../constants.js';
import {type PackageDownloader} from '../package_downloader.js';
import {type Zippy} from '../zippy.js';
import {PackageDownloader} from '../package_downloader.js';
import {Zippy} from '../zippy.js';
import {Templates} from '../templates.js';
import * as version from '../../../version.js';
import {ShellRunner} from '../shell_runner.js';
import * as semver from 'semver';
import {OS_WIN32, OS_WINDOWS} from '../constants.js';
import {type SoloLogger} from '../logging.js';
import {autoInjectable, container, singleton} from "tsyringe-neo";

// constants required by HelmDependencyManager
const HELM_RELEASE_BASE_URL = 'https://get.helm.sh';
Expand All @@ -42,32 +43,29 @@ const HELM_ARTIFACT_EXT: Map<string, string> = new Map()
/**
* Helm dependency manager installs or uninstalls helm client at SOLO_HOME_DIR/bin directory
*/
@singleton()
export class HelmDependencyManager extends ShellRunner {
private readonly osPlatform: string;
private readonly osArch: string;
private helmPath: string;
private readonly artifactName: string;
private readonly helmURL: string;
private readonly checksumURL: string;
private readonly downloader;
private readonly zippy;

constructor(
private readonly downloader: PackageDownloader,
private readonly zippy: Zippy,
logger: SoloLogger,
private readonly installationDir = path.join(constants.SOLO_HOME_DIR, 'bin'),
osPlatform = os.platform(),
osArch = os.arch(),
private readonly helmVersion = version.HELM_VERSION,
) {
super(logger);
super();

if (!downloader) throw new MissingArgumentError('An instance of core/PackageDownloader is required');
if (!zippy) throw new MissingArgumentError('An instance of core/Zippy is required');
if (!logger) throw new IllegalArgumentError('an instance of core/SoloLogger is required', logger);
if (!installationDir) throw new MissingArgumentError('installation directory is required');

this.downloader = downloader;
this.zippy = zippy;
this.downloader = container.resolve(PackageDownloader);
this.zippy = container.resolve(Zippy);
this.installationDir = installationDir;
// Node.js uses 'win32' for windows in package.json os field, but helm uses 'windows'
if (osPlatform === OS_WIN32) {
Expand Down
Loading

0 comments on commit c582f12

Please sign in to comment.