Skip to main content

awsim_core/
router.rs

1/// Context extracted from an incoming AWS API request.
2///
3/// Contains the account ID, region, service, and request metadata
4/// needed by service handlers to process the request.
5#[derive(Debug, Clone)]
6pub struct RequestContext {
7    /// AWS account ID (default: "000000000000" in bypass mode)
8    pub account_id: String,
9
10    /// AWS region (e.g., "us-east-1")
11    pub region: String,
12
13    /// Service name extracted from the request
14    pub service: String,
15
16    /// Access key ID (if present in Authorization header)
17    pub access_key: Option<String>,
18
19    /// Unique request ID for this API call
20    pub request_id: String,
21
22    /// HTTP method of the original request
23    pub method: String,
24
25    /// URI path of the original request
26    pub uri: String,
27
28    /// Internal event bus — present for requests routed through the gateway;
29    /// `None` in unit tests or any context where no bus was configured.
30    pub event_bus: Option<crate::events::EventBus>,
31}
32
33impl RequestContext {
34    pub fn new(service: impl Into<String>, region: impl Into<String>) -> Self {
35        Self {
36            account_id: "000000000000".to_string(),
37            region: region.into(),
38            service: service.into(),
39            access_key: None,
40            request_id: uuid::Uuid::new_v4().to_string(),
41            method: "POST".to_string(),
42            uri: "/".to_string(),
43            event_bus: None,
44        }
45    }
46
47    /// Returns an ARN prefix for this account and region.
48    /// e.g., "arn:aws:s3:us-east-1:000000000000"
49    pub fn arn_prefix(&self, service: &str) -> String {
50        format!(
51            "arn:aws:{}:{}:{}",
52            service, self.region, self.account_id
53        )
54    }
55}