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;
20pub mod opa;
21#[allow(clippy::module_inception)]
22mod policy;
23mod principal;
24pub mod resource;
25pub mod statement;
26pub(crate) mod utils;
27pub mod variables;
28
29pub use action::ActionSet;
30pub use doc::PolicyDoc;
31pub use effect::Effect;
32pub use function::{Functions, is_server_derived_condition_key};
33pub use id::ID;
34pub use policy::*;
35pub use principal::Principal;
36pub use resource::ResourceSet;
37pub use statement::Statement;
38pub use utils::{ClaimLookup, get_claim_case_insensitive};
39
40#[derive(thiserror::Error, Debug)]
41#[cfg_attr(test, derive(Eq, PartialEq))]
42pub enum Error {
43    #[error("invalid Version '{0}'")]
44    InvalidVersion(String),
45
46    #[error("invalid Effect '{0}'")]
47    InvalidEffect(String),
48
49    #[error("both 'Action' and 'NotAction' are empty")]
50    NonAction,
51
52    #[error("'Action' and 'NotAction' cannot both be specified in the same statement")]
53    BothActionAndNotAction,
54
55    #[error("'Resource' is empty")]
56    NonResource,
57
58    #[error("'Resource' and 'NotResource' cannot both be specified in the same statement")]
59    BothResourceAndNotResource,
60
61    #[error("invalid key name: '{0}'")]
62    InvalidKeyName(String),
63
64    #[error("invalid key: '{0}'")]
65    InvalidKey(String),
66
67    #[error("invalid action: '{0}'")]
68    InvalidAction(String),
69
70    #[error("'Action' contains mixed action families in the same statement")]
71    MixedActionFamilies,
72
73    #[error("invalid resource, type: '{0}', pattern: '{1}'")]
74    InvalidResource(String, String),
75
76    #[error("KMS resources require a statement whose actions are all KMS actions")]
77    KmsResourceWithNonKmsAction,
78
79    #[error("bucket policies do not support KMS actions or resources")]
80    KmsUnsupportedInBucketPolicy,
81}