fix(site-replication): sync IAM and bucket replication (#2671)

This commit is contained in:
cxymds
2026-04-25 09:33:43 +08:00
committed by GitHub
parent d949d4e794
commit 94f64acc87
8 changed files with 1291 additions and 35 deletions
+11 -1
View File
@@ -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) {
+24
View File
@@ -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);
}
}