Skip to main content

awsim_datasync/
lib.rs

1mod operations;
2mod state;
3
4pub use state::DataSyncState;
5
6use async_trait::async_trait;
7use awsim_core::{AccountRegionStore, AwsError, Protocol, RequestContext, ServiceHandler};
8use serde_json::Value;
9use tracing::debug;
10
11pub struct DataSyncService {
12    store: AccountRegionStore<DataSyncState>,
13}
14
15impl DataSyncService {
16    pub fn new() -> Self {
17        Self {
18            store: AccountRegionStore::new(),
19        }
20    }
21}
22
23impl Default for DataSyncService {
24    fn default() -> Self {
25        Self::new()
26    }
27}
28
29#[async_trait]
30impl ServiceHandler for DataSyncService {
31    fn service_name(&self) -> &str {
32        "datasync"
33    }
34
35    fn signing_name(&self) -> &str {
36        "datasync"
37    }
38
39    fn protocol(&self) -> Protocol {
40        Protocol::AwsJson1_1
41    }
42
43    async fn handle(
44        &self,
45        operation: &str,
46        input: Value,
47        ctx: &RequestContext,
48    ) -> Result<Value, AwsError> {
49        debug!(operation, "DataSync request");
50        let state = self.store.get(&ctx.account_id, &ctx.region);
51
52        match operation {
53            "CreateLocationS3" => operations::locations::create_location_s3(&state, &input, ctx),
54            "CreateLocationNfs" => operations::locations::create_location_nfs(&state, &input, ctx),
55            "CreateLocationSmb" => operations::locations::create_location_smb(&state, &input, ctx),
56            "CreateLocationEfs" => operations::locations::create_location_efs(&state, &input, ctx),
57            "DescribeLocationS3" => {
58                operations::locations::describe_location_s3(&state, &input, ctx)
59            }
60            "ListLocations" => operations::locations::list_locations(&state, &input, ctx),
61            "DeleteLocation" => operations::locations::delete_location(&state, &input, ctx),
62            "CreateTask" => operations::tasks::create_task(&state, &input, ctx),
63            "DescribeTask" => operations::tasks::describe_task(&state, &input, ctx),
64            "ListTasks" => operations::tasks::list_tasks(&state, &input, ctx),
65            "UpdateTask" => operations::tasks::update_task(&state, &input, ctx),
66            "DeleteTask" => operations::tasks::delete_task(&state, &input, ctx),
67            "StartTaskExecution" => {
68                operations::executions::start_task_execution(&state, &input, ctx)
69            }
70            "DescribeTaskExecution" => {
71                operations::executions::describe_task_execution(&state, &input, ctx)
72            }
73            "ListTaskExecutions" => {
74                operations::executions::list_task_executions(&state, &input, ctx)
75            }
76            "CancelTaskExecution" => {
77                operations::executions::cancel_task_execution(&state, &input, ctx)
78            }
79            _ => Err(AwsError::unknown_operation(operation)),
80        }
81    }
82}