fakecloud_lambda/
state.rs1use chrono::{DateTime, Utc};
2use parking_lot::RwLock;
3use std::collections::HashMap;
4use std::sync::Arc;
5
6#[derive(Debug, Clone)]
7pub struct LambdaFunction {
8 pub function_name: String,
9 pub function_arn: String,
10 pub runtime: String,
11 pub role: String,
12 pub handler: String,
13 pub description: String,
14 pub timeout: i64,
15 pub memory_size: i64,
16 pub code_sha256: String,
17 pub code_size: i64,
18 pub version: String,
19 pub last_modified: DateTime<Utc>,
20 pub tags: HashMap<String, String>,
21 pub environment: HashMap<String, String>,
22 pub architectures: Vec<String>,
23 pub package_type: String,
24 pub code_zip: Option<Vec<u8>>,
25}
26
27#[derive(Debug, Clone)]
28pub struct EventSourceMapping {
29 pub uuid: String,
30 pub function_arn: String,
31 pub event_source_arn: String,
32 pub batch_size: i64,
33 pub enabled: bool,
34 pub state: String,
35 pub last_modified: DateTime<Utc>,
36}
37
38#[derive(Debug, Clone)]
40pub struct LambdaInvocation {
41 pub function_arn: String,
42 pub payload: String,
43 pub timestamp: DateTime<Utc>,
44 pub source: String,
45}
46
47pub struct LambdaState {
48 pub account_id: String,
49 pub region: String,
50 pub functions: HashMap<String, LambdaFunction>,
51 pub event_source_mappings: HashMap<String, EventSourceMapping>,
52 pub invocations: Vec<LambdaInvocation>,
54}
55
56impl LambdaState {
57 pub fn new(account_id: &str, region: &str) -> Self {
58 Self {
59 account_id: account_id.to_string(),
60 region: region.to_string(),
61 functions: HashMap::new(),
62 event_source_mappings: HashMap::new(),
63 invocations: Vec::new(),
64 }
65 }
66
67 pub fn reset(&mut self) {
68 self.functions.clear();
69 self.event_source_mappings.clear();
70 self.invocations.clear();
71 }
72}
73
74pub type SharedLambdaState = Arc<RwLock<LambdaState>>;