1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Location: ./crates/apl-cpex/src/register.rs
// Copyright 2025
// SPDX-License-Identifier: Apache-2.0
// Authors: Teryl Taylor
//
// `register_apl` — sugar function that bundles "construct
// `AplConfigVisitor` + register it with the manager" into one call.
//
// Hosts that just want APL governance with sensible defaults call this
// instead of building the visitor by hand. The lower-level
// `PluginManager::register_visitor` API stays available for custom
// orchestrators (future Rego, Cedar-direct, hand-rolled audit visitors)
// that don't fit the APL setup.
//
// # Two ways to supply PDPs
//
// PDP resolvers can reach the visitor's internal `PdpRouter` via two
// channels, and `AplOptions` exposes both:
//
// * `pdps` — code-supplied resolvers. The host built them
// in Rust (e.g. a hand-rolled audit resolver,
// a test fake) and hands them in directly.
// * `pdp_factories` — factories the visitor consults when it sees a
// `global.apl.pdp[]` entry in the unified
// config. Each factory advertises a `kind()`
// string that matches the YAML block's `kind:`
// field.
//
// Both channels feed the same `PdpRouter` inside the visitor, so a
// host can mix the two freely — code-supplied Cedar for tests plus a
// config-declared OPA in prod, say.
use HashSet;
use Arc;
use PluginManager;
use ConfigVisitor;
use ;
use crateDispatchCache;
use crate;
use crateAplConfigVisitor;
/// Configuration for [`register_apl`]. All runtime collaborators APL
/// needs to do its work are funneled through here so the call site
/// reads as a single block instead of a multi-step builder.
/// Build an [`AplConfigVisitor`] from the supplied options and register
/// it on the manager. Returns the `Arc<AplConfigVisitor>` so the caller
/// can stash it for later inspection (or call `register_pdp` on it
/// after the fact for late-bound resolvers) — but in the typical case
/// the return value is dropped and the visitor lives inside the
/// manager's visitor list.
///
/// After this call, the next `mgr.load_config_yaml(yaml)` invocation
/// will walk the visitor: cpex-core's [`visit_plugins`][vp] populates
/// the APL plugin registry from `&[PluginConfig]`; `visit_global`
/// processes any `global.apl.pdp[]` entries by dispatching to the
/// registered `pdp_factories`; the hierarchy walk stacks `global.apl`
/// / `defaults.<entity>.apl` / `policies.<tag>.apl` / route-level
/// `apl:` into compiled routes; one `AplRouteHandler` is installed
/// per route per phase via [`PluginManager::annotate_route`][ar].
///
/// [vp]: cpex_core::visitor::ConfigVisitor::visit_plugins
/// [ar]: cpex_core::manager::PluginManager::annotate_route
///
/// # Example
///
/// ```ignore
/// use std::sync::Arc;
/// use cpex_core::manager::PluginManager;
/// use apl_cpex::{register_apl, AplOptions};
/// use cpex_pdp_cedar_direct::CedarDirectPdpFactory;
///
/// let mgr = Arc::new(PluginManager::default());
/// mgr.register_factory("scope-gate", Box::new(ScopeGateFactory));
///
/// apl_cpex::register_apl(&mgr, AplOptions {
/// dispatch_cache: dispatch_cache.clone(),
/// session_store: session_store.clone(),
/// pdps: vec![], // none code-supplied
/// pdp_factories: vec![Arc::new(CedarDirectPdpFactory::new())],
/// base_capabilities: None,
/// });
///
/// mgr.load_config_yaml(&yaml_string)?;
/// mgr.initialize().await?;
/// ```