mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-05 21:07:43 +00:00
2e14b32ccd
* chore: Add copyright and license headers This commit adds the Apache 2.0 license and a copyright notice to the header of all source files. This ensures that the licensing and copyright information is clearly stated within the codebase. * cargo fmt * fix * fmt * fix clippy
45 lines
1.5 KiB
Rust
45 lines
1.5 KiB
Rust
// Copyright 2024 RustFS Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use super::{error::BucketMetadataError, metadata_sys::get_bucket_metadata_sys};
|
|
use crate::error::Result;
|
|
use policy::policy::{BucketPolicy, BucketPolicyArgs};
|
|
use tracing::warn;
|
|
|
|
pub struct PolicySys {}
|
|
|
|
impl PolicySys {
|
|
pub async fn is_allowed(args: &BucketPolicyArgs<'_>) -> bool {
|
|
match Self::get(args.bucket).await {
|
|
Ok(cfg) => return cfg.is_allowed(args),
|
|
Err(err) => {
|
|
let berr: BucketMetadataError = err.into();
|
|
if berr != BucketMetadataError::BucketPolicyNotFound {
|
|
warn!("config get err {:?}", berr);
|
|
}
|
|
}
|
|
}
|
|
|
|
args.is_owner
|
|
}
|
|
pub async fn get(bucket: &str) -> Result<BucketPolicy> {
|
|
let bucket_meta_sys_lock = get_bucket_metadata_sys()?;
|
|
let bucket_meta_sys = bucket_meta_sys_lock.read().await;
|
|
|
|
let (cfg, _) = bucket_meta_sys.get_bucket_policy(bucket).await?;
|
|
|
|
Ok(cfg)
|
|
}
|
|
}
|