diff options
Diffstat (limited to 'src/authorization')
| -rw-r--r-- | src/authorization/cedar_authorizer.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/authorization/cedar_authorizer.rs b/src/authorization/cedar_authorizer.rs index 230c10a8..5ed810a7 100644 --- a/src/authorization/cedar_authorizer.rs +++ b/src/authorization/cedar_authorizer.rs @@ -38,24 +38,29 @@ impl CedarAuthorizer { fn load_from( path: &std::path::Path, ) -> Result<cedar_policy::PolicySet, Box<dyn std::error::Error>> { - if !path.exists() || !path.is_dir() { + if !path.exists() { return Ok(cedar_policy::PolicySet::default()); } - let mut policies = cedar_policy::PolicySet::new(); - for entry in fs::read_dir(path)? { - let file_path = entry?.path(); - - if let Some(extension) = file_path.extension() { + if path.is_file() { + if let Some(extension) = path.extension() { if extension == "cedar" { - let content = fs::read_to_string(&file_path)?; - let file_policies = cedar_policy::PolicySet::from_str(&content)?; - policies.merge(&file_policies, true)?; + let content = fs::read_to_string(&path)?; + return Ok(cedar_policy::PolicySet::from_str(&content)?); } } } - Ok(policies) + if !path.is_dir() { + return Ok(cedar_policy::PolicySet::default()); + } + + let mut policies = cedar_policy::PolicySet::new(); + for entry in fs::read_dir(path)? { + let file_path = entry?.path(); + policies.merge(&Self::load_from(&file_path)?, true)?; + } + return Ok(policies); } fn map_from( |
