feat: CPEX Rust config#38
Conversation
araujof
left a comment
There was a problem hiding this comment.
Nice work, @terylt!
Overall,
- Trust model enforcement is consistent: config loader -> manager -> PluginRef -> executor, never from plugin.
- The
Arc-based route cache withraw_entryzero-allocation hits is a good optimization. - Test coverage spans all execution modes, error behaviors, routing resolution, and cache behavior.
- The 5-phase executor design is clean and the phase separation is well-enforced.
A few minor comments, let me know if they are planned in a next PR, or if you want to address them here.
Issues
1. Glob matching is overly simplistic (config.rs)
StringOrList::matches() only handles suffix wildcards (prefix*). Was that intentional?
let prefix = pattern.trim_end_matches('*');
name.starts_with(prefix)This silently mismatches on interior or leading globs. Either document that only trailing * is supported, or use a glob crate (e.g., glob-match).
2. from_config duplicates load_config logic (manager.rs)
from_config() and load_config() have the same plugin instantiation loop and executor setup, but diverged implementations. Consider having from_config delegate to load_config internally.
3. RwLock::unwrap() will panic on poisoned lock (manager.rs)
If a thread panics while holding the write lock, all subsequent unwrap() calls will panic too, cascading across the system. Since this is a library crate consumed by others, consider using .read().unwrap_or_else(|e| e.into_inner()) (or parking_lot::RwLock which is non-poisoning and already a transitive dep via tokio).
4. find_matching_route returns only the single best route (config.rs)
If two routes have equal specificity for the same entity, the last one in config order wins (due to total > s using strict greater-than). This is deterministic but not documented, and could surprise users. Consider either documenting "first wins on tie" or returning all tied routes.
5. serde_yaml is deprecated (Cargo.toml)
The serde_yaml crate is deprecated in favor of alternatives. Not blocking, but worth noting for future migration planning (e.g., serde_yml or yaml-rust2 + manual serde).
Suggestions (non-blocking)
-
create_override_instancesilently falls back (manager.rs): when factory creation fails, it logs an error and returnsNone, causing the base instance to fire with the original config. This could mask misconfigurations. Consider propagating the error or at minimum emitting awarn!with the route context. -
FilteredExtensionsis alwaysdefault()(executor.rs): the TODO is fine for Phase 1, but sincemetais needed for route resolution and plugins might want to read it, you could pass throughmetain the filtered view now. Currently plugins can't see the meta extension that drives their own dispatch. -
Shutdown in reverse order (
manager.rs): the comment says "reverse registration order" butplugin_names()returns insertion order. If you want reverse, call.rev()on the iterator.
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
|
LGTM. Fixes to this PR will fold into #45. |
* feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com>
* feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com>
* feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com>
* feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com>
* feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com>
* feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com>
* feat: initial Rust Core (cpex-core and cpex-sdk) (#13) * feat: initial revision rust core. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: addressed comments in PR. Updated PluginContext to match spec. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com> * feat: CPEX Rust config (#38) * feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com> * feat: RUST with CMF and extensions. (#44) * feat: initial revision rust core. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: addressed comments in PR. Updated PluginContext to match spec. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: RUST CMF initial revision. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added invoke named support, added constants, fixed reviewed code. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added owned extensions and did some refactoring. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com> * feat: cgo Go bindings (#45) * feat: initial revision rust core. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: addressed comments in PR. Updated PluginContext to match spec. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added yaml and routing rule support. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added example code to show how to load manager and plugins. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fixes: updated plugin errors, configs to more match python. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: RUST CMF initial revision. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added invoke named support, added constants, fixed reviewed code. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added owned extensions and did some refactoring. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added cgo and golang bindings, examples and readme. Signed-off-by: Teryl Taylor <terylt@ibm.com> * address P0/P1/P2 review findings (except #17) Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: address remaining P2/P3 review findings + testing gaps Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: add CPEX Go public API spec Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * docs: renamed document Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * feat(cpex-rust): CGO review passes 1-11 + lint cleanup + Makefile targets Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: address linting issues, updated makefile to support building examples. Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: updated the go spec to reflect recent changes. Signed-off-by: Teryl Taylor <terylt@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> Co-authored-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com> * docs: intial rust specification (#50) Co-authored-by: Teryl Taylor <terylt@ibm.com> * feat: change Plugin handler to async for performance (#49) Co-authored-by: Teryl Taylor <terylt@ibm.com> * fix: missing cmf-demo main.go file and gitignore fix that missed it (#52) Co-authored-by: Teryl Taylor <terylt@ibm.com> * feat: initial APL Rust implementation (#60) * fix: initial revision APL. * feat: apl-cpex bridge crate + plugin-registry-driven hook dispatch * feat: add support for plugin calling in APL routes. * feat: add more APL plugin support, unified config * feat: added cedar direct PDP. * feat: add identity hook and extensions. * feat: added token delegation hooks and tests. * feat: added plugin for jwt token identity, oauth and biscuit delegation, cedarling PDP. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: updated identity and delegation to support keycloak. added delegate() function, and identity sections. * fix: added some sample plugins, added updates to support cedar. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added session support, serialize and parallel and full effects capabilities. * feat: add ffi pre-built .a library Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: add workflow_dispatch target Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: critical and high issues from review. * feat: add APL FFI and go bindings Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: add musl tools to musl runners Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: potential double free after use bug. * chore: update Go module paths after repo rename to cpex * feat: map identity extension into cpex ffi Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * feat: add cpex_invoke_resolved abi Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: has_hook_for handling Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: update headers Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: session binding Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: updated comments Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * tests: added more session tests for Tier 1 ids. --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> Co-authored-by: terylt <30874627+terylt@users.noreply.github.com> Co-authored-by: Teryl Taylor <terylt@ibm.com>
Summary
Adds config-driven plugin management to the CPEX Rust core. Plugins, policy groups, and routing rules are declared in
a single YAML config. The manager resolves routes at dispatch time based on entity metadata in extensions, with cached
lookups for high-throughput use cases.
Built on top of feat/cpex_rust_core (async invoke, PluginContextTable, OnError::Disable, etc.).
Config parser — Parses a unified YAML format with
plugins,policy_groups, androutessections. Routes matchentities by exact name, name list, glob, or wildcard with specificity-based resolution (exact 1000 > list 500 > glob
300 > wildcard 0). Scope filtering, tag merging (union), and
whenclauses (carried for APL evaluation) aresupported. Validation at parse time rejects duplicate plugins, unknown plugin refs, and malformed routes.
Factory system —
PluginFactorytrait mapskindstrings to plugin constructors.from_config(yaml, factories)builds a fully wired
PluginManagerfrom YAML. Routes can override plugin config; the factory creates new instanceswith merged config.
Route-filtered dispatch —
invoke_by_nameandinvoke::<H>resolve routes viaMetaExtension(entity_type,entity_name, scope, tags) before dispatching. When routing is disabled or meta is absent, all registered plugins fire.
Route cache —
RwLock<HashMap<RouteCacheKey, Arc<Vec<HookEntry>>>>with hashbrownraw_entryfor zero-allocationcache hits and
Arcfor zero-copy reads. Keyed by (entity_type, entity_name, hook_name, scope).clear_route_cache()for config reload.MetaExtension — Added to
Extensionswith entity_type, entity_name, tags, scope, and properties. Used by therouting system to identify which entity a hook invocation targets.
Closes: #16
Changes
config.rs— Unified YAML config parser with plugins, policy groups, routes, specificity-based resolution, scopematching, tag merging, and validation
factory.rs—PluginFactorytrait andPluginFactoryRegistryfor config-driven plugin instantiationmanager.rs—from_config/load_config, route-filtered dispatch, hashbrown route cache withArczero-copyreads, override instances with merged config,
clear_route_cachehooks/payload.rs—MetaExtension(entity_type, entity_name, tags, scope, properties) onExtensionsregistry.rs—register_for_names_with_handlerfor factory path (noHookTypeDeftype parameter required)lib.rs— AddedfactorymoduleCargo.toml— Addedhashbrowndependency