Skip to content

Commit

Permalink
Add dfx.json support.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-dfinity committed Sep 20, 2024
1 parent 6372aeb commit faad6b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
29 changes: 24 additions & 5 deletions docs/dfx-json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,29 @@
}
},
"CanisterLogVisibility": {
"type": "string",
"enum": [
"controllers",
"public"
"oneOf": [
{
"type": "string",
"enum": [
"controllers",
"public"
]
},
{
"type": "object",
"required": [
"allowedviewers"
],
"properties": {
"allowedviewers": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
}
]
},
"CanisterMetadataSection": {
Expand Down Expand Up @@ -947,7 +966,7 @@
},
"log_visibility": {
"title": "Log Visibility",
"description": "Specifies who is allowed to read the canister's logs.\n\nCan be \"public\" or \"controllers\".",
"description": "Specifies who is allowed to read the canister's logs.\n\nCan be \"public\", \"controllers\" or \"allowedviewers\" with a list of Principals.",
"anyOf": [
{
"$ref": "#/definitions/CanisterLogVisibility"
Expand Down
13 changes: 11 additions & 2 deletions src/dfx-core/src/config/model/dfinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,27 @@ impl CanisterTypeProperties {
}
}

#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum CanisterLogVisibility {
#[default]
Controllers,
Public,
AllowedViewers(Vec<String>),
}

impl From<CanisterLogVisibility> for LogVisibility {
fn from(value: CanisterLogVisibility) -> Self {
match value {
CanisterLogVisibility::Controllers => LogVisibility::Controllers,
CanisterLogVisibility::Public => LogVisibility::Public,
CanisterLogVisibility::AllowedViewers(viewers) => {
let principals: Vec<_> = viewers
.iter()
.map(|v| Principal::from_text(v).unwrap())
.collect();
LogVisibility::AllowedViewers(principals)
}
}
}
}
Expand Down Expand Up @@ -475,7 +483,7 @@ pub struct InitializationValues {
/// # Log Visibility
/// Specifies who is allowed to read the canister's logs.
///
/// Can be "public" or "controllers".
/// Can be "public", "controllers" or "allowedviewers" with a list of Principals.
#[schemars(with = "Option<CanisterLogVisibility>")]
pub log_visibility: Option<CanisterLogVisibility>,
}
Expand Down Expand Up @@ -1008,6 +1016,7 @@ impl ConfigInterface {
.map_err(|e| GetLogVisibilityFailed(canister_name.to_string(), e))?
.initialization_values
.log_visibility
.clone()
.map(|visibility| visibility.into()))
}

Expand Down

0 comments on commit faad6b3

Please sign in to comment.