diff --git a/src/commands/mirror_node.ts b/src/commands/mirror_node.ts index 51dbf9a87..ae03d4bd7 100644 --- a/src/commands/mirror_node.ts +++ b/src/commands/mirror_node.ts @@ -278,7 +278,6 @@ export class MirrorNodeCommand extends BaseCommand { return ListrLease.newAcquireLeaseTask(lease, task); }, }, - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), { title: 'Enable mirror-node', task: (_, parentTask) => { @@ -597,7 +596,6 @@ export class MirrorNodeCommand extends BaseCommand { return ListrLease.newAcquireLeaseTask(lease, task); }, }, - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), { title: 'Destroy mirror-node', task: async ctx => { diff --git a/src/commands/network.ts b/src/commands/network.ts index 5dea8d64e..2c20699f5 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -509,7 +509,6 @@ export class NetworkCommand extends BaseCommand { return ListrLease.newAcquireLeaseTask(lease, task); }, }, - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), { title: 'Copy gRPC TLS Certificates', task: (ctx, parentTask) => diff --git a/src/commands/node/handlers.ts b/src/commands/node/handlers.ts index 47f247451..e26a72f05 100644 --- a/src/commands/node/handlers.ts +++ b/src/commands/node/handlers.ts @@ -104,7 +104,6 @@ export class NodeCommandHandlers implements CommandHandlers { deletePrepareTaskList(argv: any, lease: Lease) { return [ this.tasks.initialize(argv, deleteConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateSingleNodeState({excludedStates: []}), this.tasks.identifyExistingNodes(), this.tasks.loadAdminKey(), @@ -148,7 +147,6 @@ export class NodeCommandHandlers implements CommandHandlers { addPrepareTasks(argv: any, lease: Lease) { return [ this.tasks.initialize(argv, addConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateSingleNodeState({excludedStates: []}), this.tasks.checkPVCsEnabled(), this.tasks.identifyExistingNodes(), @@ -201,7 +199,6 @@ export class NodeCommandHandlers implements CommandHandlers { updatePrepareTasks(argv, lease: Lease) { return [ this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateSingleNodeState({excludedStates: []}), this.tasks.identifyExistingNodes(), this.tasks.loadAdminKey(), @@ -246,7 +243,6 @@ export class NodeCommandHandlers implements CommandHandlers { upgradePrepareTasks(argv, lease: Lease) { return [ this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateSingleNodeState({excludedStates: []}), this.tasks.identifyExistingNodes(), this.tasks.loadAdminKey(), @@ -282,7 +278,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, prepareUpgradeConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.prepareUpgradeZip(), this.tasks.sendPrepareUpgradeTransaction(), ], @@ -304,7 +299,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, prepareUpgradeConfigBuilder.bind(this), null), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.prepareUpgradeZip(), this.tasks.sendFreezeUpgradeTransaction(), ], @@ -328,7 +322,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, downloadGeneratedFilesConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.identifyExistingNodes(), this.tasks.downloadNodeGeneratedFiles(), ], @@ -394,7 +387,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.loadContextData(argv, NodeCommandHandlers.UPDATE_CONTEXT_FILE, NodeHelper.updateLoadContextParser), ...this.updateSubmitTransactionsTasks(argv), ], @@ -416,7 +408,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease, false), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.loadContextData(argv, NodeCommandHandlers.UPDATE_CONTEXT_FILE, NodeHelper.updateLoadContextParser), ...this.updateExecuteTasks(argv), ], @@ -457,7 +448,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.loadContextData(argv, NodeCommandHandlers.UPGRADE_CONTEXT_FILE, NodeHelper.upgradeLoadContextParser), ...this.upgradeSubmitTransactionsTasks(argv), ], @@ -479,7 +469,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease, false), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.loadContextData(argv, NodeCommandHandlers.UPGRADE_CONTEXT_FILE, NodeHelper.upgradeLoadContextParser), ...this.upgradeExecuteTasks(argv), ], @@ -654,7 +643,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, addConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.loadContextData(argv, NodeCommandHandlers.ADD_CONTEXT_FILE, helpers.addLoadContextParser), ...this.addSubmitTransactionsTasks(argv), ], @@ -678,7 +666,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, addConfigBuilder.bind(this), lease, false), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.tasks.identifyExistingNodes(), this.tasks.loadContextData(argv, NodeCommandHandlers.ADD_CONTEXT_FILE, helpers.addLoadContextParser), ...this.addExecuteTasks(argv), @@ -698,11 +685,7 @@ export class NodeCommandHandlers implements CommandHandlers { async logs(argv: any) { argv = helpers.addFlagsToArgv(argv, NodeFlags.LOGS_FLAGS); const action = this.parent.commandActionBuilder( - [ - this.tasks.initialize(argv, logsConfigBuilder.bind(this), null), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), - this.tasks.getNodeLogsAndConfigs(), - ], + [this.tasks.initialize(argv, logsConfigBuilder.bind(this), null), this.tasks.getNodeLogsAndConfigs()], { concurrent: false, rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION, @@ -740,7 +723,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, refreshConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateAllNodeStates({ acceptedStates: [ConsensusNodeStates.STARTED, ConsensusNodeStates.SETUP, ConsensusNodeStates.INITIALIZED], }), @@ -794,7 +776,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, stopConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateAllNodeStates({ acceptedStates: [ConsensusNodeStates.STARTED, ConsensusNodeStates.SETUP], }), @@ -822,7 +803,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, startConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateAllNodeStates({acceptedStates: [ConsensusNodeStates.SETUP]}), this.tasks.identifyExistingNodes(), this.tasks.uploadStateFiles((ctx: any) => ctx.config.stateFile.length === 0), @@ -853,7 +833,6 @@ export class NodeCommandHandlers implements CommandHandlers { const action = this.parent.commandActionBuilder( [ this.tasks.initialize(argv, setupConfigBuilder.bind(this), lease), - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), this.validateAllNodeStates({ acceptedStates: [ConsensusNodeStates.INITIALIZED], }), diff --git a/src/commands/relay.ts b/src/commands/relay.ts index 5754984f4..3e3c55eb2 100644 --- a/src/commands/relay.ts +++ b/src/commands/relay.ts @@ -221,7 +221,6 @@ export class RelayCommand extends BaseCommand { return ListrLease.newAcquireLeaseTask(lease, task); }, }, - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), { title: 'Prepare chart values', task: async ctx => { @@ -350,7 +349,6 @@ export class RelayCommand extends BaseCommand { return ListrLease.newAcquireLeaseTask(lease, task); }, }, - RemoteConfigTasks.loadRemoteConfig.bind(this)(argv), { title: 'Destroy JSON RPC Relay', task: async ctx => { diff --git a/src/core/config/remote/remote_config_manager.ts b/src/core/config/remote/remote_config_manager.ts index d2cd892ee..1d8a2aa92 100644 --- a/src/core/config/remote/remote_config_manager.ts +++ b/src/core/config/remote/remote_config_manager.ts @@ -184,39 +184,50 @@ export class RemoteConfigManager { /* ---------- Listr Task Builders ---------- */ /** - * Builds a task for loading the remote configuration, intended for use with Listr task management. + * Performs the loading of the remote configuration. * Checks if the configuration is already loaded, otherwise loads and adds the command to history. * * @param argv - arguments containing command input for historical reference. - * @returns a Listr task which loads the remote configuration. */ - public buildLoadTask(argv: {_: string[]}): SoloListrTask { + public async loadAndValidate(argv: {_: string[]}) { const self = this; + try { + self.setDefaultNamespaceIfNotSet(); + self.setDefaultContextIfNotSet(); + } catch (e) { + self.logger.showUser(chalk.red(e.message)); + return; + } - return { - title: 'Load remote config', - task: async (_, task): Promise => { - try { - self.setDefaultNamespaceIfNotSet(); - self.setDefaultContextIfNotSet(); - } catch { - return; // TODO - } + if (!(await self.load())) { + self.logger.showUser(chalk.red('remote config not found')); + + // TODO see if this should be disabled to make it an optional feature + return; + // throw new SoloError('Failed to load remote config') + } - if (!(await self.load())) { - task.title = `${task.title} - ${chalk.red('remote config not found')}`; + await RemoteConfigValidator.validateComponents(self.remoteConfig.components, self.k8); - // TODO see if this should be disabled to make it an optional feature - return; - // throw new SoloError('Failed to load remote config') - } + const currentCommand = argv._.join(' '); + self.remoteConfig!.addCommandToHistory(currentCommand); - await RemoteConfigValidator.validateComponents(self.remoteConfig.components, self.k8); + await self.save(); + } - const currentCommand = argv._.join(' '); - self.remoteConfig!.addCommandToHistory(currentCommand); + /** + * Builds a listr task for loading the remote configuration. + * + * @param argv - arguments containing command input for historical reference. + * @returns a Listr task which loads the remote configuration. + */ + public buildLoadTask(argv: {_: string[]}): SoloListrTask { + const self = this; - await self.save(); + return { + title: 'Load remote config', + task: async (_, task): Promise => { + await self.loadAndValidate(argv); }, }; } diff --git a/src/index.ts b/src/index.ts index 896855015..bd4f0698d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -132,6 +132,23 @@ export function main(argv: any) { return argv; }; + const loadRemoteConfig = async (argv: any, yargs: any): Promise => { + const command = argv._[0]; + const subCommand = argv._[1]; + const skip = + command === 'init' || + (command === 'node' && subCommand === 'keys') || + (command === 'cluster' && subCommand === 'connect') || + (command === 'cluster' && subCommand === 'info') || + (command === 'cluster' && subCommand === 'list') || + (command === 'deployment' && subCommand === 'create'); + if (!skip) { + await remoteConfigManager.loadAndValidate(argv); + } + + return argv; + }; + return ( yargs(hideBin(argv)) .scriptName('') @@ -146,7 +163,7 @@ export function main(argv: any) { .wrap(120) .demand(1, 'Select a command') // @ts-ignore - .middleware(processArguments, false) // applyBeforeValidate = false as otherwise middleware is called twice + .middleware([processArguments, loadRemoteConfig], false) // applyBeforeValidate = false as otherwise middleware is called twice .parse() ); } catch (e: Error | any) {