hyprstream_core/services/worker.rs
1//! Worker service types and helpers.
2//!
3//! Worker-service authorization glue. Public worker RPC contracts and clients
4//! are owned by `hyprstream-rpc-std`; this module contains no client facade.
5
6use hyprstream_rpc::service::AuthorizeFn;
7use hyprstream_rpc_std::policy_client::PolicyCheck;
8use std::sync::Arc;
9
10// ============================================================================
11// Authorization Helper
12// ============================================================================
13
14use hyprstream_rpc_std::policy_client::PolicyClient;
15
16/// Build an `AuthorizeFn` backed by a `PolicyClient`.
17///
18/// The returned closure is async-compatible (returns a boxed future) so it
19/// works on single-threaded runtimes used by RequestService.
20pub fn build_authorize_fn(policy_client: PolicyClient) -> AuthorizeFn {
21 Arc::new(
22 move |ctx: hyprstream_rpc::service::EnvelopeContext,
23 resource: String,
24 operation: String| {
25 let client = policy_client.clone();
26 Box::pin(async move {
27 let upstream_subject = ctx.subject();
28 let request = PolicyCheck {
29 subject: upstream_subject.to_string(),
30 // Compatibility fields only; Policy derives the domain
31 // from independently verified caller evidence.
32 domain: String::new(),
33 resource,
34 operation,
35 };
36 crate::services::policy::check_with_holder_evidence(
37 &client,
38 &request,
39 ctx.jwt_token(),
40 &upstream_subject,
41 ctx.original_holder_evidence(),
42 )
43 .await
44 })
45 },
46 )
47}
48
49// WorkerZmqClient / attach_container removed — use
50// `hyprstream_rpc_std::worker_client::WorkerClient` directly (DH key exchange
51// is encapsulated by the canonical client codegen).