use std::{future::Future, pin::Pin};
use bytes::Bytes;
use rustack_sts_model::{error::StsError, operations::StsOperation};
use crate::body::StsResponseBody;
pub trait StsHandler: Send + Sync + 'static {
fn handle_operation(
&self,
op: StsOperation,
body: Bytes,
caller_access_key: Option<String>,
request_id: &str,
) -> Pin<Box<dyn Future<Output = Result<http::Response<StsResponseBody>, StsError>> + Send>>;
}
pub async fn dispatch_operation<H: StsHandler>(
handler: &H,
op: StsOperation,
body: Bytes,
caller_access_key: Option<String>,
request_id: &str,
) -> Result<http::Response<StsResponseBody>, StsError> {
tracing::debug!(operation = %op, "dispatching STS operation");
handler
.handle_operation(op, body, caller_access_key, request_id)
.await
}