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 pub account_policies: HashMap<(String, String), AccountPolicy>,
23 pub anomaly_detectors: HashMap<String, AnomalyDetector>,
25 pub import_tasks: HashMap<String, ImportTask>,
27 pub integrations: HashMap<String, Integration>,
29 pub lookup_tables: HashMap<String, LookupTable>,
31 pub scheduled_queries: HashMap<String, ScheduledQuery>,
33 pub s3_table_sources: HashMap<String, Vec<String>>,
35 pub bearer_token_auth: HashMap<String, bool>,
37}
38
39impl LogsState {
40 pub fn new(account_id: &str, region: &str) -> Self {
41 Self {
42 account_id: account_id.to_string(),
43 region: region.to_string(),
44 log_groups: HashMap::new(),
45 metric_filters: Vec::new(),
46 resource_policies: HashMap::new(),
47 destinations: HashMap::new(),
48 queries: HashMap::new(),
49 export_tasks: Vec::new(),
50 delivery_destinations: HashMap::new(),
51 delivery_sources: HashMap::new(),
52 deliveries: HashMap::new(),
53 query_definitions: HashMap::new(),
54 account_policies: HashMap::new(),
55 anomaly_detectors: HashMap::new(),
56 import_tasks: HashMap::new(),
57 integrations: HashMap::new(),
58 lookup_tables: HashMap::new(),
59 scheduled_queries: HashMap::new(),
60 s3_table_sources: HashMap::new(),
61 bearer_token_auth: HashMap::new(),
62 }
63 }
64
65 pub fn reset(&mut self) {
66 self.log_groups.clear();
67 self.metric_filters.clear();
68 self.resource_policies.clear();
69 self.destinations.clear();
70 self.queries.clear();
71 self.export_tasks.clear();
72 self.delivery_destinations.clear();
73 self.delivery_sources.clear();
74 self.deliveries.clear();
75 self.query_definitions.clear();
76 self.account_policies.clear();
77 self.anomaly_detectors.clear();
78 self.import_tasks.clear();
79 self.integrations.clear();
80 self.lookup_tables.clear();
81 self.scheduled_queries.clear();
82 self.s3_table_sources.clear();
83 self.bearer_token_auth.clear();
84 }
85}
86
87pub struct LogGroup {
88 pub name: String,
89 pub arn: String,
90 pub creation_time: i64,
91 pub retention_in_days: Option<i32>,
92 pub kms_key_id: Option<String>,
93 pub tags: HashMap<String, String>,
94 pub log_streams: HashMap<String, LogStream>,
95 pub stored_bytes: i64,
96 pub subscription_filters: Vec<SubscriptionFilter>,
97 pub data_protection_policy: Option<DataProtectionPolicy>,
98 pub index_policies: Vec<IndexPolicy>,
99 pub transformer: Option<Transformer>,
100 pub deletion_protection: bool,
101}
102
103pub struct LogStream {
104 pub name: String,
105 pub arn: String,
106 pub creation_time: i64,
107 pub first_event_timestamp: Option<i64>,
108 pub last_event_timestamp: Option<i64>,
109 pub last_ingestion_time: Option<i64>,
110 pub upload_sequence_token: String,
111 pub events: Vec<LogEvent>,
112}
113
114#[derive(Clone)]
115pub struct LogEvent {
116 pub timestamp: i64,
117 pub message: String,
118 pub ingestion_time: i64,
119}
120
121pub struct SubscriptionFilter {
122 pub filter_name: String,
123 pub log_group_name: String,
124 pub filter_pattern: String,
125 pub destination_arn: String,
126 pub role_arn: Option<String>,
127 pub distribution: String,
128 pub creation_time: i64,
129}
130
131pub struct MetricFilter {
132 pub filter_name: String,
133 pub filter_pattern: String,
134 pub log_group_name: String,
135 pub metric_transformations: Vec<MetricTransformation>,
136 pub creation_time: i64,
137}
138
139pub struct MetricTransformation {
140 pub metric_name: String,
141 pub metric_namespace: String,
142 pub metric_value: String,
143 pub default_value: Option<f64>,
144}
145
146pub struct ResourcePolicy {
147 pub policy_name: String,
148 pub policy_document: String,
149 pub last_updated_time: i64,
150}
151
152pub struct Destination {
153 pub destination_name: String,
154 pub target_arn: String,
155 pub role_arn: String,
156 pub arn: String,
157 pub access_policy: Option<String>,
158 pub creation_time: i64,
159 pub tags: HashMap<String, String>,
160}
161
162pub struct QueryInfo {
163 pub query_id: String,
164 pub log_group_name: String,
165 pub query_string: String,
166 pub start_time: i64,
167 pub end_time: i64,
168 pub status: String,
169 pub create_time: i64,
170}
171
172pub struct ExportTask {
173 pub task_id: String,
174 pub task_name: Option<String>,
175 pub log_group_name: String,
176 pub log_stream_name_prefix: Option<String>,
177 pub from_time: i64,
178 pub to_time: i64,
179 pub destination: String,
180 pub destination_prefix: String,
181 pub status_code: String,
182 pub status_message: String,
183}
184
185pub struct DeliveryDestination {
186 pub name: String,
187 pub arn: String,
188 pub output_format: Option<String>,
189 pub delivery_destination_configuration: HashMap<String, String>,
190 pub tags: HashMap<String, String>,
191 pub delivery_destination_policy: Option<String>,
192}
193
194pub struct DeliverySource {
195 pub name: String,
196 pub arn: String,
197 pub resource_arns: Vec<String>,
198 pub service: String,
199 pub log_type: String,
200 pub tags: HashMap<String, String>,
201}
202
203pub struct Delivery {
204 pub id: String,
205 pub delivery_source_name: String,
206 pub delivery_destination_arn: String,
207 pub delivery_destination_type: String,
208 pub arn: String,
209 pub tags: HashMap<String, String>,
210}
211
212pub struct QueryDefinition {
213 pub query_definition_id: String,
214 pub name: String,
215 pub query_string: String,
216 pub log_group_names: Vec<String>,
217 pub last_modified: i64,
218}
219
220pub struct AccountPolicy {
221 pub policy_name: String,
222 pub policy_type: String,
223 pub policy_document: String,
224 pub scope: Option<String>,
225 pub selection_criteria: Option<String>,
226 pub account_id: String,
227 pub last_updated_time: i64,
228}
229
230pub struct DataProtectionPolicy {
231 pub policy_document: String,
232 pub last_updated_time: i64,
233}
234
235pub struct IndexPolicy {
236 pub policy_name: String,
237 pub policy_document: String,
238 pub last_updated_time: i64,
239}
240
241pub struct Transformer {
242 pub transformer_config: serde_json::Value,
243 pub creation_time: i64,
244 pub last_modified_time: i64,
245}
246
247pub struct AnomalyDetector {
248 pub detector_name: String,
249 pub arn: String,
250 pub log_group_arn_list: Vec<String>,
251 pub evaluation_frequency: Option<String>,
252 pub filter_pattern: Option<String>,
253 pub anomaly_visibility_time: Option<i64>,
254 pub creation_time: i64,
255 pub last_modified_time: i64,
256 pub enabled: bool,
257}
258
259pub struct ImportTask {
260 pub import_id: String,
261 pub import_source_arn: String,
262 pub import_role_arn: String,
263 pub log_group_name: Option<String>,
264 pub status: String,
265 pub creation_time: i64,
266}
267
268pub struct Integration {
269 pub integration_name: String,
270 pub integration_type: String,
271 pub resource_config: serde_json::Value,
272 pub status: String,
273 pub creation_time: i64,
274}
275
276pub struct LookupTable {
277 pub lookup_table_name: String,
278 pub arn: String,
279 pub table_body: String,
280 pub creation_time: i64,
281 pub last_modified_time: i64,
282}
283
284pub struct ScheduledQuery {
285 pub name: String,
286 pub arn: String,
287 pub query_string: String,
288 pub query_language: String,
289 pub schedule_expression: String,
290 pub execution_role_arn: String,
291 pub status: String,
292 pub creation_time: i64,
293 pub last_modified_time: i64,
294}