-
Notifications
You must be signed in to change notification settings - Fork 22
feat(remote-config): save reusable solo flags in remoteconfig #1191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
instamenta
merged 21 commits into
main
from
01178-save-reusable-solo-flags-in-remoteconfig
Jan 27, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
dec37b5
added new data wrapper for the common flags and the common methods fo…
instamenta 072f142
add to middleware, pass the configManager and the argv down to the re…
instamenta 7d03d77
removed some ts-ignore tags, lint fix and added .madgerc file to igno…
instamenta 95dff03
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta 8b961b3
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta 9722eee
removed circular dependencies and madgerc override
jeromy-cannon c354941
working on prompting the user and overriding the configManager's valu…
instamenta 1e270e1
changed strategy to override values on argv so they have effect durin…
instamenta 82b2f5b
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta a3cbd49
merge with mian
instamenta 75d3837
Apply suggestions from code review
instamenta 1cd8d22
add logic for handling quiet and force flags
instamenta 966ab43
Merge remote-tracking branch 'origin/01178-save-reusable-solo-flags-i…
instamenta b4eb113
rename method
instamenta f3d57c6
remove leftover functions from merge
instamenta 047f11d
remove leftover comment
instamenta e7daab4
remove unusued compare method
instamenta 0dd6a2c
removed enquirer and inquirer packages from dependencies
instamenta 43b770f
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta 43d615e
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta 0318b1d
Merge remote-tracking branch 'origin/main' into 01178-save-reusable-s…
instamenta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* 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'; | ||
import type {AnyObject} from '../../../types/aliases.js'; | ||
import {select} from '@inquirer/prompts'; | ||
|
||
export class CommonFlagsDataWrapper implements ToObject<RemoteConfigCommonFlagsStruct> { | ||
private static readonly COMMON_FLAGS: CommandFlag[] = [ | ||
flags.releaseTag, | ||
flags.chartDirectory, | ||
flags.relayReleaseTag, | ||
flags.soloChartVersion, | ||
flags.mirrorNodeVersion, | ||
flags.nodeAliasesUnparsed, | ||
flags.hederaExplorerVersion, | ||
]; | ||
|
||
private constructor( | ||
private readonly configManager: ConfigManager, | ||
private readonly flags: RemoteConfigCommonFlagsStruct, | ||
) {} | ||
|
||
/** | ||
* Updates the flags or populates them inside the remote config | ||
*/ | ||
public async handleFlags(argv: AnyObject): Promise<void> { | ||
for (const flag of CommonFlagsDataWrapper.COMMON_FLAGS) { | ||
await this.handleFlag(flag, argv); | ||
} | ||
} | ||
|
||
private async handleFlag(flag: CommandFlag, argv: AnyObject): Promise<void> { | ||
const detectFlagMismatch = async () => { | ||
const oldValue = this.flags[flag.constName] as string; | ||
const newValue = this.configManager.getFlag<string>(flag); | ||
|
||
// if the old value is not present, override it with the new one | ||
if (!oldValue && newValue) { | ||
this.flags[flag.constName] = newValue; | ||
return; | ||
} | ||
|
||
// if its present but there is a mismatch warn user | ||
else if (oldValue && oldValue !== newValue) { | ||
const isQuiet = this.configManager.getFlag<boolean>(flags.quiet); | ||
const isForced = this.configManager.getFlag<boolean>(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<string>({ | ||
message: 'Value in remote config differs with the one you are passing, choose which you want to use', | ||
choices: [ | ||
{ | ||
name: `[old value] ${oldValue}`, | ||
value: oldValue, | ||
}, | ||
{ | ||
name: `[new value] ${newValue}`, | ||
value: newValue, | ||
}, | ||
], | ||
}); | ||
|
||
// Override if user chooses new the new value, else override and keep the old one | ||
if (answer === newValue) { | ||
this.flags[flag.constName] = newValue; | ||
} else { | ||
this.configManager.setFlag(flag, oldValue); | ||
argv[flag.constName] = oldValue; | ||
} | ||
} | ||
}; | ||
|
||
// if the flag is set, inspect the value | ||
if (this.configManager.hasFlag(flag)) { | ||
await detectFlagMismatch(); | ||
} | ||
|
||
// use remote config value if no user supplied value | ||
else if (this.flags[flag.constName]) { | ||
argv[flag.constName] = this.flags[flag.constName]; | ||
this.configManager.setFlag(flag, this.flags[flag.constName]); | ||
} | ||
} | ||
|
||
public static async initialize(configManager: ConfigManager, argv: AnyObject): Promise<CommonFlagsDataWrapper> { | ||
const commonFlagsDataWrapper = new CommonFlagsDataWrapper(configManager, {}); | ||
await commonFlagsDataWrapper.handleFlags(argv); | ||
return commonFlagsDataWrapper; | ||
} | ||
|
||
public static fromObject(configManager: ConfigManager, data: RemoteConfigCommonFlagsStruct): CommonFlagsDataWrapper { | ||
return new CommonFlagsDataWrapper(configManager, 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, | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Cluster, Namespace>; | ||
components: ComponentsDataWrapper; | ||
lastExecutedCommand: string; | ||
commandHistory: string[]; | ||
flags: CommonFlagsDataWrapper; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.