Skip to main content

rustfs_policy/
policy.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
15pub mod action;
16mod doc;
17mod effect;
18mod function;
19mod id;
20#[allow(clippy::module_inception)]
21mod policy;
22mod principal;
23pub mod resource;
24pub mod statement;
25pub(crate) mod utils;
26
27pub use action::ActionSet;
28pub use doc::PolicyDoc;
29
30pub use effect::Effect;
31pub use function::Functions;
32pub use id::ID;
33pub use policy::*;
34pub use principal::Principal;
35pub use resource::ResourceSet;
36pub use statement::Statement;
37
38pub const EMBEDDED_POLICY_TYPE: &str = "embedded-policy";
39pub const INHERITED_POLICY_TYPE: &str = "inherited-policy";
40
41#[derive(thiserror::Error, Debug)]
42#[cfg_attr(test, derive(Eq, PartialEq))]
43pub enum Error {
44    #[error("invalid Version '{0}'")]
45    InvalidVersion(String),
46
47    #[error("invalid Effect '{0}'")]
48    InvalidEffect(String),
49
50    #[error("both 'Action' and 'NotAction' are empty")]
51    NonAction,
52
53    #[error("'Resource' is empty")]
54    NonResource,
55
56    #[error("invalid key name: '{0}'")]
57    InvalidKeyName(String),
58
59    #[error("invalid key: '{0}'")]
60    InvalidKey(String),
61
62    #[error("invalid action: '{0}'")]
63    InvalidAction(String),
64
65    #[error("invalid resource, type: '{0}', pattern: '{1}'")]
66    InvalidResource(String, String),
67}