fastly_api/apis/
director_backend_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`create_director_backend`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateDirectorBackendParams {
17    /// Name for the Director.
18    pub director_name: String,
19    /// Alphanumeric string identifying the service.
20    pub service_id: String,
21    /// Integer identifying a service version.
22    pub version_id: i32,
23    /// The name of the backend.
24    pub backend_name: String
25}
26
27/// struct for passing parameters to the method [`delete_director_backend`]
28#[derive(Clone, Debug, Default)]
29pub struct DeleteDirectorBackendParams {
30    /// Name for the Director.
31    pub director_name: String,
32    /// Alphanumeric string identifying the service.
33    pub service_id: String,
34    /// Integer identifying a service version.
35    pub version_id: i32,
36    /// The name of the backend.
37    pub backend_name: String
38}
39
40/// struct for passing parameters to the method [`get_director_backend`]
41#[derive(Clone, Debug, Default)]
42pub struct GetDirectorBackendParams {
43    /// Name for the Director.
44    pub director_name: String,
45    /// Alphanumeric string identifying the service.
46    pub service_id: String,
47    /// Integer identifying a service version.
48    pub version_id: i32,
49    /// The name of the backend.
50    pub backend_name: String
51}
52
53
54/// struct for typed errors of method [`create_director_backend`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum CreateDirectorBackendError {
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`delete_director_backend`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum DeleteDirectorBackendError {
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`get_director_backend`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum GetDirectorBackendError {
72    Status404(),
73    UnknownValue(serde_json::Value),
74}
75
76
77/// Establishes a relationship between a Backend and a Director. The Backend is then considered a member of the Director and can be used to balance traffic onto.
78pub async fn create_director_backend(configuration: &mut configuration::Configuration, params: CreateDirectorBackendParams) -> Result<crate::models::DirectorBackend, Error<CreateDirectorBackendError>> {
79    let local_var_configuration = configuration;
80
81    // unbox the parameters
82    let director_name = params.director_name;
83    let service_id = params.service_id;
84    let version_id = params.version_id;
85    let backend_name = params.backend_name;
86
87
88    let local_var_client = &local_var_configuration.client;
89
90    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/director/{director_name}/backend/{backend_name}", local_var_configuration.base_path, director_name=crate::apis::urlencode(director_name), service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
91    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
92
93    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
94        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
95    }
96    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
97        let local_var_key = local_var_apikey.key.clone();
98        let local_var_value = match local_var_apikey.prefix {
99            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
100            None => local_var_key,
101        };
102        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
103    };
104
105    let local_var_req = local_var_req_builder.build()?;
106    let local_var_resp = local_var_client.execute(local_var_req).await?;
107
108    if "POST" != "GET" && "POST" != "HEAD" {
109      let headers = local_var_resp.headers();
110      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
111          Some(v) => v.to_str().unwrap().parse().unwrap(),
112          None => configuration::DEFAULT_RATELIMIT,
113      };
114      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
115          Some(v) => v.to_str().unwrap().parse().unwrap(),
116          None => 0,
117      };
118    }
119
120    let local_var_status = local_var_resp.status();
121    let local_var_content = local_var_resp.text().await?;
122
123    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
124        serde_json::from_str(&local_var_content).map_err(Error::from)
125    } else {
126        let local_var_entity: Option<CreateDirectorBackendError> = serde_json::from_str(&local_var_content).ok();
127        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
128        Err(Error::ResponseError(local_var_error))
129    }
130}
131
132/// Deletes the relationship between a Backend and a Director. The Backend is no longer considered a member of the Director and thus will not have traffic balanced onto it from this Director.
133pub async fn delete_director_backend(configuration: &mut configuration::Configuration, params: DeleteDirectorBackendParams) -> Result<crate::models::InlineResponse200, Error<DeleteDirectorBackendError>> {
134    let local_var_configuration = configuration;
135
136    // unbox the parameters
137    let director_name = params.director_name;
138    let service_id = params.service_id;
139    let version_id = params.version_id;
140    let backend_name = params.backend_name;
141
142
143    let local_var_client = &local_var_configuration.client;
144
145    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/director/{director_name}/backend/{backend_name}", local_var_configuration.base_path, director_name=crate::apis::urlencode(director_name), service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
146    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
147
148    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
149        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
150    }
151    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
152        let local_var_key = local_var_apikey.key.clone();
153        let local_var_value = match local_var_apikey.prefix {
154            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
155            None => local_var_key,
156        };
157        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
158    };
159
160    let local_var_req = local_var_req_builder.build()?;
161    let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163    if "DELETE" != "GET" && "DELETE" != "HEAD" {
164      let headers = local_var_resp.headers();
165      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
166          Some(v) => v.to_str().unwrap().parse().unwrap(),
167          None => configuration::DEFAULT_RATELIMIT,
168      };
169      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
170          Some(v) => v.to_str().unwrap().parse().unwrap(),
171          None => 0,
172      };
173    }
174
175    let local_var_status = local_var_resp.status();
176    let local_var_content = local_var_resp.text().await?;
177
178    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
179        serde_json::from_str(&local_var_content).map_err(Error::from)
180    } else {
181        let local_var_entity: Option<DeleteDirectorBackendError> = serde_json::from_str(&local_var_content).ok();
182        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
183        Err(Error::ResponseError(local_var_error))
184    }
185}
186
187/// Returns the relationship between a Backend and a Director. If the Backend has been associated with the Director, it returns a simple record indicating this. Otherwise, returns a 404.
188pub async fn get_director_backend(configuration: &mut configuration::Configuration, params: GetDirectorBackendParams) -> Result<crate::models::DirectorBackend, Error<GetDirectorBackendError>> {
189    let local_var_configuration = configuration;
190
191    // unbox the parameters
192    let director_name = params.director_name;
193    let service_id = params.service_id;
194    let version_id = params.version_id;
195    let backend_name = params.backend_name;
196
197
198    let local_var_client = &local_var_configuration.client;
199
200    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/director/{director_name}/backend/{backend_name}", local_var_configuration.base_path, director_name=crate::apis::urlencode(director_name), service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
201    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
202
203    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
204        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
205    }
206    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
207        let local_var_key = local_var_apikey.key.clone();
208        let local_var_value = match local_var_apikey.prefix {
209            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
210            None => local_var_key,
211        };
212        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
213    };
214
215    let local_var_req = local_var_req_builder.build()?;
216    let local_var_resp = local_var_client.execute(local_var_req).await?;
217
218    if "GET" != "GET" && "GET" != "HEAD" {
219      let headers = local_var_resp.headers();
220      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
221          Some(v) => v.to_str().unwrap().parse().unwrap(),
222          None => configuration::DEFAULT_RATELIMIT,
223      };
224      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
225          Some(v) => v.to_str().unwrap().parse().unwrap(),
226          None => 0,
227      };
228    }
229
230    let local_var_status = local_var_resp.status();
231    let local_var_content = local_var_resp.text().await?;
232
233    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
234        serde_json::from_str(&local_var_content).map_err(Error::from)
235    } else {
236        let local_var_entity: Option<GetDirectorBackendError> = serde_json::from_str(&local_var_content).ok();
237        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
238        Err(Error::ResponseError(local_var_error))
239    }
240}
241