Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 156dc08

Browse files
committed
Clean up the default policy config data
1 parent f5b34b5 commit 156dc08

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

crates/cli/src/util.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,9 @@ pub async fn policy_factory_from_config(
114114
password: config.password_entrypoint.clone(),
115115
};
116116

117-
PolicyFactory::load(
118-
policy_file,
119-
config.data.clone().unwrap_or_default(),
120-
entrypoints,
121-
)
122-
.await
123-
.context("failed to load the policy")
117+
PolicyFactory::load(policy_file, config.data.clone(), entrypoints)
118+
.await
119+
.context("failed to load the policy")
124120
}
125121

126122
pub async fn templates_from_config(

crates/config/src/sections/policy.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ fn default_email_endpoint() -> String {
5656
"email/violation".to_owned()
5757
}
5858

59+
fn default_data() -> serde_json::Value {
60+
serde_json::json!({})
61+
}
62+
5963
/// Application secrets
6064
#[serde_as]
6165
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
@@ -86,8 +90,8 @@ pub struct PolicyConfig {
8690
pub email_entrypoint: String,
8791

8892
/// Arbitrary data to pass to the policy
89-
#[serde(default)]
90-
pub data: Option<serde_json::Value>,
93+
#[serde(default = "default_data")]
94+
pub data: serde_json::Value,
9195
}
9296

9397
impl Default for PolicyConfig {
@@ -99,7 +103,7 @@ impl Default for PolicyConfig {
99103
authorization_grant_entrypoint: default_authorization_grant_endpoint(),
100104
password_entrypoint: default_password_endpoint(),
101105
email_entrypoint: default_email_endpoint(),
102-
data: None,
106+
data: default_data(),
103107
}
104108
}
105109
}

docs/config.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
"authorization_grant_entrypoint": "authorization_grant/violation",
189189
"password_entrypoint": "password/violation",
190190
"email_entrypoint": "email/violation",
191-
"data": null
191+
"data": {}
192192
},
193193
"allOf": [
194194
{
@@ -1647,7 +1647,7 @@
16471647
},
16481648
"data": {
16491649
"description": "Arbitrary data to pass to the policy",
1650-
"default": null
1650+
"default": {}
16511651
}
16521652
}
16531653
},

0 commit comments

Comments
 (0)