oxide_api/routes.rs
1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Routes {
6 pub client: Client,
7}
8
9impl Routes {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Routes { client }
13 }
14
15 /**
16 * List routes.
17 *
18 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_name}/routes` endpoint.
19 *
20 * List the routes associated with a router in a particular VPC.
21 *
22 * **Parameters:**
23 *
24 * * `limit: u32` -- Maximum number of items returned by a single call.
25 * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
26 * * `sort_by: crate::types::NameSortMode` -- Supported set of sort modes for scanning by name only
27 *
28 * Currently, we only support scanning in ascending order.
29 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
30 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
31 * * `router_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
32 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
33 */
34 pub async fn get_page(
35 &self,
36 limit: u32,
37 organization_name: &str,
38 page_token: &str,
39 project_name: &str,
40 router_name: &str,
41 sort_by: crate::types::NameSortMode,
42 vpc_name: &str,
43 ) -> Result<Vec<crate::types::RouterRoute>> {
44 let mut query_args: Vec<(String, String)> = Default::default();
45 if !limit.to_string().is_empty() {
46 query_args.push(("limit".to_string(), limit.to_string()));
47 }
48 if !page_token.is_empty() {
49 query_args.push(("page_token".to_string(), page_token.to_string()));
50 }
51 if !sort_by.to_string().is_empty() {
52 query_args.push(("sort_by".to_string(), sort_by.to_string()));
53 }
54 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
55 let url = format!(
56 "/organizations/{}/projects/{}/vpcs/{}/routers/{}/routes?{}",
57 crate::progenitor_support::encode_path(organization_name),
58 crate::progenitor_support::encode_path(project_name),
59 crate::progenitor_support::encode_path(vpc_name),
60 crate::progenitor_support::encode_path(router_name),
61 query_
62 );
63
64 let resp: crate::types::RouterRouteResultsPage = self.client.get(&url, None).await?;
65
66 // Return our response data.
67 Ok(resp.items)
68 }
69
70 /**
71 * List routes.
72 *
73 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_name}/routes` endpoint.
74 *
75 * As opposed to `get`, this function returns all the pages of the request at once.
76 *
77 * List the routes associated with a router in a particular VPC.
78 */
79 pub async fn get_all(
80 &self,
81 organization_name: &str,
82 project_name: &str,
83 router_name: &str,
84 sort_by: crate::types::NameSortMode,
85 vpc_name: &str,
86 ) -> Result<Vec<crate::types::RouterRoute>> {
87 let mut query_args: Vec<(String, String)> = Default::default();
88 if !sort_by.to_string().is_empty() {
89 query_args.push(("sort_by".to_string(), sort_by.to_string()));
90 }
91 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
92 let url = format!(
93 "/organizations/{}/projects/{}/vpcs/{}/routers/{}/routes?{}",
94 crate::progenitor_support::encode_path(organization_name),
95 crate::progenitor_support::encode_path(project_name),
96 crate::progenitor_support::encode_path(vpc_name),
97 crate::progenitor_support::encode_path(router_name),
98 query_
99 );
100
101 let mut resp: crate::types::RouterRouteResultsPage = self.client.get(&url, None).await?;
102
103 let mut items = resp.items;
104 let mut page = resp.next_page;
105
106 // Paginate if we should.
107 while !page.is_empty() {
108 if !url.contains('?') {
109 resp = self
110 .client
111 .get(&format!("{}?page={}", url, page), None)
112 .await?;
113 } else {
114 resp = self
115 .client
116 .get(&format!("{}&page={}", url, page), None)
117 .await?;
118 }
119
120 items.append(&mut resp.items);
121
122 if !resp.next_page.is_empty() && resp.next_page != page {
123 page = resp.next_page.to_string();
124 } else {
125 page = "".to_string();
126 }
127 }
128
129 // Return our response data.
130 Ok(items)
131 }
132
133 /**
134 * Create a router.
135 *
136 * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_name}/routes` endpoint.
137 *
138 * **Parameters:**
139 *
140 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
141 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
142 * * `router_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
143 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
144 */
145 pub async fn post(
146 &self,
147 organization_name: &str,
148 project_name: &str,
149 router_name: &str,
150 vpc_name: &str,
151 body: &crate::types::RouterRouteCreateParams,
152 ) -> Result<crate::types::RouterRoute> {
153 let url = format!(
154 "/organizations/{}/projects/{}/vpcs/{}/routers/{}/routes",
155 crate::progenitor_support::encode_path(organization_name),
156 crate::progenitor_support::encode_path(project_name),
157 crate::progenitor_support::encode_path(vpc_name),
158 crate::progenitor_support::encode_path(router_name),
159 );
160
161 self.client
162 .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
163 .await
164 }
165
166 /**
167 * Fetch a route.
168 *
169 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_name}/routes/{route_name}` endpoint.
170 *
171 * **Parameters:**
172 *
173 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
174 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
175 * * `route_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
176 * * `router_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
177 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
178 */
179 pub async fn get(
180 &self,
181 organization_name: &str,
182 project_name: &str,
183 route_name: &str,
184 router_name: &str,
185 vpc_name: &str,
186 ) -> Result<crate::types::RouterRoute> {
187 let url = format!(
188 "/organizations/{}/projects/{}/vpcs/{}/routers/{}/routes/{}",
189 crate::progenitor_support::encode_path(organization_name),
190 crate::progenitor_support::encode_path(project_name),
191 crate::progenitor_support::encode_path(vpc_name),
192 crate::progenitor_support::encode_path(router_name),
193 crate::progenitor_support::encode_path(route_name),
194 );
195
196 self.client.get(&url, None).await
197 }
198
199 /**
200 * Update a route.
201 *
202 * This function performs a `PUT` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_name}/routes/{route_name}` endpoint.
203 *
204 * **Parameters:**
205 *
206 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
207 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
208 * * `route_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
209 * * `router_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
210 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
211 */
212 pub async fn put(
213 &self,
214 organization_name: &str,
215 project_name: &str,
216 route_name: &str,
217 router_name: &str,
218 vpc_name: &str,
219 body: &crate::types::RouterRouteUpdateParams,
220 ) -> Result<crate::types::RouterRoute> {
221 let url = format!(
222 "/organizations/{}/projects/{}/vpcs/{}/routers/{}/routes/{}",
223 crate::progenitor_support::encode_path(organization_name),
224 crate::progenitor_support::encode_path(project_name),
225 crate::progenitor_support::encode_path(vpc_name),
226 crate::progenitor_support::encode_path(router_name),
227 crate::progenitor_support::encode_path(route_name),
228 );
229
230 self.client
231 .put(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
232 .await
233 }
234
235 /**
236 * Delete a route.
237 *
238 * This function performs a `DELETE` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_name}/routes/{route_name}` endpoint.
239 *
240 * **Parameters:**
241 *
242 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
243 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
244 * * `route_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
245 * * `router_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
246 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
247 */
248 pub async fn delete(
249 &self,
250 organization_name: &str,
251 project_name: &str,
252 route_name: &str,
253 router_name: &str,
254 vpc_name: &str,
255 ) -> Result<()> {
256 let url = format!(
257 "/organizations/{}/projects/{}/vpcs/{}/routers/{}/routes/{}",
258 crate::progenitor_support::encode_path(organization_name),
259 crate::progenitor_support::encode_path(project_name),
260 crate::progenitor_support::encode_path(vpc_name),
261 crate::progenitor_support::encode_path(router_name),
262 crate::progenitor_support::encode_path(route_name),
263 );
264
265 self.client.delete(&url, None).await
266 }
267}