rustfs_policy/policy/
principal.rs1use super::{Validator, utils::wildcard};
16use crate::error::{Error, Result};
17use serde::{Deserialize, Serialize};
18use std::collections::HashSet;
19
20#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
21#[serde(rename_all = "PascalCase", default)]
22pub struct Principal {
23 #[serde(rename = "AWS")]
24 aws: HashSet<String>,
25}
26
27impl Principal {
28 pub fn is_match(&self, parincipal: &str) -> bool {
29 for pattern in self.aws.iter() {
30 if wildcard::is_simple_match(pattern, parincipal) {
31 return true;
32 }
33 }
34 false
35 }
36}
37
38impl Validator for Principal {
39 type Error = Error;
40 fn is_valid(&self) -> Result<()> {
41 if self.aws.is_empty() {
42 return Err(Error::other("Principal is empty"));
43 }
44 Ok(())
45 }
46}