Skip to main content

awsim_core/
lib.rs

1pub mod auth;
2pub mod authz;
3pub mod body;
4pub mod body_store;
5pub mod error;
6pub mod events;
7pub mod gateway;
8pub mod persistence;
9pub mod protocol;
10pub mod request_detail;
11pub mod request_event;
12pub mod router;
13pub mod state;
14
15pub use authz::{
16    AuthzEngine, GrantLookup, NoopPrincipalLookup, PrincipalLookup, ResolvedPrincipal,
17    ResourcePolicyLookup, ScpLookup,
18};
19pub use body::Body;
20pub use body_store::{BlobInventory, BodyStore};
21pub use error::AwsError;
22pub use events::{EventBus, InternalEvent};
23pub use gateway::{AppState, BodyStoreHandle};
24pub use persistence::PersistenceManager;
25pub use protocol::{Protocol, RouteDefinition};
26pub use request_detail::{
27    CapturedBody, CapturedHeader, DEFAULT_BODY_CAP, DEFAULT_RING_CAPACITY, RequestDetail,
28    RequestDetailStore, capture_body, capture_headers,
29};
30pub use request_event::{RequestEvent, RequestEventBus};
31pub use router::RequestContext;
32pub use state::{AccountRegionStore, Snapshottable};
33
34use serde_json::Value;
35
36/// Trait that every AWS service crate must implement.
37///
38/// Each service (S3, SQS, DynamoDB, etc.) implements this trait in its own crate.
39/// The main `awsim` binary registers all service handlers with the gateway router.
40#[async_trait::async_trait]
41pub trait ServiceHandler: Send + Sync {
42    /// The AWS service name (e.g., "s3", "sqs", "dynamodb").
43    fn service_name(&self) -> &str;
44
45    /// The signing name used in SigV4 Authorization headers.
46    /// Usually the same as service_name, but not always.
47    fn signing_name(&self) -> &str {
48        self.service_name()
49    }
50
51    /// The primary protocol this service uses.
52    fn protocol(&self) -> Protocol;
53
54    /// Route definitions for REST-protocol services.
55    /// Not needed for RPC-style protocols (awsJson, awsQuery).
56    fn routes(&self) -> Vec<RouteDefinition> {
57        Vec::new()
58    }
59
60    /// Handle an AWS API operation.
61    async fn handle(
62        &self,
63        operation: &str,
64        input: Value,
65        ctx: &RequestContext,
66    ) -> Result<Value, AwsError>;
67
68    /// Serialize the service's state to bytes for persistence.
69    ///
70    /// Return `None` if this service does not support snapshots.
71    fn snapshot(&self) -> Option<Vec<u8>> {
72        None
73    }
74
75    /// Restore the service's state from a previous snapshot.
76    ///
77    /// The default implementation is a no-op and always succeeds.
78    fn restore(&self, _data: &[u8]) -> Result<(), String> {
79        Ok(())
80    }
81
82    fn iam_action(&self, _operation: &str) -> Option<String> {
83        None
84    }
85
86    fn iam_resource(
87        &self,
88        _operation: &str,
89        _input: &serde_json::Value,
90        _ctx: &router::RequestContext,
91    ) -> Option<String> {
92        None
93    }
94}