mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-03 18:55:39 +00:00
fix(site-replication): sync IAM and bucket replication (#2671)
This commit is contained in:
@@ -19,7 +19,7 @@ use strum::{EnumString, IntoStaticStr};
|
||||
use super::Validator;
|
||||
|
||||
#[derive(Serialize, Clone, Deserialize, EnumString, IntoStaticStr, Default, Debug, PartialEq)]
|
||||
#[serde(try_from = "&str", into = "&str")]
|
||||
#[serde(try_from = "String", into = "&str")]
|
||||
pub enum Effect {
|
||||
#[default]
|
||||
#[strum(serialize = "Allow")]
|
||||
@@ -28,6 +28,16 @@ pub enum Effect {
|
||||
Deny,
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Effect {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: String) -> std::result::Result<Self, Self::Error> {
|
||||
value
|
||||
.parse::<Self>()
|
||||
.map_err(|e: strum::ParseError| Error::StringError(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Effect {
|
||||
pub fn is_allowed(&self, allowed: bool) -> bool {
|
||||
if matches!(self, Self::Allow) {
|
||||
|
||||
@@ -1761,4 +1761,28 @@ mod test {
|
||||
assert!(!found);
|
||||
assert!(policies.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_policy_round_trips_through_json_value() {
|
||||
let policy = Policy::parse_config(
|
||||
br#"{
|
||||
"Version":"2012-10-17",
|
||||
"Statement":[
|
||||
{
|
||||
"Effect":"Allow",
|
||||
"Action":["s3:GetObject"],
|
||||
"Resource":["arn:aws:s3:::bucket/*"]
|
||||
}
|
||||
]
|
||||
}"#,
|
||||
)
|
||||
.expect("policy should parse");
|
||||
|
||||
let value = serde_json::to_value(&policy).expect("policy should serialize");
|
||||
let round_trip: Policy = serde_json::from_value(value).expect("policy should deserialize from serde_json::Value");
|
||||
|
||||
assert_eq!(round_trip.version, policy.version);
|
||||
assert_eq!(round_trip.statements.len(), policy.statements.len());
|
||||
assert_eq!(round_trip.statements[0].effect, policy.statements[0].effect);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user