netlify_rust/apis/
deploy_key_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateDeployKeyError {
22 DefaultResponse(crate::models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteDeployKeyError {
30 DefaultResponse(crate::models::Error),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetDeployKeyError {
38 DefaultResponse(crate::models::Error),
39 UnknownValue(serde_json::Value),
40}
41
42#[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