1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use crate::ScalewayApi;
use crate::ScalewayError;
use crate::data::security_group::{ScalewaySecurityGroupRule, ScalewaySecurityGroupRulesRoot};
/// Builder for listing rules in a security group.
///
/// Created by [`ScalewayApi::list_security_group_rules`](crate::ScalewayApi::list_security_group_rules).
/// Call [`run`](Self::run) or [`run_async`](Self::run_async) to execute.
///
/// **Note:** The API always returns the full rule list regardless of pagination parameters.
pub struct ScalewayListSecurityGroupRulesBuilder {
api: ScalewayApi,
zone: String,
security_group_id: String,
params: Vec<(&'static str, String)>,
}
impl ScalewayListSecurityGroupRulesBuilder {
pub fn new(api: ScalewayApi, zone: &str, security_group_id: &str) -> Self {
ScalewayListSecurityGroupRulesBuilder {
api,
zone: zone.to_string(),
security_group_id: security_group_id.to_string(),
params: vec![],
}
}
/// Requests a specific page size (note: the API currently ignores this for rules).
pub fn per_page(mut self, per_page: u32) -> Self {
self.params.push(("per_page", per_page.to_string()));
self
}
/// Fetches all rules in the security group (blocking).
#[cfg(feature = "blocking")]
pub fn run(self) -> Result<Vec<ScalewaySecurityGroupRule>, ScalewayError> {
// it seems paging does not work for security group rules
// no matter what i give for "page" i always get the full list
let result = self.api.get(
&format!(
"https://api.scaleway.com/instance/v1/zones/{zone}/security_groups/{sg_id}/rules",
zone = self.zone,
sg_id = self.security_group_id
),
self.params,
)?;
let result = result.json::<ScalewaySecurityGroupRulesRoot>()?;
Ok(result.rules)
}
/// Fetches all rules in the security group.
pub async fn run_async(self) -> Result<Vec<ScalewaySecurityGroupRule>, ScalewayError> {
// it seems paging does not work for security group rules
// no matter what i give for "page" i always get the full list
let result = self
.api
.get_async(
&format!(
"https://api.scaleway.com/instance/v1/zones/{zone}/security_groups/{sg_id}/rules",
zone = self.zone,
sg_id = self.security_group_id
),
self.params,
)
.await?;
let result = result.json::<ScalewaySecurityGroupRulesRoot>().await?;
Ok(result.rules)
}
}