Skip to main content

unifly_api/integration/client/
firewall.rs

1use tracing::debug;
2use uuid::Uuid;
3
4use super::{Error, IntegrationClient, types};
5
6impl IntegrationClient {
7    // ── Firewall Policies ────────────────────────────────────────────
8
9    pub async fn list_firewall_policies(
10        &self,
11        site_id: &Uuid,
12        offset: i64,
13        limit: i32,
14    ) -> Result<types::Page<types::FirewallPolicyResponse>, Error> {
15        self.get_with_params(
16            &format!("v1/sites/{site_id}/firewall/policies"),
17            &[("offset", offset.to_string()), ("limit", limit.to_string())],
18        )
19        .await
20    }
21
22    pub async fn get_firewall_policy(
23        &self,
24        site_id: &Uuid,
25        policy_id: &Uuid,
26    ) -> Result<types::FirewallPolicyResponse, Error> {
27        self.get(&format!("v1/sites/{site_id}/firewall/policies/{policy_id}"))
28            .await
29    }
30
31    pub async fn create_firewall_policy(
32        &self,
33        site_id: &Uuid,
34        body: &types::FirewallPolicyCreateUpdate,
35    ) -> Result<types::FirewallPolicyResponse, Error> {
36        self.post(&format!("v1/sites/{site_id}/firewall/policies"), body)
37            .await
38    }
39
40    pub async fn update_firewall_policy(
41        &self,
42        site_id: &Uuid,
43        policy_id: &Uuid,
44        body: &types::FirewallPolicyCreateUpdate,
45    ) -> Result<types::FirewallPolicyResponse, Error> {
46        self.put(
47            &format!("v1/sites/{site_id}/firewall/policies/{policy_id}"),
48            body,
49        )
50        .await
51    }
52
53    pub async fn patch_firewall_policy(
54        &self,
55        site_id: &Uuid,
56        policy_id: &Uuid,
57        body: &types::FirewallPolicyPatch,
58    ) -> Result<types::FirewallPolicyResponse, Error> {
59        self.patch(
60            &format!("v1/sites/{site_id}/firewall/policies/{policy_id}"),
61            body,
62        )
63        .await
64    }
65
66    pub async fn delete_firewall_policy(
67        &self,
68        site_id: &Uuid,
69        policy_id: &Uuid,
70    ) -> Result<(), Error> {
71        self.delete(&format!("v1/sites/{site_id}/firewall/policies/{policy_id}"))
72            .await
73    }
74
75    pub async fn get_firewall_policy_ordering(
76        &self,
77        site_id: &Uuid,
78        source_zone_id: &Uuid,
79        destination_zone_id: &Uuid,
80    ) -> Result<types::FirewallPolicyOrdering, Error> {
81        let envelope: types::FirewallPolicyOrderingEnvelope = self
82            .get_with_params(
83                &format!("v1/sites/{site_id}/firewall/policies/ordering"),
84                &[
85                    ("sourceFirewallZoneId", source_zone_id.to_string()),
86                    ("destinationFirewallZoneId", destination_zone_id.to_string()),
87                ],
88            )
89            .await?;
90        Ok(envelope.ordered_firewall_policy_ids)
91    }
92
93    pub async fn set_firewall_policy_ordering(
94        &self,
95        site_id: &Uuid,
96        source_zone_id: &Uuid,
97        destination_zone_id: &Uuid,
98        body: &types::FirewallPolicyOrdering,
99    ) -> Result<types::FirewallPolicyOrdering, Error> {
100        let url = self.url(&format!("v1/sites/{site_id}/firewall/policies/ordering"));
101        debug!(
102            "PUT {url} params={:?}",
103            &[
104                ("sourceFirewallZoneId", source_zone_id.to_string()),
105                ("destinationFirewallZoneId", destination_zone_id.to_string(),),
106            ]
107        );
108
109        let envelope = types::FirewallPolicyOrderingEnvelope {
110            ordered_firewall_policy_ids: body.clone(),
111        };
112        let resp = self
113            .http
114            .put(url)
115            .query(&[
116                ("sourceFirewallZoneId", source_zone_id.to_string()),
117                ("destinationFirewallZoneId", destination_zone_id.to_string()),
118            ])
119            .json(&envelope)
120            .send()
121            .await?;
122        let result: types::FirewallPolicyOrderingEnvelope = self.handle_response(resp).await?;
123        Ok(result.ordered_firewall_policy_ids)
124    }
125
126    // ── NAT Policies ─────────────────────────────────────────────────
127
128    pub async fn list_nat_policies(
129        &self,
130        site_id: &Uuid,
131        offset: i64,
132        limit: i32,
133    ) -> Result<types::Page<types::NatPolicyResponse>, Error> {
134        self.get_with_params(
135            &format!("v1/sites/{site_id}/firewall/nat"),
136            &[("offset", offset.to_string()), ("limit", limit.to_string())],
137        )
138        .await
139    }
140
141    pub async fn get_nat_policy(
142        &self,
143        site_id: &Uuid,
144        policy_id: &Uuid,
145    ) -> Result<types::NatPolicyResponse, Error> {
146        self.get(&format!("v1/sites/{site_id}/firewall/nat/{policy_id}"))
147            .await
148    }
149
150    pub async fn create_nat_policy(
151        &self,
152        site_id: &Uuid,
153        body: &types::NatPolicyCreateUpdate,
154    ) -> Result<types::NatPolicyResponse, Error> {
155        self.post(&format!("v1/sites/{site_id}/firewall/nat"), body)
156            .await
157    }
158
159    pub async fn update_nat_policy(
160        &self,
161        site_id: &Uuid,
162        policy_id: &Uuid,
163        body: &types::NatPolicyCreateUpdate,
164    ) -> Result<types::NatPolicyResponse, Error> {
165        self.put(
166            &format!("v1/sites/{site_id}/firewall/nat/{policy_id}"),
167            body,
168        )
169        .await
170    }
171
172    pub async fn delete_nat_policy(&self, site_id: &Uuid, policy_id: &Uuid) -> Result<(), Error> {
173        self.delete(&format!("v1/sites/{site_id}/firewall/nat/{policy_id}"))
174            .await
175    }
176
177    // ── Firewall Zones ───────────────────────────────────────────────
178
179    pub async fn list_firewall_zones(
180        &self,
181        site_id: &Uuid,
182        offset: i64,
183        limit: i32,
184    ) -> Result<types::Page<types::FirewallZoneResponse>, Error> {
185        self.get_with_params(
186            &format!("v1/sites/{site_id}/firewall/zones"),
187            &[("offset", offset.to_string()), ("limit", limit.to_string())],
188        )
189        .await
190    }
191
192    pub async fn get_firewall_zone(
193        &self,
194        site_id: &Uuid,
195        zone_id: &Uuid,
196    ) -> Result<types::FirewallZoneResponse, Error> {
197        self.get(&format!("v1/sites/{site_id}/firewall/zones/{zone_id}"))
198            .await
199    }
200
201    pub async fn create_firewall_zone(
202        &self,
203        site_id: &Uuid,
204        body: &types::FirewallZoneCreateUpdate,
205    ) -> Result<types::FirewallZoneResponse, Error> {
206        self.post(&format!("v1/sites/{site_id}/firewall/zones"), body)
207            .await
208    }
209
210    pub async fn update_firewall_zone(
211        &self,
212        site_id: &Uuid,
213        zone_id: &Uuid,
214        body: &types::FirewallZoneCreateUpdate,
215    ) -> Result<types::FirewallZoneResponse, Error> {
216        self.put(
217            &format!("v1/sites/{site_id}/firewall/zones/{zone_id}"),
218            body,
219        )
220        .await
221    }
222
223    pub async fn delete_firewall_zone(&self, site_id: &Uuid, zone_id: &Uuid) -> Result<(), Error> {
224        self.delete(&format!("v1/sites/{site_id}/firewall/zones/{zone_id}"))
225            .await
226    }
227}