netlify_rust/apis/
deploy_key_api.rs

1/*
2 * Netlify's API documentation
3 *
4 * Netlify is a hosting service for the programmable web. It understands your documents and provides an API to handle atomic deploys of websites, manage form submissions, inject JavaScript snippets, and much more. This is a REST-style API that uses JSON for serialization and OAuth 2 for authentication.  This document is an OpenAPI reference for the Netlify API that you can explore. For more detailed instructions for common uses, please visit the [online documentation](https://www.netlify.com/docs/api/). Visit our Community forum to join the conversation about [understanding and using Netlify’s API](https://community.netlify.com/t/common-issue-understanding-and-using-netlifys-api/160).  Additionally, we have two API clients for your convenience: - [Go Client](https://github.com/netlify/open-api#go-client) - [JS Client](https://github.com/netlify/js-client)
5 *
6 * The version of the OpenAPI document: 2.5.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `create_deploy_key`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateDeployKeyError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `delete_deploy_key`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteDeployKeyError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `get_deploy_key`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetDeployKeyError {
38    DefaultResponse(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `list_deploy_keys`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ListDeployKeysError {
46    DefaultResponse(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50
51pub async fn create_deploy_key(configuration: &configuration::Configuration, ) -> Result<crate::models::DeployKey, Error<CreateDeployKeyError>> {
52
53    let local_var_client = &configuration.client;
54
55    let local_var_uri_str = format!("{}/deploy_keys", configuration.base_path);
56    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
57
58    if let Some(ref local_var_user_agent) = configuration.user_agent {
59        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
60    }
61    if let Some(ref local_var_token) = configuration.oauth_access_token {
62        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
63    };
64
65    let local_var_req = local_var_req_builder.build()?;
66    let local_var_resp = local_var_client.execute(local_var_req).await?;
67
68    let local_var_status = local_var_resp.status();
69    let local_var_content = local_var_resp.text().await?;
70
71    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
72        serde_json::from_str(&local_var_content).map_err(Error::from)
73    } else {
74        let local_var_entity: Option<CreateDeployKeyError> = serde_json::from_str(&local_var_content).ok();
75        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
76        Err(Error::ResponseError(local_var_error))
77    }
78}
79
80pub async fn delete_deploy_key(configuration: &configuration::Configuration, key_id: &str) -> Result<(), Error<DeleteDeployKeyError>> {
81
82    let local_var_client = &configuration.client;
83
84    let local_var_uri_str = format!("{}/deploy_keys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(key_id));
85    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
86
87    if let Some(ref local_var_user_agent) = configuration.user_agent {
88        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
89    }
90    if let Some(ref local_var_token) = configuration.oauth_access_token {
91        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
92    };
93
94    let local_var_req = local_var_req_builder.build()?;
95    let local_var_resp = local_var_client.execute(local_var_req).await?;
96
97    let local_var_status = local_var_resp.status();
98    let local_var_content = local_var_resp.text().await?;
99
100    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
101        Ok(())
102    } else {
103        let local_var_entity: Option<DeleteDeployKeyError> = serde_json::from_str(&local_var_content).ok();
104        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
105        Err(Error::ResponseError(local_var_error))
106    }
107}
108
109pub async fn get_deploy_key(configuration: &configuration::Configuration, key_id: &str) -> Result<crate::models::DeployKey, Error<GetDeployKeyError>> {
110
111    let local_var_client = &configuration.client;
112
113    let local_var_uri_str = format!("{}/deploy_keys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(key_id));
114    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
115
116    if let Some(ref local_var_user_agent) = configuration.user_agent {
117        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
118    }
119    if let Some(ref local_var_token) = configuration.oauth_access_token {
120        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
121    };
122
123    let local_var_req = local_var_req_builder.build()?;
124    let local_var_resp = local_var_client.execute(local_var_req).await?;
125
126    let local_var_status = local_var_resp.status();
127    let local_var_content = local_var_resp.text().await?;
128
129    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
130        serde_json::from_str(&local_var_content).map_err(Error::from)
131    } else {
132        let local_var_entity: Option<GetDeployKeyError> = serde_json::from_str(&local_var_content).ok();
133        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
134        Err(Error::ResponseError(local_var_error))
135    }
136}
137
138pub async fn list_deploy_keys(configuration: &configuration::Configuration, ) -> Result<Vec<crate::models::DeployKey>, Error<ListDeployKeysError>> {
139
140    let local_var_client = &configuration.client;
141
142    let local_var_uri_str = format!("{}/deploy_keys", configuration.base_path);
143    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
144
145    if let Some(ref local_var_user_agent) = configuration.user_agent {
146        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147    }
148    if let Some(ref local_var_token) = configuration.oauth_access_token {
149        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
150    };
151
152    let local_var_req = local_var_req_builder.build()?;
153    let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155    let local_var_status = local_var_resp.status();
156    let local_var_content = local_var_resp.text().await?;
157
158    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
159        serde_json::from_str(&local_var_content).map_err(Error::from)
160    } else {
161        let local_var_entity: Option<ListDeployKeysError> = serde_json::from_str(&local_var_content).ok();
162        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
163        Err(Error::ResponseError(local_var_error))
164    }
165}
166