Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* feat!: Remove `--set-controller` and replace with a new flag `--remove-all-controllers`. For the old behavior, combine this flag with `--add-controller`
* fix: Duplicate identities no longer cause an error when starting a network

# v0.2.1-beta.0
Expand Down
29 changes: 15 additions & 14 deletions crates/icp-cli/src/commands/canister/settings/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ use crate::commands::args;
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct ControllerOpt {
/// Add one or more principals to the canister's controller list.
#[arg(long, action = ArgAction::Append, conflicts_with("set_controller"))]
#[arg(long, action = ArgAction::Append)]
add_controller: Option<Vec<Principal>>,

/// Remove one or more principals from the canister's controller list.
///
/// Warning: Removing yourself will cause you to lose control of the canister.
#[arg(long, action = ArgAction::Append, conflicts_with("set_controller"))]
#[arg(long, action = ArgAction::Append)]
remove_controller: Option<Vec<Principal>>,

/// Replace the canister's controller list with the specified principals.
/// Remove all controllers.
///
/// Warning: This removes all existing controllers not in the new list.
/// If you don't include yourself, you will lose control of the canister.
#[arg(long, action = ArgAction::Append)]
set_controller: Option<Vec<Principal>>,
/// Warning: This will cause you to lose control of the canister, unless you
/// add your user principal back in `--add-controller` in the same command.
#[arg(long, conflicts_with = "remove_controller")]
remove_all_controllers: bool,
}

impl ControllerOpt {
pub(crate) fn require_current_settings(&self) -> bool {
self.add_controller.is_some() || self.remove_controller.is_some()
!self.remove_all_controllers
&& (self.add_controller.is_some() || self.remove_controller.is_some())
}
}

Expand Down Expand Up @@ -344,9 +345,7 @@ fn get_controllers(
controllers: &ControllerOpt,
current_status: Option<&CanisterStatusResult>,
) -> Option<Vec<Principal>> {
if let Some(controllers) = controllers.set_controller.as_ref() {
return Some(controllers.clone());
} else if controllers.require_current_settings() {
if controllers.require_current_settings() {
let mut current_controllers: HashSet<Principal> = current_status
.as_ref()
.expect("current status should be ready")
Expand All @@ -365,10 +364,12 @@ fn get_controllers(
}
}

return Some(current_controllers.into_iter().collect::<Vec<Principal>>());
Some(current_controllers.into_iter().collect::<Vec<Principal>>())
} else if controllers.remove_all_controllers {
Some(controllers.add_controller.clone().unwrap_or_default())
} else {
None
}

None
}

fn get_log_visibility(
Expand Down
5 changes: 3 additions & 2 deletions crates/icp-cli/tests/canister_settings_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ async fn canister_settings_update_controllers() {
"--environment",
"random-environment",
"--force",
"--set-controller",
"--remove-all-controllers",
"--add-controller",
principal_alice.as_str(),
"--set-controller",
"--add-controller",
principal_bob.as_str(),
])
.assert()
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ Change a canister's settings to specified values
* `--remove-controller <REMOVE_CONTROLLER>` — Remove one or more principals from the canister's controller list.

Warning: Removing yourself will cause you to lose control of the canister.
* `--set-controller <SET_CONTROLLER>` — Replace the canister's controller list with the specified principals.
* `--remove-all-controllers` — Remove all controllers.

Warning: This removes all existing controllers not in the new list. If you don't include yourself, you will lose control of the canister.
Warning: This will cause you to lose control of the canister, unless you add your user principal back in `--add-controller` in the same command.
* `--compute-allocation <COMPUTE_ALLOCATION>`
* `--memory-allocation <MEMORY_ALLOCATION>` — Memory allocation in bytes. Supports suffixes: kb, kib, mb, mib, gb, gib (e.g. "4gib" or "2.5kb")
* `--freezing-threshold <FREEZING_THRESHOLD>` — Freezing threshold. Controls how long a canister can be inactive before being frozen. Supports duration suffixes: s (seconds), m (minutes), h (hours), d (days), w (weeks). A bare number is treated as seconds
Expand Down
Loading