Initializes the canister with the given owners and settings. Must only be called within a canister init call.
(&self, input: SystemInit)
| 518 | /// |
| 519 | /// Must only be called within a canister init call. |
| 520 | pub async fn init_canister(&self, input: SystemInit) -> ServiceResult<()> { |
| 521 | let mut system_info = SystemInfo::default(); |
| 522 | |
| 523 | match &input.initial_config { |
| 524 | InitialConfig::WithAllDefaults { |
| 525 | admin_quorum, |
| 526 | operator_quorum, |
| 527 | users, |
| 528 | } => { |
| 529 | // adds the default admin group |
| 530 | init_canister_sync_handlers::add_default_groups(); |
| 531 | // registers the admins of the canister |
| 532 | init_canister_sync_handlers::set_initial_users(users.clone(), &DEFAULT_GROUP_IDS)?; |
| 533 | // registers the default canister configurations such as policies and user groups. |
| 534 | init_canister_sync_handlers::init_default_permissions_and_policies( |
| 535 | *admin_quorum, |
| 536 | *operator_quorum, |
| 537 | )?; |
| 538 | // add default assets |
| 539 | init_canister_sync_handlers::add_default_assets(); |
| 540 | } |
| 541 | InitialConfig::WithDefaultPolicies { |
| 542 | assets, |
| 543 | users, |
| 544 | admin_quorum, |
| 545 | operator_quorum, |
| 546 | .. |
| 547 | } => { |
| 548 | // adds the default admin group |
| 549 | init_canister_sync_handlers::add_default_groups(); |
| 550 | // registers the admins of the canister |
| 551 | init_canister_sync_handlers::set_initial_users(users.clone(), &DEFAULT_GROUP_IDS)?; |
| 552 | // adds the initial assets |
| 553 | init_canister_sync_handlers::set_initial_assets(assets).await?; |
| 554 | |
| 555 | // registers the default canister configurations such as policies and user groups. |
| 556 | init_canister_sync_handlers::init_default_permissions_and_policies( |
| 557 | *admin_quorum, |
| 558 | *operator_quorum, |
| 559 | )?; |
| 560 | |
| 561 | // initial accounts are added in the post process work timer, since they might do inter-canister calls |
| 562 | } |
| 563 | InitialConfig::Complete { |
| 564 | users, |
| 565 | user_groups, |
| 566 | permissions, |
| 567 | request_policies, |
| 568 | named_rules, |
| 569 | assets, |
| 570 | .. |
| 571 | } => { |
| 572 | print("adding initial user groups"); |
| 573 | init_canister_sync_handlers::set_initial_user_groups(user_groups).await?; |
| 574 | print("adding initial users"); |
| 575 | init_canister_sync_handlers::set_initial_users(users.clone(), &[])?; |
| 576 | print("adding initial named rules"); |
| 577 | init_canister_sync_handlers::set_initial_named_rules(named_rules)?; |
no test coverage detected