scaleway_rs/builder/
list_instance_images_builder.rs

1use crate::{
2    data::image::{ScalewayImage, ScalewayImageRoot},
3    ScalewayApi, ScalewayError,
4};
5
6pub struct ScalewayListInstanceImagesBuilder {
7    api: ScalewayApi,
8    zone: String,
9    params: Vec<(&'static str, String)>,
10}
11
12impl ScalewayListInstanceImagesBuilder {
13    pub fn new(api: ScalewayApi, zone: &str) -> Self {
14        ScalewayListInstanceImagesBuilder {
15            api,
16            zone: zone.to_string(),
17            params: vec![],
18        }
19    }
20
21    /// A positive integer lower or equal to 100 to select the number of items to return.
22    pub fn per_page(mut self, count: u32) -> ScalewayListInstanceImagesBuilder {
23        self.params.push(("per_page", count.to_string()));
24        self
25    }
26
27    /// A positive integer to choose the page to return.
28    pub fn page(mut self, count: u32) -> ScalewayListInstanceImagesBuilder {
29        self.params.push(("page", count.to_string()));
30        self
31    }
32
33    /// List only images of this Organization ID.
34    pub fn organization(mut self, organization: &str) -> ScalewayListInstanceImagesBuilder {
35        self.params.push(("organization", organization.to_string()));
36        self
37    }
38
39    /// List only images of this Project ID.
40    pub fn project(mut self, project: &str) -> ScalewayListInstanceImagesBuilder {
41        self.params.push(("project", project.to_string()));
42        self
43    }
44
45    /// Filter images by public attribute
46    pub fn public(mut self, public: bool) -> ScalewayListInstanceImagesBuilder {
47        self.params.push(("public", public.to_string()));
48        self
49    }
50
51    /// Filter images by name (eg. "server1" will return "server100" and "server1" but not "foo").
52    pub fn name(mut self, name: &str) -> ScalewayListInstanceImagesBuilder {
53        self.params.push(("name", name.to_string()));
54        self
55    }
56
57    /// Filter images by arch
58    pub fn arch(mut self, arch: &str) -> ScalewayListInstanceImagesBuilder {
59        self.params.push(("arch", arch.to_string()));
60        self
61    }
62
63    /// List images with these exact tags (to filter with several tags, use commas to separate them).
64    pub fn tags(mut self, tags: &str) -> ScalewayListInstanceImagesBuilder {
65        self.params.push(("tags", tags.to_string()));
66        self
67    }
68
69    #[cfg(feature = "blocking")]
70    pub fn run(self) -> Result<Vec<ScalewayImage>, ScalewayError> {
71        let url = &format!(
72            "https://api.scaleway.com/instance/v1/zones/{zone}/images",
73            zone = self.zone
74        );
75        Ok(self
76            .api
77            .get(&url, self.params)?
78            .json::<ScalewayImageRoot>()?
79            .images)
80    }
81
82    pub async fn run_async(self) -> Result<Vec<ScalewayImage>, ScalewayError> {
83        let url = &format!(
84            "https://api.scaleway.com/instance/v1/zones/{zone}/images",
85            zone = self.zone
86        );
87        Ok(self
88            .api
89            .get_async(&url, self.params)
90            .await?
91            .json::<ScalewayImageRoot>()
92            .await?
93            .images)
94    }
95}