mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-28 07:57:01 +00:00
rewrite iam
This commit is contained in:
+23
-12
@@ -1,8 +1,10 @@
|
||||
use crate::sys::{Args, Validator};
|
||||
|
||||
use super::{action::Action, ActionSet, Effect, Error as IamError, Functions, ResourceSet, ID};
|
||||
use ecstore::error::{Error, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{action::Action, ActionSet, Args, Effect, Error, Functions, ResourceSet, Validator, ID};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
|
||||
pub struct Statement {
|
||||
pub sid: ID,
|
||||
pub effect: Effect,
|
||||
@@ -60,17 +62,15 @@ impl Statement {
|
||||
resource.push('/');
|
||||
}
|
||||
|
||||
if self.is_kms() {
|
||||
if resource == "/" || self.resources.is_empty() {
|
||||
break 'c self.conditions.evaluate(&args.conditions);
|
||||
}
|
||||
if self.is_kms() && (resource == "/" || self.resources.is_empty()) {
|
||||
break 'c self.conditions.evaluate(args.conditions);
|
||||
}
|
||||
|
||||
if !self.resources.is_match(&resource, &args.conditions) && !self.is_admin() && !self.is_sts() {
|
||||
if !self.resources.is_match(&resource, args.conditions) && !self.is_admin() && !self.is_sts() {
|
||||
break 'c false;
|
||||
}
|
||||
|
||||
self.conditions.evaluate(&args.conditions)
|
||||
self.conditions.evaluate(args.conditions)
|
||||
};
|
||||
|
||||
self.effect.is_allowed(check)
|
||||
@@ -78,17 +78,18 @@ impl Statement {
|
||||
}
|
||||
|
||||
impl Validator for Statement {
|
||||
fn is_valid(&self) -> Result<(), Error> {
|
||||
type Error = Error;
|
||||
fn is_valid(&self) -> Result<()> {
|
||||
self.effect.is_valid()?;
|
||||
// check sid
|
||||
self.sid.is_valid()?;
|
||||
|
||||
if self.actions.is_empty() || self.not_actions.is_empty() {
|
||||
return Err(Error::NonAction);
|
||||
return Err(IamError::NonAction.into());
|
||||
}
|
||||
|
||||
if self.resources.is_empty() {
|
||||
return Err(Error::NonResource);
|
||||
return Err(IamError::NonResource.into());
|
||||
}
|
||||
|
||||
self.actions.is_valid()?;
|
||||
@@ -98,3 +99,13 @@ impl Validator for Statement {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Statement {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.effect == other.effect
|
||||
&& self.actions == other.actions
|
||||
&& self.not_actions == other.not_actions
|
||||
&& self.resources == other.resources
|
||||
&& self.conditions == other.conditions
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user