Add support for NATS-style wildcard patterns in namespace subscriptions, enabling cross-namespace event handling for logging, monitoring, and auditing use cases.
Changes
Add pattern.go with MatchNamespacePattern and IsWildcardPattern functions
Update EventBus to handle wildcard subscribers separately from exact-match subscribers
Update NATSEventBus to leverage NATS native wildcard support for cross-node broadcasting
Add comprehensive tests for pattern matching (pattern_test.go) and EventBus wildcards (eventbus_test.go)
Document security implications throughout the codebase
Pattern Syntax
Following NATS subject matching conventions:
* matches exactly one token (dot-separated)
> matches one or more tokens (only at the end of a pattern)
Examples:
prod.* matches prod.tenant, prod.orders
prod.> matches prod.tenant, prod.tenant.orders
> matches all namespaces (catch-all)
Security Considerations
Wildcard subscriptions bypass namespace isolation. This is documented with warnings in:
## Summary
Add support for NATS-style wildcard patterns in namespace subscriptions, enabling cross-namespace event handling for logging, monitoring, and auditing use cases.
## Changes
- Add `pattern.go` with `MatchNamespacePattern` and `IsWildcardPattern` functions
- Update `EventBus` to handle wildcard subscribers separately from exact-match subscribers
- Update `NATSEventBus` to leverage NATS native wildcard support for cross-node broadcasting
- Add comprehensive tests for pattern matching (`pattern_test.go`) and EventBus wildcards (`eventbus_test.go`)
- Document security implications throughout the codebase
## Pattern Syntax
Following NATS subject matching conventions:
- `*` matches exactly one token (dot-separated)
- `>` matches one or more tokens (only at the end of a pattern)
Examples:
- `prod.*` matches `prod.tenant`, `prod.orders`
- `prod.>` matches `prod.tenant`, `prod.tenant.orders`
- `>` matches all namespaces (catch-all)
## Security Considerations
Wildcard subscriptions bypass namespace isolation. This is documented with warnings in:
- `EventBroadcaster` interface
- `EventBus` struct and `Subscribe` method
- `NATSEventBus` struct and `Subscribe` method
- `MatchNamespacePattern` function
Closes #20
Support NATS-style wildcard patterns ("*" and ">") for subscribing
to events across multiple namespaces. This enables cross-cutting
concerns like logging, monitoring, and auditing without requiring
separate subscriptions for each namespace.
- Add pattern.go with MatchNamespacePattern and IsWildcardPattern
- Update EventBus to track wildcard subscribers separately
- Update NATSEventBus to use NATS native wildcard support
- Add comprehensive tests for pattern matching and EventBus wildcards
- Document security implications in all relevant code comments
Closes#20
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This is an automated review generated by the code-reviewer agent.
Summary
This PR adds NATS-style wildcard pattern support for namespace subscriptions, enabling cross-namespace event handling for logging, monitoring, and auditing. The implementation is well-structured with comprehensive test coverage and appropriate security documentation.
Findings
Code Quality
Excellent separation of concerns: The new subscription struct and split between exactSubscribers and wildcardSubscribers is clean and maintainable
Clear pattern matching logic: The recursive matchTokens function in pattern.go is easy to follow
Good documentation: Extensive godoc comments with examples and security warnings throughout
Consistent naming: Pattern vs namespace distinction is clear in all function signatures
Minor observation: In nats_eventbus.go line ~799, the deliverToWildcardSubscribers function directly accesses neb.EventBus.wildcardSubscribers. While this works with embedding, it creates tight coupling. Consider adding a method to EventBus for this, though not blocking.
Potential Bugs
Channel closure in Unsubscribe: The channel is closed in Unsubscribe, but if the same channel is passed twice, the second call will panic on double-close. Current usage appears safe, but worth noting.
No validation of > placement: The pattern matching allows > anywhere in the pattern string during parsing (e.g., prod.>.tenant would be split into tokens). However, the matching logic only handles > correctly when it's the last pattern token. Consider adding validation in Subscribe to reject invalid patterns like prod.>.tenant early.
Security Concerns
Well-documented security implications: Every relevant interface and struct has clear warnings about wildcard subscriptions bypassing namespace isolation
No security vulnerabilities identified: Pattern matching doesn't allow injection or unexpected behavior
Good security hygiene: Documentation consistently emphasizes restricting wildcard access to trusted components
Style Notes
Consistent with codebase: Follows existing patterns and Go conventions
Test naming: Test names are descriptive and follow Go best practices
Formatting: Clean, properly indented, no style issues
Test Coverage
Comprehensive pattern matching tests: 23 test cases covering exact matches, wildcards, edge cases, and combinations
One gap: No integration test for NATSEventBus wildcard behavior across nodes. The local EventBus tests are thorough, but validating NATS subject wildcard integration would strengthen confidence.
Verdict
LGTM with minor suggestions
This is a solid implementation with excellent test coverage and thorough documentation. The pattern matching is correct, the EventBus refactoring maintains backward compatibility, and the security implications are well-documented. The minor observations about > validation and cross-node integration testing are suggestions for future improvement, not blockers.
The code is ready to merge.
## AI Code Review
> This is an automated review generated by the code-reviewer agent.
### Summary
This PR adds NATS-style wildcard pattern support for namespace subscriptions, enabling cross-namespace event handling for logging, monitoring, and auditing. The implementation is well-structured with comprehensive test coverage and appropriate security documentation.
### Findings
#### Code Quality
- **Excellent separation of concerns**: The new `subscription` struct and split between `exactSubscribers` and `wildcardSubscribers` is clean and maintainable
- **Clear pattern matching logic**: The recursive `matchTokens` function in `pattern.go` is easy to follow
- **Good documentation**: Extensive godoc comments with examples and security warnings throughout
- **Consistent naming**: Pattern vs namespace distinction is clear in all function signatures
- **Minor observation**: In `nats_eventbus.go` line ~799, the `deliverToWildcardSubscribers` function directly accesses `neb.EventBus.wildcardSubscribers`. While this works with embedding, it creates tight coupling. Consider adding a method to EventBus for this, though not blocking.
#### Potential Bugs
- **Channel closure in Unsubscribe**: The channel is closed in `Unsubscribe`, but if the same channel is passed twice, the second call will panic on double-close. Current usage appears safe, but worth noting.
- **No validation of `>` placement**: The pattern matching allows `>` anywhere in the pattern string during parsing (e.g., `prod.>.tenant` would be split into tokens). However, the matching logic only handles `>` correctly when it's the last pattern token. Consider adding validation in `Subscribe` to reject invalid patterns like `prod.>.tenant` early.
#### Security Concerns
- **Well-documented security implications**: Every relevant interface and struct has clear warnings about wildcard subscriptions bypassing namespace isolation
- **No security vulnerabilities identified**: Pattern matching doesn't allow injection or unexpected behavior
- **Good security hygiene**: Documentation consistently emphasizes restricting wildcard access to trusted components
#### Style Notes
- **Consistent with codebase**: Follows existing patterns and Go conventions
- **Test naming**: Test names are descriptive and follow Go best practices
- **Formatting**: Clean, properly indented, no style issues
#### Test Coverage
- **Comprehensive pattern matching tests**: 23 test cases covering exact matches, wildcards, edge cases, and combinations
- **EventBus integration tests**: 13 tests covering exact subscriptions, wildcard subscriptions, unsubscribe, isolation, concurrency, and non-blocking behavior
- **Performance consideration**: Includes benchmarks for pattern matching
- **Excellent coverage**: Tests cover happy paths, edge cases, error conditions, and concurrent operations
- **One gap**: No integration test for `NATSEventBus` wildcard behavior across nodes. The local EventBus tests are thorough, but validating NATS subject wildcard integration would strengthen confidence.
### Verdict
**LGTM with minor suggestions**
This is a solid implementation with excellent test coverage and thorough documentation. The pattern matching is correct, the EventBus refactoring maintains backward compatibility, and the security implications are well-documented. The minor observations about `>` validation and cross-node integration testing are suggestions for future improvement, not blockers.
The code is ready to merge.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Add support for NATS-style wildcard patterns in namespace subscriptions, enabling cross-namespace event handling for logging, monitoring, and auditing use cases.
Changes
pattern.gowithMatchNamespacePatternandIsWildcardPatternfunctionsEventBusto handle wildcard subscribers separately from exact-match subscribersNATSEventBusto leverage NATS native wildcard support for cross-node broadcastingpattern_test.go) and EventBus wildcards (eventbus_test.go)Pattern Syntax
Following NATS subject matching conventions:
*matches exactly one token (dot-separated)>matches one or more tokens (only at the end of a pattern)Examples:
prod.*matchesprod.tenant,prod.ordersprod.>matchesprod.tenant,prod.tenant.orders>matches all namespaces (catch-all)Security Considerations
Wildcard subscriptions bypass namespace isolation. This is documented with warnings in:
EventBroadcasterinterfaceEventBusstruct andSubscribemethodNATSEventBusstruct andSubscribemethodMatchNamespacePatternfunctionCloses #20
Support NATS-style wildcard patterns ("*" and ">") for subscribing to events across multiple namespaces. This enables cross-cutting concerns like logging, monitoring, and auditing without requiring separate subscriptions for each namespace. - Add pattern.go with MatchNamespacePattern and IsWildcardPattern - Update EventBus to track wildcard subscribers separately - Update NATSEventBus to use NATS native wildcard support - Add comprehensive tests for pattern matching and EventBus wildcards - Document security implications in all relevant code comments Closes #20 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>AI Code Review
Summary
This PR adds NATS-style wildcard pattern support for namespace subscriptions, enabling cross-namespace event handling for logging, monitoring, and auditing. The implementation is well-structured with comprehensive test coverage and appropriate security documentation.
Findings
Code Quality
subscriptionstruct and split betweenexactSubscribersandwildcardSubscribersis clean and maintainablematchTokensfunction inpattern.gois easy to follownats_eventbus.goline ~799, thedeliverToWildcardSubscribersfunction directly accessesneb.EventBus.wildcardSubscribers. While this works with embedding, it creates tight coupling. Consider adding a method to EventBus for this, though not blocking.Potential Bugs
Unsubscribe, but if the same channel is passed twice, the second call will panic on double-close. Current usage appears safe, but worth noting.>placement: The pattern matching allows>anywhere in the pattern string during parsing (e.g.,prod.>.tenantwould be split into tokens). However, the matching logic only handles>correctly when it's the last pattern token. Consider adding validation inSubscribeto reject invalid patterns likeprod.>.tenantearly.Security Concerns
Style Notes
Test Coverage
NATSEventBuswildcard behavior across nodes. The local EventBus tests are thorough, but validating NATS subject wildcard integration would strengthen confidence.Verdict
LGTM with minor suggestions
This is a solid implementation with excellent test coverage and thorough documentation. The pattern matching is correct, the EventBus refactoring maintains backward compatibility, and the security implications are well-documented. The minor observations about
>validation and cross-node integration testing are suggestions for future improvement, not blockers.The code is ready to merge.