-
Notifications
You must be signed in to change notification settings - Fork 3
feat: settings sync command #198
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
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1e47192
settings sync command
adamspofford-dfinity 4585e0c
.
adamspofford-dfinity ad11446
Add warning
adamspofford-dfinity 04da38d
feedback
adamspofford-dfinity 9bc0cd0
that makes it stdout
adamspofford-dfinity 45b04a1
.
adamspofford-dfinity 1869e49
Merge branch 'main' into spofford/settings-sync
adamspofford-dfinity d1ea0ac
box some large errors to reduce result size for clippy lint
adamspofford-dfinity 2501161
convert to snafu while I'm here
adamspofford-dfinity 6651c31
Merge branch 'main' into spofford/settings-sync
raymondk e01b5bd
Merge branch 'main' into spofford/settings-sync
adamspofford-dfinity 76af09b
merge checks
adamspofford-dfinity 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
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 |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| use clap::Subcommand; | ||
|
|
||
| pub(crate) mod show; | ||
| pub(crate) mod sync; | ||
| pub(crate) mod update; | ||
|
|
||
| #[derive(Subcommand, Debug)] | ||
| #[allow(clippy::large_enum_variant)] | ||
| pub(crate) enum Command { | ||
| /// Display a canister's settings | ||
| Show(show::ShowArgs), | ||
| /// Change a canister's settings to specified values | ||
| Update(update::UpdateArgs), | ||
| /// Synchronize a canister's settings with those defined in the project | ||
| Sync(sync::SyncArgs), | ||
| } | ||
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,75 @@ | ||
| use crate::{ | ||
| commands::args::CanisterCommandArgs, operations::settings::SyncSettingsOperationError, | ||
| }; | ||
|
|
||
| use clap::Args; | ||
| use ic_utils::interfaces::ManagementCanister; | ||
| use icp::{ | ||
| LoadError, | ||
| context::{ | ||
| AssertEnvContainsCanisterError, CanisterSelection, Context, GetCanisterIdAndAgentError, | ||
| GetEnvironmentError, | ||
| }, | ||
| }; | ||
| use snafu::Snafu; | ||
|
|
||
| #[derive(Debug, Args)] | ||
| pub(crate) struct SyncArgs { | ||
| #[command(flatten)] | ||
| cmd_args: CanisterCommandArgs, | ||
| } | ||
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub(crate) enum CommandError { | ||
| #[snafu(transparent)] | ||
| GetIdAndAgent { source: GetCanisterIdAndAgentError }, | ||
|
|
||
| #[snafu(transparent)] | ||
| GetEnvironment { source: GetEnvironmentError }, | ||
|
|
||
| #[snafu(display("Canister name must be used for settings sync"))] | ||
| PrincipalCanister, | ||
|
|
||
| #[snafu(transparent)] | ||
| LoadProject { source: LoadError }, | ||
|
|
||
| #[snafu(display("project does not contain a canister named '{name}'"))] | ||
| CanisterNotFound { name: String }, | ||
|
|
||
| #[snafu(transparent)] | ||
| EnvironmentCanisterNotFound { | ||
| source: AssertEnvContainsCanisterError, | ||
| }, | ||
|
|
||
| #[snafu(transparent)] | ||
| SyncSettingsError { source: SyncSettingsOperationError }, | ||
| } | ||
|
|
||
| pub(crate) async fn exec(ctx: &Context, args: &SyncArgs) -> Result<(), CommandError> { | ||
| let selections = args.cmd_args.selections(); | ||
| let CanisterSelection::Named(name) = &selections.canister else { | ||
| return PrincipalCanisterSnafu.fail(); | ||
| }; | ||
|
|
||
| let p = ctx.project.load().await?; | ||
|
|
||
| let Some((_, canister)) = p.canisters.get(name) else { | ||
| return CanisterNotFoundSnafu { name }.fail(); | ||
| }; | ||
adamspofford-dfinity marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ctx.assert_env_contains_canister(name, &selections.environment) | ||
| .await?; | ||
|
|
||
| let (cid, agent) = ctx | ||
| .get_canister_id_and_agent( | ||
| &selections.canister, | ||
| &selections.environment, | ||
| &selections.network, | ||
| &selections.identity, | ||
| ) | ||
| .await?; | ||
|
|
||
| let mgmt = ManagementCanister::create(&agent); | ||
|
|
||
| crate::operations::settings::sync_settings(&mgmt, &cid, canister).await?; | ||
| Ok(()) | ||
| } | ||
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
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.