rustfs_policy/policy/effect.rs
1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::error::{Error, Result};
16use serde::{Deserialize, Serialize};
17use strum::{EnumString, IntoStaticStr};
18
19use super::Validator;
20
21#[derive(Serialize, Clone, Deserialize, EnumString, IntoStaticStr, Default, Debug, PartialEq)]
22#[serde(try_from = "&str", into = "&str")]
23pub enum Effect {
24 #[default]
25 #[strum(serialize = "Allow")]
26 Allow,
27 #[strum(serialize = "Deny")]
28 Deny,
29}
30
31impl Effect {
32 pub fn is_allowed(&self, allowed: bool) -> bool {
33 if matches!(self, Self::Allow) {
34 return allowed;
35 }
36
37 !allowed
38 }
39}
40
41impl Validator for Effect {
42 type Error = Error;
43 fn is_valid(&self) -> Result<()> {
44 Ok(())
45 }
46}