Skip to content

Commit

Permalink
log_visibility v2
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymar committed Aug 27, 2024
1 parent 6e11a35 commit bc58215
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ic-utils/src/interfaces/management_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub struct QueryStats {
}

/// Log visibility for a canister.
#[derive(Default, Clone, Copy, CandidType, Deserialize, Debug, PartialEq, Eq)]
#[derive(Default, Clone, CandidType, Deserialize, Debug, PartialEq, Eq)]
pub enum LogVisibility {
#[default]
#[serde(rename = "controllers")]
Expand All @@ -158,6 +158,9 @@ pub enum LogVisibility {
#[serde(rename = "public")]
/// Canister logs are visible to everyone.
Public,
#[serde(rename = "allowed_viewers")]
/// Canister logs are visible to a set of principals.
AllowedViewers(Vec<Principal>),
}

/// The concrete settings of a canister.
Expand Down
21 changes: 18 additions & 3 deletions ref-tests/tests/ic-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ mod extras {
use ic_agent::{
agent::{RejectCode, RejectResponse},
export::Principal,
AgentError,
AgentError, Identity,
};
use ic_utils::{
call::AsyncCall,
Expand All @@ -1017,8 +1017,7 @@ mod extras {
ManagementCanister,
},
};
use ref_tests::get_effective_canister_id;
use ref_tests::with_agent;
use ref_tests::{create_basic_identity, get_effective_canister_id, with_agent};

#[ignore]
#[test]
Expand Down Expand Up @@ -1350,6 +1349,7 @@ mod extras {
with_agent(|agent| async move {
let ic00 = ManagementCanister::create(&agent);

// Create with Controllers.
let (canister_id,) = ic00
.create_canister()
.as_provisional_create_with_amount(Some(20_000_000_000_000_u128))
Expand All @@ -1361,6 +1361,7 @@ mod extras {
let result = ic00.canister_status(&canister_id).call_and_wait().await?;
assert_eq!(result.0.settings.log_visibility, LogVisibility::Controllers);

// Update to Public.
ic00.update_settings(&canister_id)
.with_log_visibility(LogVisibility::Public)
.call_and_wait()
Expand All @@ -1369,6 +1370,7 @@ mod extras {
let result = ic00.canister_status(&canister_id).call_and_wait().await?;
assert_eq!(result.0.settings.log_visibility, LogVisibility::Public);

// Update with no change.
let no_change: Option<LogVisibility> = None;
ic00.update_settings(&canister_id)
.with_optional_log_visibility(no_change)
Expand All @@ -1378,6 +1380,19 @@ mod extras {
let result = ic00.canister_status(&canister_id).call_and_wait().await?;
assert_eq!(result.0.settings.log_visibility, LogVisibility::Public);

// Update to AllowedViewers.
let principals = vec![create_basic_identity()?.sender()?];
ic00.update_settings(&canister_id)
.with_log_visibility(LogVisibility::AllowedViewers(principals.clone()))
.call_and_wait()
.await?;

let result = ic00.canister_status(&canister_id).call_and_wait().await?;
assert_eq!(
result.0.settings.log_visibility,
LogVisibility::AllowedViewers(principals)
);

Ok(())
})
}
Expand Down

0 comments on commit bc58215

Please sign in to comment.