Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 24269fe
Author: Ivo Yankov <ivo@devlabs.bg>
Date:   Fri Dec 20 11:03:26 2024 +0200

    wip: attempting to fix tests

    Signed-off-by: Ivo Yankov <ivo@devlabs.bg>

commit 7698f16
Author: Ivo Yankov <ivo@devlabs.bg>
Date:   Thu Dec 19 15:41:38 2024 +0200

    chore: format

    Signed-off-by: Ivo Yankov <ivo@devlabs.bg>

commit 507a081
Author: Ivo Yankov <ivo@devlabs.bg>
Date:   Thu Dec 19 14:53:36 2024 +0200

    feat: implement IOC in core classes

    Signed-off-by: Ivo Yankov <ivo@devlabs.bg>

commit c582f12
Author: Ivo Yankov <ivo@devlabs.bg>
Date:   Wed Dec 18 17:32:22 2024 +0200

    wip: refactoring dependencies

    Signed-off-by: Ivo Yankov <ivo@devlabs.bg>

Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
  • Loading branch information
jeromy-cannon committed Dec 23, 2024
1 parent 1b9b7e6 commit f323ca7
Show file tree
Hide file tree
Showing 51 changed files with 467 additions and 332 deletions.
7 changes: 0 additions & 7 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,6 @@ export default [
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/consistent-type-imports': [
// optional: assists in reducing circular dependencies
'error',
{
fixStyle: 'inline-type-imports',
},
],
'@typescript-eslint/no-explicit-any': 'warn', // TODO remove (771 errors)
'@typescript-eslint/no-this-alias': [
'error',
Expand Down
13 changes: 13 additions & 0 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
5 changes: 2 additions & 3 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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 +57,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
13 changes: 6 additions & 7 deletions src/core/account_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ import type {NetworkNodeServices} from './network_node_services.js';
import {NetworkNodeServicesBuilder} from './network_node_services.js';
import path from 'path';

import {type SoloLogger} from './logging.js';
import {type K8} from './k8.js';
import {SoloLogger} from './logging.js';
import {K8} from './k8.js';
import {type AccountIdWithKeyPairObject, type ExtendedNetServer} from '../types/index.js';
import {type NodeAlias, type PodName, type SdkNetworkEndpoint} from '../types/aliases.js';
import {IGNORED_NODE_ACCOUNT_ID} from './constants.js';
import {sleep} from './helpers.js';
import {Duration} from './time/duration.js';
import {autoInjectable} from 'tsyringe-neo';

const REASON_FAILED_TO_GET_KEYS = 'failed to get keys for accountId';
const REASON_SKIPPED = 'skipped since it does not have a genesis key';
Expand All @@ -55,17 +56,15 @@ const REASON_FAILED_TO_CREATE_K8S_S_KEY = 'failed to create k8s scrt key';
const FULFILLED = 'fulfilled';
const REJECTED = 'rejected';

@autoInjectable()
export class AccountManager {
private _portForwards: ExtendedNetServer[];
public _nodeClient: Client | null;

constructor(
private readonly logger: SoloLogger,
private readonly k8: K8,
private readonly logger?: SoloLogger,
private readonly k8?: K8,
) {
if (!logger) throw new Error('An instance of core/SoloLogger is required');
if (!k8) throw new Error('An instance of core/K8 is required');

this._portForwards = [];
this._nodeClient = null;
}
Expand Down
20 changes: 9 additions & 11 deletions src/core/certificate_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,23 @@ import fs from 'fs';
import {Templates} from './templates.js';
import {GrpcProxyTlsEnums} from './enumerations.js';

import type {ConfigManager} from './config_manager.js';
import type {K8} from './k8.js';
import type {SoloLogger} from './logging.js';
import {ConfigManager} from './config_manager.js';
import {K8} from './k8.js';
import {SoloLogger} from './logging.js';
import type {ListrTaskWrapper} from 'listr2';
import type {NodeAlias} from '../types/aliases.js';
import {autoInjectable} from 'tsyringe-neo';

/**
* Used to handle interactions with certificates data and inject it into the K8s cluster secrets
*/
@autoInjectable()
export class CertificateManager {
constructor(
private readonly k8: K8,
private readonly logger: SoloLogger,
private readonly configManager: ConfigManager,
) {
if (!k8) throw new MissingArgumentError('an instance of core/K8 is required');
if (!logger) throw new MissingArgumentError('an instance of core/SoloLogger is required');
if (!configManager) throw new MissingArgumentError('an instance of core/ConfigManager is required');
}
private readonly k8?: K8,
private readonly logger?: SoloLogger,
private readonly configManager?: ConfigManager,
) {}

/**
* Reads the certificate and key and build the secret with the appropriate structure
Expand Down
15 changes: 7 additions & 8 deletions src/core/chart_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
*
*/
import * as constants from './constants.js';
import {type Helm} from './helm.js';
import {Helm} from './helm.js';
import chalk from 'chalk';
import {SoloError} from './errors.js';
import {type SoloLogger} from './logging.js';
import {SoloLogger} from './logging.js';
import {autoInjectable} from 'tsyringe-neo';

@autoInjectable()
export class ChartManager {
constructor(
private readonly helm: Helm,
private readonly logger: SoloLogger,
) {
if (!logger) throw new Error('An instance of core/SoloLogger is required');
if (!helm) throw new Error('An instance of core/Helm is required');
}
private readonly helm?: Helm,
private readonly logger?: SoloLogger,
) {}

/**
* Setup chart repositories
Expand Down
11 changes: 6 additions & 5 deletions src/core/config/local_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ import {
type LocalConfigData,
} from './local_config_data.js';
import {MissingArgumentError, SoloError} from '../errors.js';
import {type SoloLogger} from '../logging.js';
import {SoloLogger} from '../logging.js';
import {IsClusterContextMapping, IsDeployments} from '../validator_decorators.js';
import type {ConfigManager} from '../config_manager.js';
import {ConfigManager} from '../config_manager.js';
import type {EmailAddress, Namespace} from './remote/types.js';
import {ErrorMessages} from '../error_messages.js';
import {type K8} from '../k8.js';
import {splitFlagInput} from '../helpers.js';
import {autoInjectable} from 'tsyringe-neo';

@autoInjectable()
export class LocalConfig implements LocalConfigData {
@IsEmail(
{},
Expand Down Expand Up @@ -70,11 +72,10 @@ export class LocalConfig implements LocalConfigData {

public constructor(
private readonly filePath: string,
private readonly logger: SoloLogger,
private readonly configManager: ConfigManager,
private readonly logger?: SoloLogger,
private readonly configManager?: ConfigManager,
) {
if (!filePath || filePath === '') throw new MissingArgumentError('a valid filePath is required');
if (!logger) throw new Error('An instance of core/SoloLogger is required');

const allowedKeys = ['userEmailAddress', 'deployments', 'currentDeploymentName', 'clusterContextMapping'];
if (this.configFileExists()) {
Expand Down
18 changes: 10 additions & 8 deletions src/core/config/remote/remote_config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ import {Flags as flags} from '../../../commands/flags.js';
import * as yaml from 'yaml';
import {ComponentsDataWrapper} from './components_data_wrapper.js';
import {RemoteConfigValidator} from './remote_config_validator.js';
import type {K8} from '../../k8.js';
import {K8} from '../../k8.js';
import type {Cluster, Namespace} from './types.js';
import type {SoloLogger} from '../../logging.js';
import type {ConfigManager} from '../../config_manager.js';
import type {LocalConfig} from '../local_config.js';
import {SoloLogger} from '../../logging.js';
import {ConfigManager} from '../../config_manager.js';
import {LocalConfig} from '../local_config.js';
import type {DeploymentStructure} from '../local_config_data.js';
import {type ContextClusterStructure} from '../../../types/config_types.js';
import {type EmptyContextConfig, type Optional, type SoloListrTask} from '../../../types/index.js';
import type * as k8s from '@kubernetes/client-node';
import {StatusCodes} from 'http-status-codes';
import {autoInjectable} from 'tsyringe-neo';

interface ListrContext {
config: {contextCluster: ContextClusterStructure};
Expand All @@ -42,6 +43,7 @@ interface ListrContext {
* Uses Kubernetes ConfigMaps to manage the remote configuration data by creating, loading, modifying,
* and saving the configuration data to and from a Kubernetes cluster.
*/
@autoInjectable()
export class RemoteConfigManager {
/** Stores the loaded remote configuration data. */
private remoteConfig: Optional<RemoteConfigDataWrapper>;
Expand All @@ -53,10 +55,10 @@ export class RemoteConfigManager {
* @param configManager - Manager to retrieve application flags and settings.
*/
public constructor(
private readonly k8: K8,
private readonly logger: SoloLogger,
private readonly localConfig: LocalConfig,
private readonly configManager: ConfigManager,
private readonly k8?: K8,
private readonly logger?: SoloLogger,
private readonly localConfig?: LocalConfig,
private readonly configManager?: ConfigManager,
) {}

/* ---------- Getters ---------- */
Expand Down
10 changes: 5 additions & 5 deletions src/core/config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@
* limitations under the License.
*
*/
import {SoloError, MissingArgumentError, IllegalArgumentError} from './errors.js';
import {SoloError, MissingArgumentError} from './errors.js';
import {SoloLogger} from './logging.js';
import {Flags, Flags as flags} from '../commands/flags.js';
import * as paths from 'path';
import * as helpers from './helpers.js';
import type * as yargs from 'yargs';
import {type CommandFlag} from '../types/flag_types.js';
import {type ListrTaskWrapper} from 'listr2';
import {autoInjectable, container} from 'tsyringe-neo';

/**
* ConfigManager cache command flag values so that user doesn't need to enter the same values repeatedly.
*
* For example, 'namespace' is usually remains the same across commands once it is entered, and therefore user
* doesn't need to enter it repeatedly. However, user should still be able to specify the flag explicitly for any command.
*/
@autoInjectable()
export class ConfigManager {
config!: Record<string, any>;

constructor(private readonly logger: SoloLogger) {
if (!logger || !(logger instanceof SoloLogger))
throw new MissingArgumentError('An instance of core/SoloLogger is required');

constructor(private readonly logger?: SoloLogger) {
const logger2 = container.resolve(SoloLogger)
this.reset();
}

Expand Down
60 changes: 60 additions & 0 deletions src/core/container_init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the ""License"");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an ""AS IS"" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
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 {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()});
container.register<ChartManager>(ChartManager, {useValue: new ChartManager()});
container.register<ConfigManager>(ConfigManager, {useValue: new ConfigManager()});
container.register<K8>(K8, {useValue: new K8()});
container.register<AccountManager>(AccountManager, {useValue: new AccountManager()});
container.register<PlatformInstaller>(PlatformInstaller, {useValue: new PlatformInstaller()});
container.register<KeyManager>(KeyManager, {useValue: new KeyManager()});
container.register<ProfileManager>(ProfileManager, {useValue: new ProfileManager()});
container.register<IntervalLeaseRenewalService>(IntervalLeaseRenewalService, {
useValue: new IntervalLeaseRenewalService(),
});
container.register<LeaseManager>(LeaseManager, {
useValue: new LeaseManager(container.resolve(IntervalLeaseRenewalService)),
});
container.register<CertificateManager>(CertificateManager, {useValue: new CertificateManager()});
const localConfigPath = path.join(constants.SOLO_CACHE_DIR, constants.DEFAULT_LOCAL_CONFIG_FILE);
container.register<LocalConfig>(LocalConfig, {useValue: new LocalConfig(localConfigPath)});
container.register<RemoteConfigManager>(RemoteConfigManager, {useValue: new RemoteConfigManager()});
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
Loading

0 comments on commit f323ca7

Please sign in to comment.