fix(event): normalize shorthand event names before persisting notifications#67
fix(event): normalize shorthand event names before persisting notifications#67
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes rc event add so shorthand event tokens are normalized to concrete S3 event patterns before being persisted, ensuring RustFS notification matching works as expected (closes #65).
Changes:
- Normalize
--eventvalues inparse_event_list()(e.g.,put→s3:ObjectCreated:*) while keeping fully-qualified event names unchanged. - Preserve existing sorting + deduplication behavior after normalization.
- Add a unit test covering shorthand normalization and case-insensitivity.
💡 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 new String for every event via to_ascii_lowercase(), even when the value is already a fully-qualified S3 event name. Consider using eq_ignore_ascii_case(...) checks (or matching on value with AsciiExt-style comparisons) to avoid the extra allocation in the hot path, especially when many events are provided.
| 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() |
|
Reviewed the automated summary comment. It matches the implemented scope and does not include additional actionable change requests, so no follow-up code changes are needed at this stage. |
Related issue
Background
rc event add --event putstoredputliterally in bucket notification configuration. RustFS matches concrete S3 event patterns (for examples3:ObjectCreated:Put), so the shorthand token never matched and notifications were not emitted.Root cause
parse_event_list()incrates/cli/src/commands/event.rspassed--eventvalues through without normalization.Solution
event addparsing:put->s3:ObjectCreated:*get->s3:ObjectAccessed:*delete->s3:ObjectRemoved:*replica->s3:Replication:*ilm->s3:ObjectTransition:*Tests
test_parse_event_list_normalizes_shorthand_namesValidation
event listshowed-> put.event listshows-> s3:ObjectCreated:*.CI / Quality checks
cargo fmt --all --checkcargo clippy --workspace -- -D warningscargo test --workspace