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 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}
107
108pub struct LogStream {
109 pub name: String,
110 pub arn: String,
111 pub creation_time: i64,
112 pub first_event_timestamp: Option<i64>,
113 pub last_event_timestamp: Option<i64>,
114 pub last_ingestion_time: Option<i64>,
115 pub upload_sequence_token: String,
116 pub events: Vec<LogEvent>,
117}
118
119#[derive(Clone)]
120pub struct LogEvent {
121 pub timestamp: i64,
122 pub message: String,
123 pub ingestion_time: i64,
124}
125
126pub struct SubscriptionFilter {
127 pub filter_name: String,
128 pub log_group_name: String,
129 pub filter_pattern: String,
130 pub destination_arn: String,
131 pub role_arn: Option<String>,
132 pub distribution: String,
133 pub creation_time: i64,
134}
135
136pub struct MetricFilter {
137 pub filter_name: String,
138 pub filter_pattern: String,
139 pub log_group_name: String,
140 pub metric_transformations: Vec<MetricTransformation>,
141 pub creation_time: i64,
142}
143
144pub struct MetricTransformation {
145 pub metric_name: String,
146 pub metric_namespace: String,
147 pub metric_value: String,
148 pub default_value: Option<f64>,
149}
150
151pub struct ResourcePolicy {
152 pub policy_name: String,
153 pub policy_document: String,
154 pub last_updated_time: i64,
155}
156
157pub struct Destination {
158 pub destination_name: String,
159 pub target_arn: String,
160 pub role_arn: String,
161 pub arn: String,
162 pub access_policy: Option<String>,
163 pub creation_time: i64,
164 pub tags: HashMap<String, String>,
165}
166
167pub struct QueryInfo {
168 pub query_id: String,
169 pub log_group_name: String,
170 pub query_string: String,
171 pub start_time: i64,
172 pub end_time: i64,
173 pub status: String,
174 pub create_time: i64,
175}
176
177pub struct ExportTask {
178 pub task_id: String,
179 pub task_name: Option<String>,
180 pub log_group_name: String,
181 pub log_stream_name_prefix: Option<String>,
182 pub from_time: i64,
183 pub to_time: i64,
184 pub destination: String,
185 pub destination_prefix: String,
186 pub status_code: String,
187 pub status_message: String,
188}
189
190pub struct DeliveryDestination {
191 pub name: String,
192 pub arn: String,
193 pub output_format: Option<String>,
194 pub delivery_destination_configuration: HashMap<String, String>,
195 pub tags: HashMap<String, String>,
196 pub delivery_destination_policy: Option<String>,
197}
198
199pub struct DeliverySource {
200 pub name: String,
201 pub arn: String,
202 pub resource_arns: Vec<String>,
203 pub service: String,
204 pub log_type: String,
205 pub tags: HashMap<String, String>,
206}
207
208pub struct Delivery {
209 pub id: String,
210 pub delivery_source_name: String,
211 pub delivery_destination_arn: String,
212 pub delivery_destination_type: String,
213 pub arn: String,
214 pub tags: HashMap<String, String>,
215}
216
217pub struct QueryDefinition {
218 pub query_definition_id: String,
219 pub name: String,
220 pub query_string: String,
221 pub log_group_names: Vec<String>,
222 pub last_modified: i64,
223}
224
225pub struct AccountPolicy {
226 pub policy_name: String,
227 pub policy_type: String,
228 pub policy_document: String,
229 pub scope: Option<String>,
230 pub selection_criteria: Option<String>,
231 pub account_id: String,
232 pub last_updated_time: i64,
233}
234
235pub struct DataProtectionPolicy {
236 pub policy_document: String,
237 pub last_updated_time: i64,
238}
239
240pub struct IndexPolicy {
241 pub policy_name: String,
242 pub policy_document: String,
243 pub last_updated_time: i64,
244}
245
246pub struct Transformer {
247 pub transformer_config: serde_json::Value,
248 pub creation_time: i64,
249 pub last_modified_time: i64,
250}
251
252pub struct AnomalyDetector {
253 pub detector_name: String,
254 pub arn: String,
255 pub log_group_arn_list: Vec<String>,
256 pub evaluation_frequency: Option<String>,
257 pub filter_pattern: Option<String>,
258 pub anomaly_visibility_time: Option<i64>,
259 pub creation_time: i64,
260 pub last_modified_time: i64,
261 pub enabled: bool,
262}
263
264pub struct ImportTask {
265 pub import_id: String,
266 pub import_source_arn: String,
267 pub import_role_arn: String,
268 pub log_group_name: Option<String>,
269 pub status: String,
270 pub creation_time: i64,
271}
272
273pub struct Integration {
274 pub integration_name: String,
275 pub integration_type: String,
276 pub resource_config: serde_json::Value,
277 pub status: String,
278 pub creation_time: i64,
279}
280
281pub struct LookupTable {
282 pub lookup_table_name: String,
283 pub arn: String,
284 pub table_body: String,
285 pub creation_time: i64,
286 pub last_modified_time: i64,
287}
288
289pub struct ScheduledQuery {
290 pub name: String,
291 pub arn: String,
292 pub query_string: String,
293 pub query_language: String,
294 pub schedule_expression: String,
295 pub execution_role_arn: String,
296 pub status: String,
297 pub creation_time: i64,
298 pub last_modified_time: i64,
299}