Skip to main content

fakecloud_logs/
state.rs

1use std::collections::HashMap;
2use std::sync::Arc;
3
4use parking_lot::RwLock;
5
6pub type SharedLogsState = Arc<RwLock<LogsState>>;
7
8pub struct LogsState {
9    pub account_id: String,
10    pub region: String,
11    pub log_groups: HashMap<String, LogGroup>,
12    pub metric_filters: Vec<MetricFilter>,
13    pub resource_policies: HashMap<String, ResourcePolicy>,
14    pub destinations: HashMap<String, Destination>,
15    pub queries: HashMap<String, QueryInfo>,
16    pub export_tasks: Vec<ExportTask>,
17    pub delivery_destinations: HashMap<String, DeliveryDestination>,
18    pub delivery_sources: HashMap<String, DeliverySource>,
19    pub deliveries: HashMap<String, Delivery>,
20    pub query_definitions: HashMap<String, QueryDefinition>,
21    /// Account policies keyed by (policy_name, policy_type)
22    pub account_policies: HashMap<(String, String), AccountPolicy>,
23    /// Anomaly detectors keyed by detector ARN
24    pub anomaly_detectors: HashMap<String, AnomalyDetector>,
25    /// Import tasks keyed by import ID
26    pub import_tasks: HashMap<String, ImportTask>,
27    /// Integrations keyed by integration name
28    pub integrations: HashMap<String, Integration>,
29    /// Lookup tables keyed by ARN
30    pub lookup_tables: HashMap<String, LookupTable>,
31    /// Scheduled queries keyed by identifier (ARN)
32    pub scheduled_queries: HashMap<String, ScheduledQuery>,
33    /// S3 table integration sources keyed by integration ARN -> list of source identifiers
34    pub s3_table_sources: HashMap<String, Vec<String>>,
35    /// Bearer token authentication flag per log group
36    pub bearer_token_auth: HashMap<String, bool>,
37    /// Internal export storage: keyed by "bucket/prefix/..." path, value is exported data.
38    /// Used by CreateExportTask and delivery pipeline when direct S3 access is unavailable.
39    pub export_storage: HashMap<String, Vec<u8>>,
40}
41
42impl LogsState {
43    pub fn new(account_id: &str, region: &str) -> Self {
44        Self {
45            account_id: account_id.to_string(),
46            region: region.to_string(),
47            log_groups: HashMap::new(),
48            metric_filters: Vec::new(),
49            resource_policies: HashMap::new(),
50            destinations: HashMap::new(),
51            queries: HashMap::new(),
52            export_tasks: Vec::new(),
53            delivery_destinations: HashMap::new(),
54            delivery_sources: HashMap::new(),
55            deliveries: HashMap::new(),
56            query_definitions: HashMap::new(),
57            account_policies: HashMap::new(),
58            anomaly_detectors: HashMap::new(),
59            import_tasks: HashMap::new(),
60            integrations: HashMap::new(),
61            lookup_tables: HashMap::new(),
62            scheduled_queries: HashMap::new(),
63            s3_table_sources: HashMap::new(),
64            bearer_token_auth: HashMap::new(),
65            export_storage: HashMap::new(),
66        }
67    }
68
69    pub fn reset(&mut self) {
70        self.log_groups.clear();
71        self.metric_filters.clear();
72        self.resource_policies.clear();
73        self.destinations.clear();
74        self.queries.clear();
75        self.export_tasks.clear();
76        self.delivery_destinations.clear();
77        self.delivery_sources.clear();
78        self.deliveries.clear();
79        self.query_definitions.clear();
80        self.account_policies.clear();
81        self.anomaly_detectors.clear();
82        self.import_tasks.clear();
83        self.integrations.clear();
84        self.lookup_tables.clear();
85        self.scheduled_queries.clear();
86        self.s3_table_sources.clear();
87        self.bearer_token_auth.clear();
88        self.export_storage.clear();
89    }
90}
91
92pub struct LogGroup {
93    pub name: String,
94    pub arn: String,
95    pub creation_time: i64,
96    pub retention_in_days: Option<i32>,
97    pub kms_key_id: Option<String>,
98    pub tags: HashMap<String, String>,
99    pub log_streams: HashMap<String, LogStream>,
100    pub stored_bytes: i64,
101    pub subscription_filters: Vec<SubscriptionFilter>,
102    pub data_protection_policy: Option<DataProtectionPolicy>,
103    pub index_policies: Vec<IndexPolicy>,
104    pub transformer: Option<Transformer>,
105    pub deletion_protection: bool,
106    /// `STANDARD` (default), `INFREQUENT_ACCESS`, or `DELIVERY`. Set at
107    /// creation time via `CreateLogGroup`'s `logGroupClass` parameter.
108    /// Tracked here so `DescribeLogGroups` round-trips it correctly.
109    pub log_group_class: Option<String>,
110}
111
112pub struct LogStream {
113    pub name: String,
114    pub arn: String,
115    pub creation_time: i64,
116    pub first_event_timestamp: Option<i64>,
117    pub last_event_timestamp: Option<i64>,
118    pub last_ingestion_time: Option<i64>,
119    pub upload_sequence_token: String,
120    pub events: Vec<LogEvent>,
121}
122
123#[derive(Clone)]
124pub struct LogEvent {
125    pub timestamp: i64,
126    pub message: String,
127    pub ingestion_time: i64,
128}
129
130pub struct SubscriptionFilter {
131    pub filter_name: String,
132    pub log_group_name: String,
133    pub filter_pattern: String,
134    pub destination_arn: String,
135    pub role_arn: Option<String>,
136    pub distribution: String,
137    pub creation_time: i64,
138}
139
140pub struct MetricFilter {
141    pub filter_name: String,
142    pub filter_pattern: String,
143    pub log_group_name: String,
144    pub metric_transformations: Vec<MetricTransformation>,
145    pub creation_time: i64,
146}
147
148pub struct MetricTransformation {
149    pub metric_name: String,
150    pub metric_namespace: String,
151    pub metric_value: String,
152    pub default_value: Option<f64>,
153}
154
155pub struct ResourcePolicy {
156    pub policy_name: String,
157    pub policy_document: String,
158    pub last_updated_time: i64,
159}
160
161pub struct Destination {
162    pub destination_name: String,
163    pub target_arn: String,
164    pub role_arn: String,
165    pub arn: String,
166    pub access_policy: Option<String>,
167    pub creation_time: i64,
168    pub tags: HashMap<String, String>,
169}
170
171pub struct QueryInfo {
172    pub query_id: String,
173    pub log_group_name: String,
174    pub query_string: String,
175    pub start_time: i64,
176    pub end_time: i64,
177    pub status: String,
178    pub create_time: i64,
179}
180
181pub struct ExportTask {
182    pub task_id: String,
183    pub task_name: Option<String>,
184    pub log_group_name: String,
185    pub log_stream_name_prefix: Option<String>,
186    pub from_time: i64,
187    pub to_time: i64,
188    pub destination: String,
189    pub destination_prefix: String,
190    pub status_code: String,
191    pub status_message: String,
192}
193
194pub struct DeliveryDestination {
195    pub name: String,
196    pub arn: String,
197    pub output_format: Option<String>,
198    pub delivery_destination_configuration: HashMap<String, String>,
199    pub tags: HashMap<String, String>,
200    pub delivery_destination_policy: Option<String>,
201}
202
203pub struct DeliverySource {
204    pub name: String,
205    pub arn: String,
206    pub resource_arns: Vec<String>,
207    pub service: String,
208    pub log_type: String,
209    pub tags: HashMap<String, String>,
210}
211
212pub struct Delivery {
213    pub id: String,
214    pub delivery_source_name: String,
215    pub delivery_destination_arn: String,
216    pub delivery_destination_type: String,
217    pub arn: String,
218    pub tags: HashMap<String, String>,
219}
220
221pub struct QueryDefinition {
222    pub query_definition_id: String,
223    pub name: String,
224    pub query_string: String,
225    pub log_group_names: Vec<String>,
226    pub last_modified: i64,
227}
228
229pub struct AccountPolicy {
230    pub policy_name: String,
231    pub policy_type: String,
232    pub policy_document: String,
233    pub scope: Option<String>,
234    pub selection_criteria: Option<String>,
235    pub account_id: String,
236    pub last_updated_time: i64,
237}
238
239pub struct DataProtectionPolicy {
240    pub policy_document: String,
241    pub last_updated_time: i64,
242}
243
244pub struct IndexPolicy {
245    pub policy_name: String,
246    pub policy_document: String,
247    pub last_updated_time: i64,
248}
249
250pub struct Transformer {
251    pub transformer_config: serde_json::Value,
252    pub creation_time: i64,
253    pub last_modified_time: i64,
254}
255
256pub struct AnomalyDetector {
257    pub detector_name: String,
258    pub arn: String,
259    pub log_group_arn_list: Vec<String>,
260    pub evaluation_frequency: Option<String>,
261    pub filter_pattern: Option<String>,
262    pub anomaly_visibility_time: Option<i64>,
263    pub creation_time: i64,
264    pub last_modified_time: i64,
265    pub enabled: bool,
266}
267
268pub struct ImportTask {
269    pub import_id: String,
270    pub import_source_arn: String,
271    pub import_role_arn: String,
272    pub log_group_name: Option<String>,
273    pub status: String,
274    pub creation_time: i64,
275}
276
277pub struct Integration {
278    pub integration_name: String,
279    pub integration_type: String,
280    pub resource_config: serde_json::Value,
281    pub status: String,
282    pub creation_time: i64,
283}
284
285pub struct LookupTable {
286    pub lookup_table_name: String,
287    pub arn: String,
288    pub table_body: String,
289    pub creation_time: i64,
290    pub last_modified_time: i64,
291}
292
293pub struct ScheduledQuery {
294    pub name: String,
295    pub arn: String,
296    pub query_string: String,
297    pub query_language: String,
298    pub schedule_expression: String,
299    pub execution_role_arn: String,
300    pub status: String,
301    pub creation_time: i64,
302    pub last_modified_time: i64,
303}