From dec37b540c06e3ae683a5da2569e97aa67d3a6ba Mon Sep 17 00:00:00 2001 From: instamenta Date: Tue, 21 Jan 2025 11:58:30 +0200 Subject: [PATCH 01/14] added new data wrapper for the common flags and the common methods for it Signed-off-by: instamenta --- .../remote/common_flags_data_wrapper.ts | 91 +++++++++++++++++++ .../config/remote/components_data_wrapper.ts | 23 ++--- .../remote/remote_config_data_wrapper.ts | 29 +++--- .../config/remote/remote_config_manager.ts | 10 +- src/core/config/remote/types.ts | 30 ++++++ .../remote_config_data_wrapper.test.ts | 3 + 6 files changed, 150 insertions(+), 36 deletions(-) create mode 100644 src/core/config/remote/common_flags_data_wrapper.ts diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts new file mode 100644 index 000000000..cacb7eed9 --- /dev/null +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -0,0 +1,91 @@ +/** + * 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 {Flags as flags} from '../../../commands/flags.js'; +import type {ToObject} from '../../../types/index.js'; +import type {RemoteConfigCommonFlagsStruct} from './types.js'; +import type {ConfigManager} from '../../config_manager.js'; +import type {CommandFlag} from '../../../types/flag_types.js'; + +export class CommonFlagsDataWrapper implements ToObject { + private static readonly COMMON_FLAGS: CommandFlag[] = [ + flags.nodeAliasesUnparsed, + flags.releaseTag, + flags.relayReleaseTag, + flags.hederaExplorerVersion, + flags.mirrorNodeVersion, + ]; + + private readonly flags: RemoteConfigCommonFlagsStruct; + + constructor(flags: RemoteConfigCommonFlagsStruct) { + this.flags = flags; + } + + /** + * Updates the flags or populates them inside the remote config + */ + public handleFlags(configManager: ConfigManager): void { + CommonFlagsDataWrapper.COMMON_FLAGS.forEach(flag => { + this.updateFlag(configManager, flag); + }); + } + + private updateFlag(configManager: ConfigManager, flag: CommandFlag): void { + const detectFlagMismatch = () => { + const oldValue = this.flags[flag.constName] as string; + const newValue = configManager.getFlag(flag); + + // if the old value is not present, override it with the new one + if (!oldValue) { + this.flags[flag.constName] = newValue; + } + + // if its present but there is a mismatch warn user + else if (oldValue && oldValue !== newValue) { + // TODO WARN USER AND OVERRIDE WITH NEW VALUE + } + }; + + // if the flag is set, inspect the value + if (configManager.hasFlag(flag)) { + detectFlagMismatch(); + } + + // if the value is not set and exists, override it + else if (this.flags[flag.constName]) { + configManager.setFlag(flag, this.flags[flag.constName]); + } + } + + public static initializeEmpty() { + return new CommonFlagsDataWrapper({}); + } + + public static fromObject(data: RemoteConfigCommonFlagsStruct): CommonFlagsDataWrapper { + return new CommonFlagsDataWrapper(data); + } + + public toObject(): RemoteConfigCommonFlagsStruct { + return { + nodeAliasesUnparsed: this.flags.nodeAliasesUnparsed, + releaseTag: this.flags.releaseTag, + relayReleaseTag: this.flags.relayReleaseTag, + hederaExplorerVersion: this.flags.hederaExplorerVersion, + mirrorNodeVersion: this.flags.mirrorNodeVersion, + }; + } +} diff --git a/src/core/config/remote/components_data_wrapper.ts b/src/core/config/remote/components_data_wrapper.ts index 117673fdd..aaadb949a 100644 --- a/src/core/config/remote/components_data_wrapper.ts +++ b/src/core/config/remote/components_data_wrapper.ts @@ -23,25 +23,14 @@ import {MirrorNodeComponent} from './components/mirror_node_component.js'; import {EnvoyProxyComponent} from './components/envoy_proxy_component.js'; import {ConsensusNodeComponent} from './components/consensus_node_component.js'; import {MirrorNodeExplorerComponent} from './components/mirror_node_explorer_component.js'; -import { - type Component, - type ComponentsDataStructure, - type IConsensusNodeComponent, - type IRelayComponent, - type ComponentName, - type Cluster, - type Namespace, +import type { + Component, + ComponentsDataStructure, + IConsensusNodeComponent, + IRelayComponent, + ComponentName, } from './types.js'; import type {ToObject, Validate} from '../../../types/index.js'; -import type {RemoteConfigMetadata} from './metadata.js'; - -export interface RemoteConfigData { - metadata: RemoteConfigMetadata; - clusters: Record; - components: ComponentsDataWrapper; - lastExecutedCommand: string; - commandHistory: string[]; -} /** * Represent the components in the remote config and handles: diff --git a/src/core/config/remote/remote_config_data_wrapper.ts b/src/core/config/remote/remote_config_data_wrapper.ts index 8c014c835..f2bcc2219 100644 --- a/src/core/config/remote/remote_config_data_wrapper.ts +++ b/src/core/config/remote/remote_config_data_wrapper.ts @@ -16,21 +16,13 @@ */ import {SoloError} from '../../errors.js'; import * as yaml from 'yaml'; -import {RemoteConfigMetadata, type RemoteConfigMetadataStructure} from './metadata.js'; -import {ComponentsDataWrapper, type RemoteConfigData} from './components_data_wrapper.js'; +import {RemoteConfigMetadata} from './metadata.js'; +import {ComponentsDataWrapper} from './components_data_wrapper.js'; import * as constants from '../../constants.js'; -import {type Cluster, type Version, type Namespace, type ComponentsDataStructure} from './types.js'; +import type {Cluster, Version, Namespace, RemoteConfigDataStructure, RemoteConfigData} from './types.js'; import type * as k8s from '@kubernetes/client-node'; import type {ToObject, Validate} from '../../../types/index.js'; - -export interface RemoteConfigDataStructure { - metadata: RemoteConfigMetadataStructure; - version: Version; - clusters: Record; - components: ComponentsDataStructure; - commandHistory: string[]; - lastExecutedCommand: string; -} +import type {CommonFlagsDataWrapper} from './common_flags_data_wrapper.js'; export class RemoteConfigDataWrapper implements Validate, ToObject { private readonly _version: Version = '1.0.0'; @@ -39,6 +31,7 @@ export class RemoteConfigDataWrapper implements Validate, ToObject => { + task: async (): Promise => { await self.loadAndValidate(argv); }, }; diff --git a/src/core/config/remote/types.ts b/src/core/config/remote/types.ts index f5f7228d6..79b395d00 100644 --- a/src/core/config/remote/types.ts +++ b/src/core/config/remote/types.ts @@ -16,6 +16,9 @@ */ import type {NodeAliases} from '../../../types/aliases.js'; import type {ComponentType, ConsensusNodeStates} from './enumerations.js'; +import type {RemoteConfigMetadata, RemoteConfigMetadataStructure} from './metadata.js'; +import type {ComponentsDataWrapper} from './components_data_wrapper.js'; +import {CommonFlagsDataWrapper} from './common_flags_data_wrapper.js'; export type EmailAddress = `${string}@${string}.${string}`; export type Version = string; @@ -45,3 +48,30 @@ export interface IConsensusNodeComponent extends Component { } export type ComponentsDataStructure = Record>; + +export interface RemoteConfigData { + metadata: RemoteConfigMetadata; + clusters: Record; + components: ComponentsDataWrapper; + lastExecutedCommand: string; + commandHistory: string[]; + flags: CommonFlagsDataWrapper; +} + +export type RemoteConfigCommonFlagsStruct = { + nodeAliasesUnparsed?: string; + releaseTag?: string; + relayReleaseTag?: string; + hederaExplorerVersion?: string; + mirrorNodeVersion?: string; +}; + +export interface RemoteConfigDataStructure { + metadata: RemoteConfigMetadataStructure; + version: Version; + clusters: Record; + components: ComponentsDataStructure; + commandHistory: string[]; + lastExecutedCommand: string; + flags: RemoteConfigCommonFlagsStruct; +} diff --git a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts index e1f783295..c1a83e096 100644 --- a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts +++ b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts @@ -23,6 +23,7 @@ import {createMetadata} from './metadata.test.js'; import {createComponentsDataWrapper} from './components_data_wrapper.test.js'; import {SoloError} from '../../../../src/core/errors.js'; import * as constants from '../../../../src/core/constants.js'; +import {CommonFlagsDataWrapper} from '../../../../src/core/config/remote/common_flags_data_wrapper.js'; function createRemoteConfigDataWrapper() { const {metadata} = createMetadata(); @@ -34,6 +35,7 @@ function createRemoteConfigDataWrapper() { const components = componentsDataWrapper; const lastExecutedCommand = 'lastExecutedCommand'; const commandHistory = []; + const flags = CommonFlagsDataWrapper.initializeEmpty(); const dataWrapper = new RemoteConfigDataWrapper({ metadata, @@ -41,6 +43,7 @@ function createRemoteConfigDataWrapper() { components, lastExecutedCommand, commandHistory, + flags, }); return { From 072f142c52890e9abeb6c1a29c384efdf72f4dc4 Mon Sep 17 00:00:00 2001 From: instamenta Date: Tue, 21 Jan 2025 14:53:19 +0200 Subject: [PATCH 02/14] add to middleware, pass the configManager and the argv down to the remote config common flags data wrapper and fix failing tests Signed-off-by: instamenta --- src/commands/mirror_node.ts | 1 - .../remote/common_flags_data_wrapper.ts | 43 +++++++++++-------- .../remote/remote_config_data_wrapper.ts | 7 +-- .../config/remote/remote_config_manager.ts | 18 +++++--- src/core/config/remote/remote_config_tasks.ts | 6 ++- src/core/config/remote/types.ts | 6 ++- .../remote_config_data_wrapper.test.ts | 12 ++++-- 7 files changed, 59 insertions(+), 34 deletions(-) diff --git a/src/commands/mirror_node.ts b/src/commands/mirror_node.ts index f48027ccf..4ad5dc717 100644 --- a/src/commands/mirror_node.ts +++ b/src/commands/mirror_node.ts @@ -23,7 +23,6 @@ import {type ProfileManager} from '../core/profile_manager.js'; import {BaseCommand} from './base.js'; import {Flags as flags} from './flags.js'; import {getEnvValue} from '../core/helpers.js'; -import {RemoteConfigTasks} from '../core/config/remote/remote_config_tasks.js'; import {type CommandBuilder, type PodName} from '../types/aliases.js'; import {type Opts} from '../types/command_types.js'; import {ListrLease} from '../core/lease/listr_lease.js'; diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts index cacb7eed9..f9e3f61f9 100644 --- a/src/core/config/remote/common_flags_data_wrapper.ts +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -19,35 +19,39 @@ import type {ToObject} from '../../../types/index.js'; import type {RemoteConfigCommonFlagsStruct} from './types.js'; import type {ConfigManager} from '../../config_manager.js'; import type {CommandFlag} from '../../../types/flag_types.js'; +import type {AnyObject} from '../../../types/aliases.js'; export class CommonFlagsDataWrapper implements ToObject { private static readonly COMMON_FLAGS: CommandFlag[] = [ - flags.nodeAliasesUnparsed, flags.releaseTag, + flags.chartDirectory, flags.relayReleaseTag, - flags.hederaExplorerVersion, + flags.soloChartVersion, flags.mirrorNodeVersion, + flags.nodeAliasesUnparsed, + flags.hederaExplorerVersion, ]; - private readonly flags: RemoteConfigCommonFlagsStruct; - - constructor(flags: RemoteConfigCommonFlagsStruct) { - this.flags = flags; - } + private constructor( + private readonly configManager: ConfigManager, + private readonly flags: RemoteConfigCommonFlagsStruct, + ) {} /** * Updates the flags or populates them inside the remote config */ - public handleFlags(configManager: ConfigManager): void { + public handleFlags(argv: AnyObject): void { + this.configManager.update(argv); + CommonFlagsDataWrapper.COMMON_FLAGS.forEach(flag => { - this.updateFlag(configManager, flag); + this.updateFlag(flag); }); } - private updateFlag(configManager: ConfigManager, flag: CommandFlag): void { + private updateFlag(flag: CommandFlag): void { const detectFlagMismatch = () => { const oldValue = this.flags[flag.constName] as string; - const newValue = configManager.getFlag(flag); + const newValue = this.configManager.getFlag(flag); // if the old value is not present, override it with the new one if (!oldValue) { @@ -56,27 +60,30 @@ export class CommonFlagsDataWrapper implements ToObject { private readonly _version: Version = '1.0.0'; @@ -117,7 +118,7 @@ export class RemoteConfigDataWrapper implements Validate, ToObject { + private async create(argv: AnyObject): Promise { const clusters: Record = {}; Object.entries(this.localConfig.deployments).forEach( @@ -121,7 +122,7 @@ export class RemoteConfigManager { commandHistory: ['deployment create'], lastExecutedCommand: 'deployment create', components: ComponentsDataWrapper.initializeEmpty(), - flags: CommonFlagsDataWrapper.initializeEmpty(), + flags: CommonFlagsDataWrapper.initializeEmpty(this.configManager, argv), }); await this.createConfigMap(); @@ -149,7 +150,7 @@ export class RemoteConfigManager { const configMap = await this.getConfigMap(); if (!configMap) return false; - this.remoteConfig = RemoteConfigDataWrapper.fromConfigmap(configMap); + this.remoteConfig = RemoteConfigDataWrapper.fromConfigmap(this.configManager, configMap); return true; } @@ -214,6 +215,8 @@ export class RemoteConfigManager { const currentCommand = argv._.join(' '); self.remoteConfig!.addCommandToHistory(currentCommand); + self.remoteConfig.flags.handleFlags(argv); + await self.save(); } @@ -240,7 +243,12 @@ export class RemoteConfigManager { * * @returns a Listr task which creates the remote configuration. */ - public buildCreateTask(cluster: Cluster, context: Context, namespace: Namespace): SoloListrTask { + public buildCreateTask( + cluster: Cluster, + context: Context, + namespace: Namespace, + argv: AnyObject, + ): SoloListrTask { const self = this; return { @@ -263,7 +271,7 @@ export class RemoteConfigManager { throw new SoloError('Remote config already exists'); } - await self.create(); + await self.create(argv); }, }; } diff --git a/src/core/config/remote/remote_config_tasks.ts b/src/core/config/remote/remote_config_tasks.ts index 03c381fb1..982494b93 100644 --- a/src/core/config/remote/remote_config_tasks.ts +++ b/src/core/config/remote/remote_config_tasks.ts @@ -16,7 +16,8 @@ */ import type {ListrTask} from 'listr2'; import type {BaseCommand} from '../../../commands/base.js'; -import {type Cluster, type Context, type Namespace} from './types.js'; +import type {Cluster, Context, Namespace} from './types.js'; +import type {AnyObject} from '../../../types/aliases.js'; /** * Static class that handles all tasks related to remote config used by other commands. @@ -39,7 +40,8 @@ export class RemoteConfigTasks { cluster: Cluster, context: Context, namespace: Namespace, + argv: AnyObject, ): ListrTask { - return this.remoteConfigManager.buildCreateTask(cluster, context, namespace); + return this.remoteConfigManager.buildCreateTask(cluster, context, namespace, argv); } } diff --git a/src/core/config/remote/types.ts b/src/core/config/remote/types.ts index 79b395d00..c94b7ec9a 100644 --- a/src/core/config/remote/types.ts +++ b/src/core/config/remote/types.ts @@ -59,11 +59,13 @@ export interface RemoteConfigData { } export type RemoteConfigCommonFlagsStruct = { - nodeAliasesUnparsed?: string; releaseTag?: string; + chartDirectory?: string; relayReleaseTag?: string; - hederaExplorerVersion?: string; + soloChartVersion?: string; mirrorNodeVersion?: string; + nodeAliasesUnparsed?: string; + hederaExplorerVersion?: string; }; export interface RemoteConfigDataStructure { diff --git a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts index c1a83e096..27b138fa7 100644 --- a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts +++ b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts @@ -25,6 +25,13 @@ import {SoloError} from '../../../../src/core/errors.js'; import * as constants from '../../../../src/core/constants.js'; import {CommonFlagsDataWrapper} from '../../../../src/core/config/remote/common_flags_data_wrapper.js'; +const configManagerMock = { + update: (...args: any) => true, + getFlag: (...args: any) => true, + hasFlag: (...args: any) => true, + setFlag: (...args: any) => true, +}; + function createRemoteConfigDataWrapper() { const {metadata} = createMetadata(); const { @@ -35,7 +42,7 @@ function createRemoteConfigDataWrapper() { const components = componentsDataWrapper; const lastExecutedCommand = 'lastExecutedCommand'; const commandHistory = []; - const flags = CommonFlagsDataWrapper.initializeEmpty(); + const flags = CommonFlagsDataWrapper.initializeEmpty(configManagerMock as any, {}); // TODO MOCK const dataWrapper = new RemoteConfigDataWrapper({ metadata, @@ -84,8 +91,7 @@ describe('RemoteConfigDataWrapper', () => { lastExecutedCommand: dataWrapperObject.lastExecutedCommand, }); - // @ts-ignore - RemoteConfigDataWrapper.fromConfigmap({data: {'remote-config-data': yamlData}}); + RemoteConfigDataWrapper.fromConfigmap(configManagerMock as any, {data: {'remote-config-data': yamlData}} as any); }); it('should fail if invalid data is passed to setters', () => { From 7d03d77663f894fe36de0dbb5f57f000c6ae8e70 Mon Sep 17 00:00:00 2001 From: instamenta Date: Tue, 21 Jan 2025 16:00:20 +0200 Subject: [PATCH 03/14] removed some ts-ignore tags, lint fix and added .madgerc file to ignore type imports because they are impossible to fix in the context of the remote config Signed-off-by: instamenta --- .madgerc | 7 ++++ .../config/remote/components_data_wrapper.ts | 1 - .../config/remote/remote_config_manager.ts | 2 +- src/core/config/remote/types.ts | 2 +- .../remote_config_data_wrapper.test.ts | 35 +++++++++++++------ 5 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 .madgerc diff --git a/.madgerc b/.madgerc new file mode 100644 index 000000000..4a7c7253b --- /dev/null +++ b/.madgerc @@ -0,0 +1,7 @@ +{ + "detectiveOptions": { + "ts": { + "skipTypeImports": true + } + } +} \ No newline at end of file diff --git a/src/core/config/remote/components_data_wrapper.ts b/src/core/config/remote/components_data_wrapper.ts index aaadb949a..31d40b2aa 100644 --- a/src/core/config/remote/components_data_wrapper.ts +++ b/src/core/config/remote/components_data_wrapper.ts @@ -155,7 +155,6 @@ export class ComponentsDataWrapper implements Validate, ToObject { it('should fail if invalid data is passed to setters', () => { const {dataWrapper} = createRemoteConfigDataWrapper(); - // @ts-ignore - expect(() => (dataWrapper.commandHistory = '')).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.lastExecutedCommand = '')).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.lastExecutedCommand = 1)).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.clusters = 1)).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.clusters = '')).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.components = 1)).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.components = '')).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.metadata = null)).to.throw(SoloError); // @ts-ignore - expect(() => (dataWrapper.metadata = {})).to.throw(SoloError); // @ts-ignore + // @ts-expect-error TS2322: Type string is not assignable to type string[] + expect(() => (dataWrapper.commandHistory = '')).to.throw(SoloError); + + // @ts-expect-error TS2341 Property lastExecutedCommand is private and only accessible within class RemoteConfigDataWrapper + expect(() => (dataWrapper.lastExecutedCommand = '')).to.throw(SoloError); + + // @ts-expect-error TS2341 Property lastExecutedCommand is private and only accessible within class RemoteConfigDataWrapper + expect(() => (dataWrapper.lastExecutedCommand = 1)).to.throw(SoloError); + + // @ts-expect-error TS2322 Type number is not assignable to type Record + expect(() => (dataWrapper.clusters = 1)).to.throw(SoloError); + + // @ts-expect-error TS2322 Type string is not assignable to type Record + expect(() => (dataWrapper.clusters = '')).to.throw(SoloError); + + // @ts-expect-error TS2322 Type number is not assignable to type ComponentsDataWrapper + expect(() => (dataWrapper.components = 1)).to.throw(SoloError); + + // @ts-expect-error TS2322 Type string is not assignable to type ComponentsDataWrapper + expect(() => (dataWrapper.components = '')).to.throw(SoloError); + + expect(() => (dataWrapper.metadata = null)).to.throw(SoloError); + + // @ts-expect-error 2740: Type {} is missing the following properties from type RemoteConfigMetadata + expect(() => (dataWrapper.metadata = {})).to.throw(SoloError); expect(() => (dataWrapper.clusters = {null: null})).to.throw(SoloError); expect(() => (dataWrapper.clusters = {namespace: null})).to.throw(SoloError); From 9722eeee8394478e12fac647ed5df773b6df1e2f Mon Sep 17 00:00:00 2001 From: Jeromy Cannon Date: Tue, 21 Jan 2025 17:47:35 +0000 Subject: [PATCH 04/14] removed circular dependencies and madgerc override Signed-off-by: Jeromy Cannon --- .madgerc | 7 ----- src/core/config/remote/metadata.ts | 9 +----- src/core/config/remote/remote_config_data.ts | 29 +++++++++++++++++++ .../remote/remote_config_data_wrapper.ts | 3 +- src/core/config/remote/types.ts | 19 +++++------- 5 files changed, 39 insertions(+), 28 deletions(-) delete mode 100644 .madgerc create mode 100644 src/core/config/remote/remote_config_data.ts diff --git a/.madgerc b/.madgerc deleted file mode 100644 index 4a7c7253b..000000000 --- a/.madgerc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "detectiveOptions": { - "ts": { - "skipTypeImports": true - } - } -} \ No newline at end of file diff --git a/src/core/config/remote/metadata.ts b/src/core/config/remote/metadata.ts index 577df08a7..a6680babb 100644 --- a/src/core/config/remote/metadata.ts +++ b/src/core/config/remote/metadata.ts @@ -17,16 +17,9 @@ import {Migration} from './migration.js'; import {SoloError} from '../../errors.js'; import * as k8s from '@kubernetes/client-node'; -import type {EmailAddress, Namespace, Version} from './types.js'; +import type {EmailAddress, Namespace, RemoteConfigMetadataStructure, Version} from './types.js'; import type {Optional, ToObject, Validate} from '../../../types/index.js'; -export interface RemoteConfigMetadataStructure { - name: Namespace; - lastUpdatedAt: Date; - lastUpdateBy: EmailAddress; - migration?: Migration; -} - /** * Represent the remote config metadata object and handles: * - Validation diff --git a/src/core/config/remote/remote_config_data.ts b/src/core/config/remote/remote_config_data.ts new file mode 100644 index 000000000..3e206eb00 --- /dev/null +++ b/src/core/config/remote/remote_config_data.ts @@ -0,0 +1,29 @@ +/** + * 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 type {RemoteConfigMetadata} from './metadata.js'; +import type {ComponentsDataWrapper} from './components_data_wrapper.js'; +import type {CommonFlagsDataWrapper} from './common_flags_data_wrapper.js'; +import {type Cluster, type Namespace} from './types.js'; + +export interface RemoteConfigData { + metadata: RemoteConfigMetadata; + clusters: Record; + components: ComponentsDataWrapper; + lastExecutedCommand: string; + commandHistory: string[]; + flags: CommonFlagsDataWrapper; +} diff --git a/src/core/config/remote/remote_config_data_wrapper.ts b/src/core/config/remote/remote_config_data_wrapper.ts index 348fc5718..d31adf9fd 100644 --- a/src/core/config/remote/remote_config_data_wrapper.ts +++ b/src/core/config/remote/remote_config_data_wrapper.ts @@ -20,10 +20,11 @@ import {RemoteConfigMetadata} from './metadata.js'; import {ComponentsDataWrapper} from './components_data_wrapper.js'; import * as constants from '../../constants.js'; import {CommonFlagsDataWrapper} from './common_flags_data_wrapper.js'; -import type {Cluster, Version, Namespace, RemoteConfigDataStructure, RemoteConfigData} from './types.js'; +import type {Cluster, Version, Namespace, RemoteConfigDataStructure} from './types.js'; import type * as k8s from '@kubernetes/client-node'; import type {ToObject, Validate} from '../../../types/index.js'; import type {ConfigManager} from '../../config_manager.js'; +import {type RemoteConfigData} from './remote_config_data.js'; export class RemoteConfigDataWrapper implements Validate, ToObject { private readonly _version: Version = '1.0.0'; diff --git a/src/core/config/remote/types.ts b/src/core/config/remote/types.ts index 4b995dfe8..52c077d04 100644 --- a/src/core/config/remote/types.ts +++ b/src/core/config/remote/types.ts @@ -16,9 +16,6 @@ */ import type {NodeAliases} from '../../../types/aliases.js'; import type {ComponentType, ConsensusNodeStates} from './enumerations.js'; -import type {RemoteConfigMetadata, RemoteConfigMetadataStructure} from './metadata.js'; -import type {ComponentsDataWrapper} from './components_data_wrapper.js'; -import {type CommonFlagsDataWrapper} from './common_flags_data_wrapper.js'; export type EmailAddress = `${string}@${string}.${string}`; export type Version = string; @@ -49,15 +46,6 @@ export interface IConsensusNodeComponent extends Component { export type ComponentsDataStructure = Record>; -export interface RemoteConfigData { - metadata: RemoteConfigMetadata; - clusters: Record; - components: ComponentsDataWrapper; - lastExecutedCommand: string; - commandHistory: string[]; - flags: CommonFlagsDataWrapper; -} - export type RemoteConfigCommonFlagsStruct = { releaseTag?: string; chartDirectory?: string; @@ -77,3 +65,10 @@ export interface RemoteConfigDataStructure { lastExecutedCommand: string; flags: RemoteConfigCommonFlagsStruct; } + +export interface RemoteConfigMetadataStructure { + name: Namespace; + lastUpdatedAt: Date; + lastUpdateBy: EmailAddress; + migration?: IMigration; +} From c35494150a3673e64cababc87055b6523e18bf31 Mon Sep 17 00:00:00 2001 From: instamenta Date: Wed, 22 Jan 2025 13:39:46 +0200 Subject: [PATCH 05/14] working on prompting the user and overriding the configManager's values when passed to command, since they are overriden on configManager.update which is called at the beggining of all commands Signed-off-by: instamenta --- package-lock.json | 204 +----------------- package.json | 1 + src/commands/account.ts | 4 - src/commands/cluster/configs.ts | 1 - src/commands/deployment.ts | 1 - src/commands/init.ts | 1 - src/commands/mirror_node.ts | 3 - src/commands/network.ts | 2 - src/commands/node/tasks.ts | 2 - src/commands/relay.ts | 3 - .../remote/common_flags_data_wrapper.ts | 46 ++-- .../config/remote/remote_config_manager.ts | 4 +- src/index.ts | 1 + .../remote_config_data_wrapper.test.ts | 18 +- 14 files changed, 48 insertions(+), 243 deletions(-) diff --git a/package-lock.json b/package-lock.json index 004a996bd..11b84349a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ ], "dependencies": { "@hashgraph/sdk": "^2.56.0", + "@inquirer/prompts": "^7.2.3", "@kubernetes/client-node": "^0.22.3", "@listr2/prompt-adapter-enquirer": "^2.0.12", "@peculiar/x509": "^1.12.3", @@ -1542,6 +1543,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/@inquirer/prompts/-/prompts-7.2.3.tgz", "integrity": "sha512-hzfnm3uOoDySDXfDNOm9usOuYIaQvTgKp/13l1uJoe6UNY+Zpcn2RYt0jXz3yA+yemGHvDOxVzqWl3S5sQq53Q==", + "license": "MIT", "dependencies": { "@inquirer/checkbox": "^4.0.6", "@inquirer/confirm": "^5.1.3", @@ -2894,30 +2896,6 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils": { - "version": "8.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.20.0.tgz", - "integrity": "sha512-dq70RUw6UK9ei7vxc4KQtBRk7qkHZv447OUZ6RPQMQl71I3NZxQJX/f32Smr+iqWrB02pHKn2yAdHBb0KNrRMA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.20.0", - "@typescript-eslint/types": "8.20.0", - "@typescript-eslint/typescript-estree": "8.20.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0", - "typescript": ">=4.8.4 <5.8.0" - } - }, "node_modules/@typescript-eslint/eslint-plugin/node_modules/ts-api-utils": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.0.0.tgz", @@ -2998,30 +2976,6 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/utils": { - "version": "8.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.20.0.tgz", - "integrity": "sha512-dq70RUw6UK9ei7vxc4KQtBRk7qkHZv447OUZ6RPQMQl71I3NZxQJX/f32Smr+iqWrB02pHKn2yAdHBb0KNrRMA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.20.0", - "@typescript-eslint/types": "8.20.0", - "@typescript-eslint/typescript-estree": "8.20.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0", - "typescript": ">=4.8.4 <5.8.0" - } - }, "node_modules/@typescript-eslint/type-utils/node_modules/ts-api-utils": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.0.0.tgz", @@ -3139,135 +3093,6 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/scope-manager": { - "version": "8.21.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.21.0.tgz", - "integrity": "sha512-G3IBKz0/0IPfdeGRMbp+4rbjfSSdnGkXsM/pFZA8zM9t9klXDnB/YnKOBQ0GoPmoROa4bCq2NeHgJa5ydsQ4mA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.21.0", - "@typescript-eslint/visitor-keys": "8.21.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/types": { - "version": "8.21.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.21.0.tgz", - "integrity": "sha512-PAL6LUuQwotLW2a8VsySDBwYMm129vFm4tMVlylzdoTybTHaAi0oBp7Ac6LhSrHHOdLM3efH+nAR6hAWoMF89A==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree": { - "version": "8.21.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.21.0.tgz", - "integrity": "sha512-x+aeKh/AjAArSauz0GiQZsjT8ciadNMHdkUSwBB9Z6PrKc/4knM4g3UfHml6oDJmKC88a6//cdxnO/+P2LkMcg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.21.0", - "@typescript-eslint/visitor-keys": "8.21.0", - "debug": "^4.3.4", - "fast-glob": "^3.3.2", - "is-glob": "^4.0.3", - "minimatch": "^9.0.4", - "semver": "^7.6.0", - "ts-api-utils": "^2.0.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "typescript": ">=4.8.4 <5.8.0" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/visitor-keys": { - "version": "8.21.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.21.0.tgz", - "integrity": "sha512-BkLMNpdV6prozk8LlyK/SOoWLmUFi+ZD+pcqti9ILCbVvHGk1ui1g4jJOc2WDLaeExz2qWwojxlPce5PljcT3w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.21.0", - "eslint-visitor-keys": "^4.2.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/eslint-visitor-keys": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", - "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/ts-api-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.0.0.tgz", - "integrity": "sha512-xCt/TOAc+EOHS1XPnijD3/yzpH6qg2xppZO1YDqGoVsNXfQfzHpOdNuXwrwOU8u4ITXJyDCTyt8w5g1sZv9ynQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18.12" - }, - "peerDependencies": { - "typescript": ">=4.8.4" - } - }, "node_modules/@typescript-eslint/visitor-keys": { "version": "8.21.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.21.0.tgz", @@ -5143,6 +4968,7 @@ "version": "2.4.1", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.4.1.tgz", "integrity": "sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ==", + "license": "MIT", "dependencies": { "ansi-colors": "^4.1.1", "strip-ansi": "^6.0.1" @@ -12606,30 +12432,6 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/utils": { - "version": "8.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.20.0.tgz", - "integrity": "sha512-dq70RUw6UK9ei7vxc4KQtBRk7qkHZv447OUZ6RPQMQl71I3NZxQJX/f32Smr+iqWrB02pHKn2yAdHBb0KNrRMA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.20.0", - "@typescript-eslint/types": "8.20.0", - "@typescript-eslint/typescript-estree": "8.20.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0", - "typescript": ">=4.8.4 <5.8.0" - } - }, "node_modules/uc.micro": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", diff --git a/package.json b/package.json index 83e29b2d7..102862683 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "license": "Apache2.0", "dependencies": { "@hashgraph/sdk": "^2.56.0", + "@inquirer/prompts": "^7.2.3", "@kubernetes/client-node": "^0.22.3", "@listr2/prompt-adapter-enquirer": "^2.0.12", "@peculiar/x509": "^1.12.3", diff --git a/src/commands/account.ts b/src/commands/account.ts index f8e39fda2..7aff66b03 100644 --- a/src/commands/account.ts +++ b/src/commands/account.ts @@ -177,7 +177,6 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { - self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.namespace]); const config = { @@ -330,7 +329,6 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { - self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.namespace]); const config = { @@ -413,7 +411,6 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { - self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.accountId, flags.namespace]); const config = { @@ -496,7 +493,6 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { - self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.accountId, flags.namespace]); const config = { diff --git a/src/commands/cluster/configs.ts b/src/commands/cluster/configs.ts index d1f9ece95..e1efcedeb 100644 --- a/src/commands/cluster/configs.ts +++ b/src/commands/cluster/configs.ts @@ -38,7 +38,6 @@ export const connectConfigBuilder = async function (argv, ctx, task) { export const setupConfigBuilder = async function (argv, ctx, task) { const parent = this.parent; const configManager = parent.getConfigManager(); - configManager.update(argv); flags.disablePrompts([flags.chartDirectory]); await configManager.executePrompt(task, [ diff --git a/src/commands/deployment.ts b/src/commands/deployment.ts index 8ace56ebc..a164df29d 100644 --- a/src/commands/deployment.ts +++ b/src/commands/deployment.ts @@ -68,7 +68,6 @@ export class DeploymentCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { - self.configManager.update(argv); self.logger.debug('Updated config with argv', {config: self.configManager.config}); await self.configManager.executePrompt(task, [ diff --git a/src/commands/init.ts b/src/commands/init.ts index 3ad318c0c..184e683d5 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -45,7 +45,6 @@ export class InitCommand extends BaseCommand { { title: 'Setup home directory and cache', task: ctx => { - self.configManager.update(argv); ctx.dirs = this.setupHomeDirectory(); }, }, diff --git a/src/commands/mirror_node.ts b/src/commands/mirror_node.ts index 3cae3e509..07d0aca4c 100644 --- a/src/commands/mirror_node.ts +++ b/src/commands/mirror_node.ts @@ -225,8 +225,6 @@ export class MirrorNodeCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { - self.configManager.update(argv); - // disable the prompts that we don't want to prompt the user for flags.disablePrompts([ flags.deployHederaExplorer, @@ -600,7 +598,6 @@ export class MirrorNodeCommand extends BaseCommand { } } - self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.namespace]); // @ts-ignore diff --git a/src/commands/network.ts b/src/commands/network.ts index 2c20699f5..aa825fa50 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -356,7 +356,6 @@ export class NetworkCommand extends BaseCommand { } async prepareConfig(task: any, argv: any) { - this.configManager.update(argv); this.logger.debug('Updated config with argv', {config: this.configManager.config}); // disable the prompts that we don't want to prompt the user for @@ -750,7 +749,6 @@ export class NetworkCommand extends BaseCommand { } } - self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.deletePvcs, flags.deleteSecrets, flags.namespace]); ctx.config = { diff --git a/src/commands/node/tasks.ts b/src/commands/node/tasks.ts index a5bf0d111..460b22a34 100644 --- a/src/commands/node/tasks.ts +++ b/src/commands/node/tasks.ts @@ -1738,8 +1738,6 @@ export class NodeCommandTasks { this.logger.setDevMode(true); } - this.configManager.update(argv); - // disable the prompts that we don't want to prompt the user for flags.disablePrompts([...requiredFlagsWithDisabledPrompt, ...optionalFlags]); diff --git a/src/commands/relay.ts b/src/commands/relay.ts index bc5b2fab7..5e9179d97 100644 --- a/src/commands/relay.ts +++ b/src/commands/relay.ts @@ -215,8 +215,6 @@ export class RelayCommand extends BaseCommand { // reset nodeAlias self.configManager.setFlag(flags.nodeAliasesUnparsed, ''); - self.configManager.update(argv); - flags.disablePrompts([flags.operatorId, flags.operatorKey]); await self.configManager.executePrompt(task, RelayCommand.DEPLOY_FLAGS_LIST); @@ -345,7 +343,6 @@ export class RelayCommand extends BaseCommand { // reset nodeAlias self.configManager.setFlag(flags.nodeAliasesUnparsed, ''); - self.configManager.update(argv); await self.configManager.executePrompt(task, RelayCommand.DESTROY_FLAGS_LIST); // prompt if inputs are empty and set it in the context diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts index f9e3f61f9..62cf76d5b 100644 --- a/src/core/config/remote/common_flags_data_wrapper.ts +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -20,6 +20,7 @@ import type {RemoteConfigCommonFlagsStruct} from './types.js'; import type {ConfigManager} from '../../config_manager.js'; import type {CommandFlag} from '../../../types/flag_types.js'; import type {AnyObject} from '../../../types/aliases.js'; +import {select} from '@inquirer/prompts'; export class CommonFlagsDataWrapper implements ToObject { private static readonly COMMON_FLAGS: CommandFlag[] = [ @@ -40,34 +41,47 @@ export class CommonFlagsDataWrapper implements ToObject { - this.updateFlag(flag); - }); + public async handleFlags(argv: AnyObject): Promise { + for (const flag of CommonFlagsDataWrapper.COMMON_FLAGS) { + await this.checkFlag(flag); + } } - private updateFlag(flag: CommandFlag): void { - const detectFlagMismatch = () => { + private async checkFlag(flag: CommandFlag): Promise { + const detectFlagMismatch = async () => { const oldValue = this.flags[flag.constName] as string; const newValue = this.configManager.getFlag(flag); // if the old value is not present, override it with the new one - if (!oldValue) { + if (!oldValue && newValue) { this.flags[flag.constName] = newValue; + return; } // if its present but there is a mismatch warn user else if (oldValue && oldValue !== newValue) { - // TODO: WARN THE USER - this.flags[flag.constName] = newValue; + const answer = await select({ + message: 'Value in remote config differs with the one you are passing, choose with which you want to keep', + choices: [ + { + name: `[old value] ${oldValue}`, + value: oldValue, + }, + { + name: `[new value] ${newValue}`, + value: newValue, + }, + ], + }); + + // Override if user chooses new the new value, else do nothing and keep the old one + if (answer === newValue) this.flags[flag.constName] = newValue; } }; // if the flag is set, inspect the value if (this.configManager.hasFlag(flag)) { - detectFlagMismatch(); + await detectFlagMismatch(); } // if the value is not set and exists, override it @@ -76,9 +90,13 @@ export class CommonFlagsDataWrapper implements ToObject { const commonFlagsDataWrapper = new CommonFlagsDataWrapper(configManager, {}); - commonFlagsDataWrapper.handleFlags(argv); + await commonFlagsDataWrapper.handleFlags(argv); return commonFlagsDataWrapper; } diff --git a/src/core/config/remote/remote_config_manager.ts b/src/core/config/remote/remote_config_manager.ts index 8e50d1773..721af1b04 100644 --- a/src/core/config/remote/remote_config_manager.ts +++ b/src/core/config/remote/remote_config_manager.ts @@ -122,7 +122,7 @@ export class RemoteConfigManager { commandHistory: ['deployment create'], lastExecutedCommand: 'deployment create', components: ComponentsDataWrapper.initializeEmpty(), - flags: CommonFlagsDataWrapper.initializeEmpty(this.configManager, argv), + flags: await CommonFlagsDataWrapper.initializeEmpty(this.configManager, argv), }); await this.createConfigMap(); @@ -215,7 +215,7 @@ export class RemoteConfigManager { const currentCommand = argv._.join(' '); self.remoteConfig!.addCommandToHistory(currentCommand); - self.remoteConfig.flags.handleFlags(argv); + await self.remoteConfig.flags.handleFlags(argv); await self.save(); } diff --git a/src/index.ts b/src/index.ts index 11e831515..c1bbf515a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -141,6 +141,7 @@ export function main(argv: any) { (command === 'cluster' && subCommand === 'info') || (command === 'cluster' && subCommand === 'list') || (command === 'deployment' && subCommand === 'create'); + if (!skip) { await remoteConfigManager.loadAndValidate(argv); } diff --git a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts index d16ad0682..93d41a404 100644 --- a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts +++ b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts @@ -32,7 +32,7 @@ const configManagerMock = { setFlag: (...args: any) => true, }; -function createRemoteConfigDataWrapper() { +async function createRemoteConfigDataWrapper() { const {metadata} = createMetadata(); const { wrapper: {componentsDataWrapper}, @@ -42,7 +42,7 @@ function createRemoteConfigDataWrapper() { const components = componentsDataWrapper; const lastExecutedCommand = 'lastExecutedCommand'; const commandHistory = []; - const flags = CommonFlagsDataWrapper.initializeEmpty(configManagerMock as any, {}); // TODO MOCK + const flags = await CommonFlagsDataWrapper.initializeEmpty(configManagerMock as any, {}); // TODO MOCK const dataWrapper = new RemoteConfigDataWrapper({ metadata, @@ -59,11 +59,11 @@ function createRemoteConfigDataWrapper() { }; } -describe('RemoteConfigDataWrapper', () => { +describe('RemoteConfigDataWrapper', async () => { it('should be able to create a instance', () => createRemoteConfigDataWrapper()); - it('should be able to add new command to history with addCommandToHistory()', () => { - const {dataWrapper} = createRemoteConfigDataWrapper(); + it('should be able to add new command to history with addCommandToHistory()', async () => { + const {dataWrapper} = await createRemoteConfigDataWrapper(); const command = 'command'; @@ -79,8 +79,8 @@ describe('RemoteConfigDataWrapper', () => { }); }); - it('should successfully be able to parse yaml and create instance with fromConfigmap()', () => { - const {dataWrapper} = createRemoteConfigDataWrapper(); + it('should successfully be able to parse yaml and create instance with fromConfigmap()', async () => { + const {dataWrapper} = await createRemoteConfigDataWrapper(); const dataWrapperObject = dataWrapper.toObject(); const yamlData = yaml.stringify({ @@ -94,8 +94,8 @@ describe('RemoteConfigDataWrapper', () => { RemoteConfigDataWrapper.fromConfigmap(configManagerMock as any, {data: {'remote-config-data': yamlData}} as any); }); - it('should fail if invalid data is passed to setters', () => { - const {dataWrapper} = createRemoteConfigDataWrapper(); + it('should fail if invalid data is passed to setters', async () => { + const {dataWrapper} = await createRemoteConfigDataWrapper(); // @ts-expect-error TS2322: Type string is not assignable to type string[] expect(() => (dataWrapper.commandHistory = '')).to.throw(SoloError); From 1e270e1a3dc40d5196c3993a2f0b788793b8a79a Mon Sep 17 00:00:00 2001 From: instamenta Date: Wed, 22 Jan 2025 16:42:06 +0200 Subject: [PATCH 06/14] changed strategy to override values on argv so they have effect during the post middleware command execution Signed-off-by: instamenta --- src/commands/account.ts | 4 ++++ src/commands/cluster/configs.ts | 1 + src/commands/deployment.ts | 5 ++++- src/commands/init.ts | 1 + src/commands/mirror_node.ts | 3 +++ src/commands/network.ts | 2 ++ src/commands/node/tasks.ts | 2 ++ src/commands/relay.ts | 3 +++ .../remote/common_flags_data_wrapper.ts | 20 ++++++++++--------- 9 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/commands/account.ts b/src/commands/account.ts index 7aff66b03..f8e39fda2 100644 --- a/src/commands/account.ts +++ b/src/commands/account.ts @@ -177,6 +177,7 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { + self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.namespace]); const config = { @@ -329,6 +330,7 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { + self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.namespace]); const config = { @@ -411,6 +413,7 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { + self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.accountId, flags.namespace]); const config = { @@ -493,6 +496,7 @@ export class AccountCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { + self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.accountId, flags.namespace]); const config = { diff --git a/src/commands/cluster/configs.ts b/src/commands/cluster/configs.ts index e1efcedeb..d1f9ece95 100644 --- a/src/commands/cluster/configs.ts +++ b/src/commands/cluster/configs.ts @@ -38,6 +38,7 @@ export const connectConfigBuilder = async function (argv, ctx, task) { export const setupConfigBuilder = async function (argv, ctx, task) { const parent = this.parent; const configManager = parent.getConfigManager(); + configManager.update(argv); flags.disablePrompts([flags.chartDirectory]); await configManager.executePrompt(task, [ diff --git a/src/commands/deployment.ts b/src/commands/deployment.ts index a164df29d..e5fff3a72 100644 --- a/src/commands/deployment.ts +++ b/src/commands/deployment.ts @@ -68,6 +68,7 @@ export class DeploymentCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { + self.configManager.update(argv); self.logger.debug('Updated config with argv', {config: self.configManager.config}); await self.configManager.executePrompt(task, [ @@ -137,7 +138,9 @@ export class DeploymentCommand extends BaseCommand { for (const context of Object.keys(ctx.config.contextCluster)) { const cluster = ctx.config.contextCluster[context]; - subTasks.push(RemoteConfigTasks.createRemoteConfig.bind(this)(cluster, context, ctx.config.namespace)); + subTasks.push( + RemoteConfigTasks.createRemoteConfig.bind(this)(cluster, context, ctx.config.namespace, argv), + ); } return task.newListr(subTasks, { diff --git a/src/commands/init.ts b/src/commands/init.ts index 184e683d5..3ad318c0c 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -45,6 +45,7 @@ export class InitCommand extends BaseCommand { { title: 'Setup home directory and cache', task: ctx => { + self.configManager.update(argv); ctx.dirs = this.setupHomeDirectory(); }, }, diff --git a/src/commands/mirror_node.ts b/src/commands/mirror_node.ts index 07d0aca4c..3cae3e509 100644 --- a/src/commands/mirror_node.ts +++ b/src/commands/mirror_node.ts @@ -225,6 +225,8 @@ export class MirrorNodeCommand extends BaseCommand { { title: 'Initialize', task: async (ctx, task) => { + self.configManager.update(argv); + // disable the prompts that we don't want to prompt the user for flags.disablePrompts([ flags.deployHederaExplorer, @@ -598,6 +600,7 @@ export class MirrorNodeCommand extends BaseCommand { } } + self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.namespace]); // @ts-ignore diff --git a/src/commands/network.ts b/src/commands/network.ts index aa825fa50..2c20699f5 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -356,6 +356,7 @@ export class NetworkCommand extends BaseCommand { } async prepareConfig(task: any, argv: any) { + this.configManager.update(argv); this.logger.debug('Updated config with argv', {config: this.configManager.config}); // disable the prompts that we don't want to prompt the user for @@ -749,6 +750,7 @@ export class NetworkCommand extends BaseCommand { } } + self.configManager.update(argv); await self.configManager.executePrompt(task, [flags.deletePvcs, flags.deleteSecrets, flags.namespace]); ctx.config = { diff --git a/src/commands/node/tasks.ts b/src/commands/node/tasks.ts index 460b22a34..a5bf0d111 100644 --- a/src/commands/node/tasks.ts +++ b/src/commands/node/tasks.ts @@ -1738,6 +1738,8 @@ export class NodeCommandTasks { this.logger.setDevMode(true); } + this.configManager.update(argv); + // disable the prompts that we don't want to prompt the user for flags.disablePrompts([...requiredFlagsWithDisabledPrompt, ...optionalFlags]); diff --git a/src/commands/relay.ts b/src/commands/relay.ts index 5e9179d97..bc5b2fab7 100644 --- a/src/commands/relay.ts +++ b/src/commands/relay.ts @@ -215,6 +215,8 @@ export class RelayCommand extends BaseCommand { // reset nodeAlias self.configManager.setFlag(flags.nodeAliasesUnparsed, ''); + self.configManager.update(argv); + flags.disablePrompts([flags.operatorId, flags.operatorKey]); await self.configManager.executePrompt(task, RelayCommand.DEPLOY_FLAGS_LIST); @@ -343,6 +345,7 @@ export class RelayCommand extends BaseCommand { // reset nodeAlias self.configManager.setFlag(flags.nodeAliasesUnparsed, ''); + self.configManager.update(argv); await self.configManager.executePrompt(task, RelayCommand.DESTROY_FLAGS_LIST); // prompt if inputs are empty and set it in the context diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts index 62cf76d5b..cff5599d0 100644 --- a/src/core/config/remote/common_flags_data_wrapper.ts +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -43,11 +43,11 @@ export class CommonFlagsDataWrapper implements ToObject { for (const flag of CommonFlagsDataWrapper.COMMON_FLAGS) { - await this.checkFlag(flag); + await this.checkFlag(flag, argv); } } - private async checkFlag(flag: CommandFlag): Promise { + private async checkFlag(flag: CommandFlag, argv: AnyObject): Promise { const detectFlagMismatch = async () => { const oldValue = this.flags[flag.constName] as string; const newValue = this.configManager.getFlag(flag); @@ -61,7 +61,7 @@ export class CommonFlagsDataWrapper implements ToObject({ - message: 'Value in remote config differs with the one you are passing, choose with which you want to keep', + message: 'Value in remote config differs with the one you are passing, choose which you want to use', choices: [ { name: `[old value] ${oldValue}`, @@ -74,8 +74,13 @@ export class CommonFlagsDataWrapper implements ToObject { const commonFlagsDataWrapper = new CommonFlagsDataWrapper(configManager, {}); await commonFlagsDataWrapper.handleFlags(argv); From a3cbd49ec0044f7eea6c9904ca3af6a2c369cb30 Mon Sep 17 00:00:00 2001 From: instamenta Date: Thu, 23 Jan 2025 13:39:50 +0200 Subject: [PATCH 07/14] merge with mian Signed-off-by: instamenta --- src/commands/deployment.ts | 2 +- src/commands/mirror_node.ts | 2 +- src/core/config/remote/listr_config_tasks.ts | 24 +++++++++---------- .../config/remote/remote_config_manager.ts | 4 ++-- src/core/config/remote/remote_config_tasks.ts | 0 5 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 src/core/config/remote/remote_config_tasks.ts diff --git a/src/commands/deployment.ts b/src/commands/deployment.ts index 2f7c888f3..b246b8d4c 100644 --- a/src/commands/deployment.ts +++ b/src/commands/deployment.ts @@ -131,7 +131,7 @@ export class DeploymentCommand extends BaseCommand { }); }, }, - ListrRemoteConfig.createRemoteConfigInMultipleClusters(this), + ListrRemoteConfig.createRemoteConfigInMultipleClusters(this, argv), ], { concurrent: false, diff --git a/src/commands/mirror_node.ts b/src/commands/mirror_node.ts index d7a60335a..7796eebc9 100644 --- a/src/commands/mirror_node.ts +++ b/src/commands/mirror_node.ts @@ -570,7 +570,7 @@ export class MirrorNodeCommand extends BaseCommand { } /** Removes the mirror node components from remote config. */ - public removeMirrorNodeComponents(): SoloListrTask { + public removeMirrorNodeComponents(): SoloListrTask { return { title: 'Remove mirror node from remote config', skip: (): boolean => !this.remoteConfigManager.isLoaded(), diff --git a/src/core/config/remote/listr_config_tasks.ts b/src/core/config/remote/listr_config_tasks.ts index 91d967301..ffd058a8b 100644 --- a/src/core/config/remote/listr_config_tasks.ts +++ b/src/core/config/remote/listr_config_tasks.ts @@ -14,10 +14,10 @@ * limitations under the License. * */ -import type {ListrTask} from 'listr2'; import type {BaseCommand} from '../../../commands/base.js'; -import {type Cluster, type Context, type Namespace} from './types.js'; +import type {Cluster, Context, Namespace} from './types.js'; import type {SoloListrTask} from '../../../types/index.js'; +import type {AnyObject} from '../../../types/aliases.js'; /** * Static class that handles all tasks related to remote config used by other commands. @@ -38,10 +38,10 @@ export class ListrRemoteConfig { * @param command - the BaseCommand object on which an action will be performed * @param argv - used to update the last executed command and command history */ - public static loadRemoteConfig(command: BaseCommand, argv: any): ListrTask { + public static loadRemoteConfig(command: BaseCommand, argv: any): SoloListrTask { return { title: 'Load remote config', - task: async (_, task): Promise => { + task: async (): Promise => { await command.getRemoteConfigManager().loadAndValidate(argv); }, }; @@ -49,21 +49,18 @@ export class ListrRemoteConfig { /** * Create remoteConfig and save it to the provided cluster. - * @param command - * @param cluster - * @param context - * @param namespace */ public static createRemoteConfig( command: BaseCommand, cluster: Cluster, context: Context, namespace: Namespace, - ): ListrTask { + argv: AnyObject, + ): SoloListrTask { return { title: `Create remote config in cluster: ${cluster}`, - task: async (_, task): Promise => { - await command.getRemoteConfigManager().createAndValidate(cluster, context, namespace); + task: async (): Promise => { + await command.getRemoteConfigManager().createAndValidate(cluster, context, namespace, argv); }, }; } @@ -72,8 +69,9 @@ export class ListrRemoteConfig { * Create a remoteConfig object and save it to multiple clusters, read from ctx config * * @param command - the BaseCommand object on which an action will be performed + * @param argv */ - public static createRemoteConfigInMultipleClusters(command: BaseCommand): ListrTask { + public static createRemoteConfigInMultipleClusters(command: BaseCommand, argv: AnyObject): SoloListrTask { return { title: 'Create remoteConfig in clusters', task: async (ctx, task) => { @@ -81,7 +79,7 @@ export class ListrRemoteConfig { for (const context of Object.keys(ctx.config.contextCluster)) { const cluster = ctx.config.contextCluster[context]; - subTasks.push(ListrRemoteConfig.createRemoteConfig(command, cluster, context, ctx.config.namespace)); + subTasks.push(ListrRemoteConfig.createRemoteConfig(command, cluster, context, ctx.config.namespace, argv)); } return task.newListr(subTasks, { diff --git a/src/core/config/remote/remote_config_manager.ts b/src/core/config/remote/remote_config_manager.ts index a53a40b85..af6ac960b 100644 --- a/src/core/config/remote/remote_config_manager.ts +++ b/src/core/config/remote/remote_config_manager.ts @@ -277,7 +277,7 @@ export class RemoteConfigManager { } /// ---- - not mine ---- - - -- - -- - public async createAndValidate(cluster: Cluster, context: Context, namespace: Namespace) { + public async createAndValidate(cluster: Cluster, context: Context, namespace: Namespace, argv: AnyObject) { const self = this; self.k8.setCurrentContext(context); @@ -296,7 +296,7 @@ export class RemoteConfigManager { throw new SoloError('Remote config already exists'); } - await self.create(); + await self.create(argv); } /* ---------- Utilities ---------- */ diff --git a/src/core/config/remote/remote_config_tasks.ts b/src/core/config/remote/remote_config_tasks.ts deleted file mode 100644 index e69de29bb..000000000 From 75d38376fbb8a1603968ee8e422fbda64f0ba9b9 Mon Sep 17 00:00:00 2001 From: Jan Milenkov Date: Thu, 23 Jan 2025 15:52:50 +0200 Subject: [PATCH 08/14] Apply suggestions from code review Co-authored-by: Jeromy Cannon Signed-off-by: Jan Milenkov --- src/core/config/remote/common_flags_data_wrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts index cff5599d0..c80c1daf7 100644 --- a/src/core/config/remote/common_flags_data_wrapper.ts +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -47,7 +47,7 @@ export class CommonFlagsDataWrapper implements ToObject { + private async handleFlag(flag: CommandFlag, argv: AnyObject): Promise { const detectFlagMismatch = async () => { const oldValue = this.flags[flag.constName] as string; const newValue = this.configManager.getFlag(flag); @@ -89,7 +89,7 @@ export class CommonFlagsDataWrapper implements ToObject Date: Thu, 23 Jan 2025 15:53:29 +0200 Subject: [PATCH 09/14] add logic for handling quiet and force flags Signed-off-by: instamenta --- src/commands/mirror_node.ts | 2 +- src/core/config/remote/common_flags_data_wrapper.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/mirror_node.ts b/src/commands/mirror_node.ts index 7796eebc9..06b6131b7 100644 --- a/src/commands/mirror_node.ts +++ b/src/commands/mirror_node.ts @@ -507,7 +507,7 @@ export class MirrorNodeCommand extends BaseCommand { await tasks.run(); self.logger.debug('mirror node destruction has completed'); } catch (e) { - throw new SoloError(`Error destrong mirror node: ${e.message}`, e); + throw new SoloError(`Error destroying mirror node: ${e.message}`, e); } finally { await lease.release(); await self.accountManager.close(); diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts index cff5599d0..47dfa55d3 100644 --- a/src/core/config/remote/common_flags_data_wrapper.ts +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -60,6 +60,12 @@ export class CommonFlagsDataWrapper implements ToObject(flags.quiet); + const isForced = this.configManager.getFlag(flags.force); + + // if the quiet or forced flag is passed don't prompt the user + if (isQuiet === true || isForced === true) return; + const answer = await select({ message: 'Value in remote config differs with the one you are passing, choose which you want to use', choices: [ From b4eb113a82668348ffc0fd638594f53aa200e792 Mon Sep 17 00:00:00 2001 From: instamenta Date: Thu, 23 Jan 2025 15:56:09 +0200 Subject: [PATCH 10/14] rename method Signed-off-by: instamenta --- src/core/config/remote/common_flags_data_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts index 858e0265c..cd1a672a4 100644 --- a/src/core/config/remote/common_flags_data_wrapper.ts +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -43,7 +43,7 @@ export class CommonFlagsDataWrapper implements ToObject { for (const flag of CommonFlagsDataWrapper.COMMON_FLAGS) { - await this.checkFlag(flag, argv); + await this.handleFlag(flag, argv); } } From f3d57c6a1b39f46663ce142d202d27b809ec9f91 Mon Sep 17 00:00:00 2001 From: instamenta Date: Thu, 23 Jan 2025 16:03:13 +0200 Subject: [PATCH 11/14] remove leftover functions from merge Signed-off-by: instamenta --- .../remote/common_flags_data_wrapper.ts | 2 +- .../config/remote/remote_config_manager.ts | 59 +------------------ .../remote_config_data_wrapper.test.ts | 2 +- 3 files changed, 3 insertions(+), 60 deletions(-) diff --git a/src/core/config/remote/common_flags_data_wrapper.ts b/src/core/config/remote/common_flags_data_wrapper.ts index cd1a672a4..dbd29041e 100644 --- a/src/core/config/remote/common_flags_data_wrapper.ts +++ b/src/core/config/remote/common_flags_data_wrapper.ts @@ -102,7 +102,7 @@ export class CommonFlagsDataWrapper implements ToObject { + public static async initialize(configManager: ConfigManager, argv: AnyObject): Promise { const commonFlagsDataWrapper = new CommonFlagsDataWrapper(configManager, {}); await commonFlagsDataWrapper.handleFlags(argv); return commonFlagsDataWrapper; diff --git a/src/core/config/remote/remote_config_manager.ts b/src/core/config/remote/remote_config_manager.ts index af6ac960b..fcd494dcb 100644 --- a/src/core/config/remote/remote_config_manager.ts +++ b/src/core/config/remote/remote_config_manager.ts @@ -122,7 +122,7 @@ export class RemoteConfigManager { commandHistory: ['deployment create'], lastExecutedCommand: 'deployment create', components: ComponentsDataWrapper.initializeEmpty(), - flags: await CommonFlagsDataWrapper.initializeEmpty(this.configManager, argv), + flags: await CommonFlagsDataWrapper.initialize(this.configManager, argv), }); await this.createConfigMap(); @@ -220,63 +220,6 @@ export class RemoteConfigManager { await self.save(); } - /** - * 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; - - return { - title: 'Load remote config', - task: async (): Promise => { - await self.loadAndValidate(argv); - }, - }; - } - - /** - * Builds a task for creating a new remote configuration, intended for use with Listr task management. - * Merges cluster mappings from the provided context into the local configuration, then creates the remote config. - * - * @returns a Listr task which creates the remote configuration. - */ - public buildCreateTask( - cluster: Cluster, - context: Context, - namespace: Namespace, - argv: AnyObject, - ): SoloListrTask { - const self = this; - - return { - title: `Create remote config in cluster: ${cluster}`, - task: async (_, task): Promise => { - self.k8.setCurrentContext(context); - - if (!(await self.k8.hasNamespace(namespace))) { - await self.k8.createNamespace(namespace); - } - - const localConfigExists = this.localConfig.configFileExists(); - if (!localConfigExists) { - throw new SoloError("Local config doesn't exist"); - } - - self.unload(); - if (await self.load()) { - task.title = `${task.title} - ${chalk.red('Remote config already exists')}}`; - throw new SoloError('Remote config already exists'); - } - - await self.create(argv); - }, - }; - } - - /// ---- - not mine ---- - - -- - -- public async createAndValidate(cluster: Cluster, context: Context, namespace: Namespace, argv: AnyObject) { const self = this; self.k8.setCurrentContext(context); diff --git a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts index 93d41a404..4b0ef96df 100644 --- a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts +++ b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts @@ -42,7 +42,7 @@ async function createRemoteConfigDataWrapper() { const components = componentsDataWrapper; const lastExecutedCommand = 'lastExecutedCommand'; const commandHistory = []; - const flags = await CommonFlagsDataWrapper.initializeEmpty(configManagerMock as any, {}); // TODO MOCK + const flags = await CommonFlagsDataWrapper.initialize(configManagerMock as any, {}); // TODO MOCK const dataWrapper = new RemoteConfigDataWrapper({ metadata, From 047f11d01230e6f00de938be58ad5d8df9e19347 Mon Sep 17 00:00:00 2001 From: instamenta Date: Thu, 23 Jan 2025 16:04:37 +0200 Subject: [PATCH 12/14] remove leftover comment Signed-off-by: instamenta --- test/unit/core/remote_config/remote_config_data_wrapper.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts index 4b0ef96df..45b86313e 100644 --- a/test/unit/core/remote_config/remote_config_data_wrapper.test.ts +++ b/test/unit/core/remote_config/remote_config_data_wrapper.test.ts @@ -42,7 +42,7 @@ async function createRemoteConfigDataWrapper() { const components = componentsDataWrapper; const lastExecutedCommand = 'lastExecutedCommand'; const commandHistory = []; - const flags = await CommonFlagsDataWrapper.initialize(configManagerMock as any, {}); // TODO MOCK + const flags = await CommonFlagsDataWrapper.initialize(configManagerMock as any, {}); const dataWrapper = new RemoteConfigDataWrapper({ metadata, From e7daab4547147499346d6d321f4e81d6d8f7bdd9 Mon Sep 17 00:00:00 2001 From: instamenta Date: Thu, 23 Jan 2025 16:05:55 +0200 Subject: [PATCH 13/14] remove unusued compare method Signed-off-by: instamenta --- src/core/config/remote/remote_config_data_wrapper.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/core/config/remote/remote_config_data_wrapper.ts b/src/core/config/remote/remote_config_data_wrapper.ts index d31adf9fd..dfb0f5d9a 100644 --- a/src/core/config/remote/remote_config_data_wrapper.ts +++ b/src/core/config/remote/remote_config_data_wrapper.ts @@ -115,10 +115,6 @@ export class RemoteConfigDataWrapper implements Validate, ToObject Date: Thu, 23 Jan 2025 16:42:11 +0200 Subject: [PATCH 14/14] removed enquirer and inquirer packages from dependencies Signed-off-by: instamenta --- package-lock.json | 32 ++------------------------------ package.json | 2 -- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index 11b84349a..e411c527c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,12 +25,10 @@ "class-validator": "^0.14.1", "dot-object": "^2.1.5", "dotenv": "^16.4.7", - "enquirer": "^2.4.1", "esm": "^3.2.25", "figlet": "^1.8.0", "got": "^14.4.5", "http-status-codes": "^2.3.0", - "inquirer": "^12.3.2", "ip": "^2.0.1", "js-base64": "^3.7.7", "listr2": "^8.2.5", @@ -4969,6 +4967,7 @@ "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.4.1.tgz", "integrity": "sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ==", "license": "MIT", + "peer": true, "dependencies": { "ansi-colors": "^4.1.1", "strip-ansi": "^6.0.1" @@ -6857,26 +6856,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/inquirer": { - "version": "12.3.2", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-12.3.2.tgz", - "integrity": "sha512-YjQCIcDd3yyDuQrbII0FBtm/ZqNoWtvaC71yeCnd5Vbg4EgzsAGaemzfpzmqfvIZEp2roSwuZZKdM0C65hA43g==", - "dependencies": { - "@inquirer/core": "^10.1.4", - "@inquirer/prompts": "^7.2.3", - "@inquirer/type": "^3.0.2", - "ansi-escapes": "^4.3.2", - "mute-stream": "^2.0.0", - "run-async": "^3.0.0", - "rxjs": "^7.8.1" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "@types/node": ">=18" - } - }, "node_modules/internal-slot": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.7.tgz", @@ -11255,14 +11234,6 @@ "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==" }, - "node_modules/run-async": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-3.0.0.tgz", - "integrity": "sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==", - "engines": { - "node": ">=0.12.0" - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -11291,6 +11262,7 @@ "version": "7.8.1", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "dev": true, "dependencies": { "tslib": "^2.1.0" } diff --git a/package.json b/package.json index 102862683..52dce67f0 100644 --- a/package.json +++ b/package.json @@ -58,12 +58,10 @@ "class-validator": "^0.14.1", "dot-object": "^2.1.5", "dotenv": "^16.4.7", - "enquirer": "^2.4.1", "esm": "^3.2.25", "figlet": "^1.8.0", "got": "^14.4.5", "http-status-codes": "^2.3.0", - "inquirer": "^12.3.2", "ip": "^2.0.1", "js-base64": "^3.7.7", "listr2": "^8.2.5",