1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateVariableError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteVariableError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DeleteVariablesBulkError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum EncryptValueError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ExistsVariableError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetVariableError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetVariableValueError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListContextualVariablesError {
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ListVariableError {
78 UnknownValue(serde_json::Value),
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum UpdateVariableError {
85 UnknownValue(serde_json::Value),
86}
87
88
89pub async fn create_variable(configuration: &configuration::Configuration, workspace: &str, create_variable: models::CreateVariable, already_encrypted: Option<bool>) -> Result<String, Error<CreateVariableError>> {
90 let local_var_configuration = configuration;
91
92 let local_var_client = &local_var_configuration.client;
93
94 let local_var_uri_str = format!("{}/w/{workspace}/variables/create", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
95 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
96
97 if let Some(ref local_var_str) = already_encrypted {
98 local_var_req_builder = local_var_req_builder.query(&[("already_encrypted", &local_var_str.to_string())]);
99 }
100 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
101 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
102 }
103 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
104 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
105 };
106 local_var_req_builder = local_var_req_builder.json(&create_variable);
107
108 let local_var_req = local_var_req_builder.build()?;
109 let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111 let local_var_status = local_var_resp.status();
112 let local_var_content = local_var_resp.text().await?;
113
114 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115 crate::from_str_patched(&local_var_content).map_err(Error::from)
116 } else {
117 let local_var_entity: Option<CreateVariableError> = crate::from_str_patched(&local_var_content).ok();
118 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
119 Err(Error::ResponseError(local_var_error))
120 }
121}
122
123pub async fn delete_variable(configuration: &configuration::Configuration, workspace: &str, path: &str) -> Result<String, Error<DeleteVariableError>> {
124 let local_var_configuration = configuration;
125
126 let local_var_client = &local_var_configuration.client;
127
128 let local_var_uri_str = format!("{}/w/{workspace}/variables/delete/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path));
129 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
130
131 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
132 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
133 }
134 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
135 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
136 };
137
138 let local_var_req = local_var_req_builder.build()?;
139 let local_var_resp = local_var_client.execute(local_var_req).await?;
140
141 let local_var_status = local_var_resp.status();
142 let local_var_content = local_var_resp.text().await?;
143
144 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
145 crate::from_str_patched(&local_var_content).map_err(Error::from)
146 } else {
147 let local_var_entity: Option<DeleteVariableError> = crate::from_str_patched(&local_var_content).ok();
148 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
149 Err(Error::ResponseError(local_var_error))
150 }
151}
152
153pub async fn delete_variables_bulk(configuration: &configuration::Configuration, workspace: &str, delete_variables_bulk_request: models::DeleteVariablesBulkRequest) -> Result<Vec<String>, Error<DeleteVariablesBulkError>> {
154 let local_var_configuration = configuration;
155
156 let local_var_client = &local_var_configuration.client;
157
158 let local_var_uri_str = format!("{}/w/{workspace}/variables/delete_bulk", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
159 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
160
161 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
162 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
163 }
164 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
165 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
166 };
167 local_var_req_builder = local_var_req_builder.json(&delete_variables_bulk_request);
168
169 let local_var_req = local_var_req_builder.build()?;
170 let local_var_resp = local_var_client.execute(local_var_req).await?;
171
172 let local_var_status = local_var_resp.status();
173 let local_var_content = local_var_resp.text().await?;
174
175 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176 crate::from_str_patched(&local_var_content).map_err(Error::from)
177 } else {
178 let local_var_entity: Option<DeleteVariablesBulkError> = crate::from_str_patched(&local_var_content).ok();
179 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180 Err(Error::ResponseError(local_var_error))
181 }
182}
183
184pub async fn encrypt_value(configuration: &configuration::Configuration, workspace: &str, body: &str) -> Result<String, Error<EncryptValueError>> {
185 let local_var_configuration = configuration;
186
187 let local_var_client = &local_var_configuration.client;
188
189 let local_var_uri_str = format!("{}/w/{workspace}/variables/encrypt", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
190 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
191
192 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
193 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
194 }
195 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
196 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
197 };
198 local_var_req_builder = local_var_req_builder.json(&body);
199
200 let local_var_req = local_var_req_builder.build()?;
201 let local_var_resp = local_var_client.execute(local_var_req).await?;
202
203 let local_var_status = local_var_resp.status();
204 let local_var_content = local_var_resp.text().await?;
205
206 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
207 crate::from_str_patched(&local_var_content).map_err(Error::from)
208 } else {
209 let local_var_entity: Option<EncryptValueError> = crate::from_str_patched(&local_var_content).ok();
210 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
211 Err(Error::ResponseError(local_var_error))
212 }
213}
214
215pub async fn exists_variable(configuration: &configuration::Configuration, workspace: &str, path: &str) -> Result<bool, Error<ExistsVariableError>> {
216 let local_var_configuration = configuration;
217
218 let local_var_client = &local_var_configuration.client;
219
220 let local_var_uri_str = format!("{}/w/{workspace}/variables/exists/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path));
221 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
222
223 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
224 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
225 }
226 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
227 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
228 };
229
230 let local_var_req = local_var_req_builder.build()?;
231 let local_var_resp = local_var_client.execute(local_var_req).await?;
232
233 let local_var_status = local_var_resp.status();
234 let local_var_content = local_var_resp.text().await?;
235
236 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
237 crate::from_str_patched(&local_var_content).map_err(Error::from)
238 } else {
239 let local_var_entity: Option<ExistsVariableError> = crate::from_str_patched(&local_var_content).ok();
240 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
241 Err(Error::ResponseError(local_var_error))
242 }
243}
244
245pub async fn get_variable(configuration: &configuration::Configuration, workspace: &str, path: &str, decrypt_secret: Option<bool>, include_encrypted: Option<bool>) -> Result<models::ListableVariable, Error<GetVariableError>> {
246 let local_var_configuration = configuration;
247
248 let local_var_client = &local_var_configuration.client;
249
250 let local_var_uri_str = format!("{}/w/{workspace}/variables/get/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path));
251 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
252
253 if let Some(ref local_var_str) = decrypt_secret {
254 local_var_req_builder = local_var_req_builder.query(&[("decrypt_secret", &local_var_str.to_string())]);
255 }
256 if let Some(ref local_var_str) = include_encrypted {
257 local_var_req_builder = local_var_req_builder.query(&[("include_encrypted", &local_var_str.to_string())]);
258 }
259 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
260 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
261 }
262 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
263 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
264 };
265
266 let local_var_req = local_var_req_builder.build()?;
267 let local_var_resp = local_var_client.execute(local_var_req).await?;
268
269 let local_var_status = local_var_resp.status();
270 let local_var_content = local_var_resp.text().await?;
271
272 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
273 crate::from_str_patched(&local_var_content).map_err(Error::from)
274 } else {
275 let local_var_entity: Option<GetVariableError> = crate::from_str_patched(&local_var_content).ok();
276 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
277 Err(Error::ResponseError(local_var_error))
278 }
279}
280
281pub async fn get_variable_value(configuration: &configuration::Configuration, workspace: &str, path: &str, allow_cache: Option<bool>) -> Result<String, Error<GetVariableValueError>> {
282 let local_var_configuration = configuration;
283
284 let local_var_client = &local_var_configuration.client;
285
286 let local_var_uri_str = format!("{}/w/{workspace}/variables/get_value/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path));
287 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
288
289 if let Some(ref local_var_str) = allow_cache {
290 local_var_req_builder = local_var_req_builder.query(&[("allow_cache", &local_var_str.to_string())]);
291 }
292 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
293 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
294 }
295 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
296 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
297 };
298
299 let local_var_req = local_var_req_builder.build()?;
300 let local_var_resp = local_var_client.execute(local_var_req).await?;
301
302 let local_var_status = local_var_resp.status();
303 let local_var_content = local_var_resp.text().await?;
304
305 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
306 crate::from_str_patched(&local_var_content).map_err(Error::from)
307 } else {
308 let local_var_entity: Option<GetVariableValueError> = crate::from_str_patched(&local_var_content).ok();
309 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
310 Err(Error::ResponseError(local_var_error))
311 }
312}
313
314pub async fn list_contextual_variables(configuration: &configuration::Configuration, workspace: &str) -> Result<Vec<models::ContextualVariable>, Error<ListContextualVariablesError>> {
315 let local_var_configuration = configuration;
316
317 let local_var_client = &local_var_configuration.client;
318
319 let local_var_uri_str = format!("{}/w/{workspace}/variables/list_contextual", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
320 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
321
322 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
323 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
324 }
325 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
326 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
327 };
328
329 let local_var_req = local_var_req_builder.build()?;
330 let local_var_resp = local_var_client.execute(local_var_req).await?;
331
332 let local_var_status = local_var_resp.status();
333 let local_var_content = local_var_resp.text().await?;
334
335 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
336 crate::from_str_patched(&local_var_content).map_err(Error::from)
337 } else {
338 let local_var_entity: Option<ListContextualVariablesError> = crate::from_str_patched(&local_var_content).ok();
339 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
340 Err(Error::ResponseError(local_var_error))
341 }
342}
343
344pub async fn list_variable(configuration: &configuration::Configuration, workspace: &str, path_start: Option<&str>, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<models::ListableVariable>, Error<ListVariableError>> {
345 let local_var_configuration = configuration;
346
347 let local_var_client = &local_var_configuration.client;
348
349 let local_var_uri_str = format!("{}/w/{workspace}/variables/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
350 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
351
352 if let Some(ref local_var_str) = path_start {
353 local_var_req_builder = local_var_req_builder.query(&[("path_start", &local_var_str.to_string())]);
354 }
355 if let Some(ref local_var_str) = page {
356 local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
357 }
358 if let Some(ref local_var_str) = per_page {
359 local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
360 }
361 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
362 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
363 }
364 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
365 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
366 };
367
368 let local_var_req = local_var_req_builder.build()?;
369 let local_var_resp = local_var_client.execute(local_var_req).await?;
370
371 let local_var_status = local_var_resp.status();
372 let local_var_content = local_var_resp.text().await?;
373
374 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
375 crate::from_str_patched(&local_var_content).map_err(Error::from)
376 } else {
377 let local_var_entity: Option<ListVariableError> = crate::from_str_patched(&local_var_content).ok();
378 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
379 Err(Error::ResponseError(local_var_error))
380 }
381}
382
383pub async fn update_variable(configuration: &configuration::Configuration, workspace: &str, path: &str, edit_variable: models::EditVariable, already_encrypted: Option<bool>) -> Result<String, Error<UpdateVariableError>> {
384 let local_var_configuration = configuration;
385
386 let local_var_client = &local_var_configuration.client;
387
388 let local_var_uri_str = format!("{}/w/{workspace}/variables/update/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path));
389 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
390
391 if let Some(ref local_var_str) = already_encrypted {
392 local_var_req_builder = local_var_req_builder.query(&[("already_encrypted", &local_var_str.to_string())]);
393 }
394 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
395 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
396 }
397 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
398 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
399 };
400 local_var_req_builder = local_var_req_builder.json(&edit_variable);
401
402 let local_var_req = local_var_req_builder.build()?;
403 let local_var_resp = local_var_client.execute(local_var_req).await?;
404
405 let local_var_status = local_var_resp.status();
406 let local_var_content = local_var_resp.text().await?;
407
408 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
409 crate::from_str_patched(&local_var_content).map_err(Error::from)
410 } else {
411 let local_var_entity: Option<UpdateVariableError> = crate::from_str_patched(&local_var_content).ok();
412 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
413 Err(Error::ResponseError(local_var_error))
414 }
415}
416