Skip to main content

rustack_sts_http/
dispatch.rs

1//! STS handler trait and operation dispatch.
2
3use std::{future::Future, pin::Pin};
4
5use bytes::Bytes;
6use rustack_sts_model::{error::StsError, operations::StsOperation};
7
8use crate::body::StsResponseBody;
9
10/// Trait that the STS business logic provider must implement.
11///
12/// The handler receives a parsed operation enum, the raw form body bytes,
13/// and the caller's access key extracted from the SigV4 Authorization header.
14pub trait StsHandler: Send + Sync + 'static {
15    /// Handle an STS operation and produce an HTTP response.
16    fn handle_operation(
17        &self,
18        op: StsOperation,
19        body: Bytes,
20        caller_access_key: Option<String>,
21        request_id: &str,
22    ) -> Pin<Box<dyn Future<Output = Result<http::Response<StsResponseBody>, StsError>> + Send>>;
23}
24
25/// Dispatch an STS operation to the handler.
26pub async fn dispatch_operation<H: StsHandler>(
27    handler: &H,
28    op: StsOperation,
29    body: Bytes,
30    caller_access_key: Option<String>,
31    request_id: &str,
32) -> Result<http::Response<StsResponseBody>, StsError> {
33    tracing::debug!(operation = %op, "dispatching STS operation");
34    handler
35        .handle_operation(op, body, caller_access_key, request_id)
36        .await
37}