fix(event): normalize shorthand notification event names#66
fix(event): normalize shorthand notification event names#66
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes rc event add --event <shorthand> persisting literal shorthand values by normalizing supported shorthands into S3 notification event patterns, ensuring saved rules match incoming RustFS events (closes #65).
Changes:
- Normalize shorthand event names (
put/get/delete/replica/ilm, case-insensitive) inparse_event_list(). - Add a focused unit test to lock in shorthand normalization + dedup/sort behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| match value.to_ascii_lowercase().as_str() { | ||
| "put" => "s3:ObjectCreated:*".to_string(), | ||
| "get" => "s3:ObjectAccessed:*".to_string(), | ||
| "delete" => "s3:ObjectRemoved:*".to_string(), | ||
| "replica" => "s3:Replication:*".to_string(), | ||
| "ilm" => "s3:ObjectTransition:*".to_string(), | ||
| _ => value.to_string(), |
There was a problem hiding this comment.
normalize_event_name() allocates a lowercase String for matching (to_ascii_lowercase) and then allocates again for the returned String (even in the non-shorthand _ case). This does unnecessary work for a CLI parse path; consider avoiding the temporary allocation by matching with eq_ignore_ascii_case (or matching on ASCII bytes) and only allocating the output once.
| match value.to_ascii_lowercase().as_str() { | |
| "put" => "s3:ObjectCreated:*".to_string(), | |
| "get" => "s3:ObjectAccessed:*".to_string(), | |
| "delete" => "s3:ObjectRemoved:*".to_string(), | |
| "replica" => "s3:Replication:*".to_string(), | |
| "ilm" => "s3:ObjectTransition:*".to_string(), | |
| _ => value.to_string(), | |
| if value.eq_ignore_ascii_case("put") { | |
| "s3:ObjectCreated:*".to_string() | |
| } else if value.eq_ignore_ascii_case("get") { | |
| "s3:ObjectAccessed:*".to_string() | |
| } else if value.eq_ignore_ascii_case("delete") { | |
| "s3:ObjectRemoved:*".to_string() | |
| } else if value.eq_ignore_ascii_case("replica") { | |
| "s3:Replication:*".to_string() | |
| } else if value.eq_ignore_ascii_case("ilm") { | |
| "s3:ObjectTransition:*".to_string() | |
| } else { | |
| value.to_string() |
|
Closing as duplicate of #67, which contains the same fix with slightly broader test coverage. |
Summary
Fixes
rc event add --event putstoring shorthand names literally instead of normalizing to S3 event patterns.Closes #65.
Problem
parse_event_list()passed--eventvalues through unchanged. As a result, shorthand values such asputwere persisted as-is in bucket notification configuration and never matched incoming RustFS events likes3:ObjectCreated:Put.Root Cause
Event normalization for shorthand names was missing in
crates/cli/src/commands/event.rs.Solution
normalize_event_name()in the event command parser.put->s3:ObjectCreated:*get->s3:ObjectAccessed:*delete->s3:ObjectRemoved:*replica->s3:Replication:*ilm->s3:ObjectTransition:*test_parse_event_list_normalizes_shorthand_eventsto lock behavior and dedup semantics.Validation
Docker Reproduction (before fix)
rustfs/rustfs:latestin Docker.Docker Verification (after fix)
rustfs/rustfs:latest.Quality Gates
cargo fmt --all --check cargo clippy --workspace -- -D warnings cargo test --workspaceAll passed.