nodesty_api_library/services/
firewall.rs1use crate::models::{
2 firewall::{
3 AttackNotificationSettings, FirewallAttackLog, FirewallCreateRuleData, FirewallReverseDns,
4 FirewallRule, FirewallStatistics,
5 },
6 ApiResponse,
7};
8use crate::NodestyApiClient;
9use reqwest::{Error, Method};
10use std::sync::Arc;
11
12pub struct FirewallApiService {
13 client: Arc<NodestyApiClient>,
14}
15
16impl FirewallApiService {
17 pub fn new(client: Arc<NodestyApiClient>) -> Self {
18 Self { client }
19 }
20
21 pub async fn get_attack_logs(
22 &self,
23 service_id: &str,
24 ip: &str,
25 ) -> Result<ApiResponse<Vec<FirewallAttackLog>>, Error> {
26 self.client
27 .send_request(
28 Method::GET,
29 &format!("/services/{}/firewall/{}/attack-logs", service_id, ip),
30 None,
31 )
32 .await
33 }
34
35 pub async fn get_attack_notification_settings(
36 &self,
37 service_id: &str,
38 ip: &str,
39 ) -> Result<ApiResponse<AttackNotificationSettings>, Error> {
40 self.client
41 .send_request(
42 Method::GET,
43 &format!(
44 "/services/{}/firewall/{}/attack-notification",
45 service_id, ip
46 ),
47 None,
48 )
49 .await
50 }
51
52 pub async fn update_attack_notification_settings(
53 &self,
54 service_id: &str,
55 ip: &str,
56 data: AttackNotificationSettings,
57 ) -> Result<ApiResponse<AttackNotificationSettings>, Error> {
58 let body = serde_json::to_value(&data).ok();
59 self.client
60 .send_request(
61 Method::PUT,
62 &format!(
63 "/services/{}/firewall/{}/attack-notification",
64 service_id, ip
65 ),
66 body,
67 )
68 .await
69 }
70
71 pub async fn reset_reverse_dns(
72 &self,
73 service_id: &str,
74 ip: &str,
75 ) -> Result<ApiResponse<()>, Error> {
76 self.client
77 .send_request(
78 Method::DELETE,
79 &format!("/services/{}/firewall/{}/rdns", service_id, ip),
80 None,
81 )
82 .await
83 }
84
85 pub async fn get_reverse_dns(
86 &self,
87 service_id: &str,
88 ip: &str,
89 ) -> Result<ApiResponse<FirewallReverseDns>, Error> {
90 self.client
91 .send_request(
92 Method::GET,
93 &format!("/services/{}/firewall/{}/rdns", service_id, ip),
94 None,
95 )
96 .await
97 }
98
99 pub async fn upsert_reverse_dns(
100 &self,
101 service_id: &str,
102 ip: &str,
103 data: FirewallReverseDns,
104 ) -> Result<ApiResponse<()>, Error> {
105 let body = serde_json::to_value(&data).ok();
106 self.client
107 .send_request(
108 Method::PUT,
109 &format!("/services/{}/firewall/{}/rdns", service_id, ip),
110 body,
111 )
112 .await
113 }
114
115 pub async fn delete_rule(
116 &self,
117 service_id: &str,
118 ip: &str,
119 rule_id: u32,
120 ) -> Result<ApiResponse<()>, Error> {
121 self.client
122 .send_request(
123 Method::DELETE,
124 &format!("/services/{}/firewall/{}/rules/{}", service_id, ip, rule_id),
125 None,
126 )
127 .await
128 }
129
130 pub async fn get_rules(
131 &self,
132 service_id: &str,
133 ip: &str,
134 ) -> Result<ApiResponse<Vec<FirewallRule>>, Error> {
135 self.client
136 .send_request(
137 Method::GET,
138 &format!("/services/{}/firewall/{}/rules", service_id, ip),
139 None,
140 )
141 .await
142 }
143
144 pub async fn create_rule(
145 &self,
146 service_id: &str,
147 ip: &str,
148 data: FirewallCreateRuleData,
149 ) -> Result<ApiResponse<()>, Error> {
150 let body = serde_json::to_value(&data).ok();
151 self.client
152 .send_request(
153 Method::POST,
154 &format!("/services/{}/firewall/{}/rules", service_id, ip),
155 body,
156 )
157 .await
158 }
159
160 pub async fn get_statistics(
161 &self,
162 service_id: &str,
163 ip: &str,
164 ) -> Result<ApiResponse<Vec<FirewallStatistics>>, Error> {
165 self.client
166 .send_request(
167 Method::GET,
168 &format!("/services/{}/firewall/{}/stats", service_id, ip),
169 None,
170 )
171 .await
172 }
173}