1use std::collections::BTreeMap;
4use std::sync::Arc;
5
6use chrono::{DateTime, Utc};
7use parking_lot::RwLock;
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10
11pub type SharedWafv2State = Arc<RwLock<Wafv2Accounts>>;
12
13#[derive(Debug, Default, Serialize, Deserialize)]
14pub struct Wafv2Accounts {
15 pub accounts: BTreeMap<String, AccountState>,
16}
17
18impl Wafv2Accounts {
19 pub fn new() -> Self {
20 Self::default()
21 }
22}
23
24#[derive(Debug, Default, Serialize, Deserialize)]
25pub struct AccountState {
26 pub web_acls: BTreeMap<ScopedKey, WebAcl>,
28 pub rule_groups: BTreeMap<ScopedKey, RuleGroup>,
30 pub ip_sets: BTreeMap<ScopedKey, IpSet>,
32 pub regex_pattern_sets: BTreeMap<ScopedKey, RegexPatternSet>,
34 pub api_keys: BTreeMap<String, ApiKey>,
36 pub logging_configs: BTreeMap<String, Value>,
38 pub permission_policies: BTreeMap<String, String>,
40 pub associations: BTreeMap<String, String>,
42 pub tags: BTreeMap<String, BTreeMap<String, String>>,
44}
45
46pub type ScopedKey = (String, String);
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct WebAcl {
50 pub id: String,
51 pub name: String,
52 pub arn: String,
53 pub scope: String,
54 pub default_action: Value,
55 pub description: Option<String>,
56 pub rules: Vec<Value>,
57 pub visibility_config: Value,
58 pub capacity: i64,
59 pub lock_token: String,
60 pub label_namespace: String,
61 pub custom_response_bodies: BTreeMap<String, Value>,
62 pub captcha_config: Option<Value>,
63 pub challenge_config: Option<Value>,
64 pub token_domains: Vec<String>,
65 pub association_config: Option<Value>,
66 pub data_protection_config: Option<Value>,
67 pub on_source_d_do_s_protection_config: Option<Value>,
68 pub application_config: Option<Value>,
69 pub retrofitted_by_firewall_manager: bool,
70 pub pre_process_firewall_manager_rule_groups: Vec<Value>,
71 pub post_process_firewall_manager_rule_groups: Vec<Value>,
72 pub managed_by_firewall_manager: bool,
73 pub created_time: DateTime<Utc>,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct RuleGroup {
78 pub id: String,
79 pub name: String,
80 pub arn: String,
81 pub scope: String,
82 pub capacity: i64,
83 pub description: Option<String>,
84 pub rules: Vec<Value>,
85 pub visibility_config: Value,
86 pub lock_token: String,
87 pub label_namespace: String,
88 pub custom_response_bodies: BTreeMap<String, Value>,
89 pub available_labels: Vec<Value>,
90 pub consumed_labels: Vec<Value>,
91 pub created_time: DateTime<Utc>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct IpSet {
96 pub id: String,
97 pub name: String,
98 pub arn: String,
99 pub scope: String,
100 pub description: Option<String>,
101 pub ip_address_version: String,
102 pub addresses: Vec<String>,
103 pub lock_token: String,
104 pub created_time: DateTime<Utc>,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct RegexPatternSet {
109 pub id: String,
110 pub name: String,
111 pub arn: String,
112 pub scope: String,
113 pub description: Option<String>,
114 pub regular_expressions: Vec<Value>,
115 pub lock_token: String,
116 pub created_time: DateTime<Utc>,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
120pub struct ApiKey {
121 pub api_key: String,
122 pub scope: String,
123 pub token_domains: Vec<String>,
124 pub version: i32,
125 pub creation_timestamp: DateTime<Utc>,
126}