1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateSecretError {
20 Status400(models::RespError),
21 Status401(models::RespError),
22 Status409(models::RespError),
23 Status415(models::RespError),
24 Status500(models::RespError),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteSecretError {
32 Status401(models::RespError),
33 Status403(models::RespError),
34 Status404(models::RespError),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetSecretError {
42 Status401(models::RespError),
43 Status500(models::RespError),
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum ListSecretsError {
51 Status401(models::RespError),
52 Status500(models::RespError),
53 UnknownValue(serde_json::Value),
54}
55
56pub async fn create_secret(
58 configuration: &configuration::Configuration,
59 req_create_secret: models::ReqCreateSecret,
60) -> Result<models::RespSecret, Error<CreateSecretError>> {
61 let p_body_req_create_secret = req_create_secret;
63
64 let uri_str = format!("{}/v3/workflows/secrets", configuration.base_path);
65 let mut req_builder = configuration
66 .client
67 .request(reqwest::Method::POST, &uri_str);
68
69 if let Some(ref user_agent) = configuration.user_agent {
70 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71 }
72 if let Some(ref apikey) = configuration.api_key {
73 let key = apikey.key.clone();
74 let value = match apikey.prefix {
75 Some(ref prefix) => format!("{} {}", prefix, key),
76 None => key,
77 };
78 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
79 };
80 req_builder = req_builder.json(&p_body_req_create_secret);
81
82 let req = req_builder.build()?;
83 let resp = configuration.client.execute(req).await?;
84
85 let status = resp.status();
86 let content_type = resp
87 .headers()
88 .get("content-type")
89 .and_then(|v| v.to_str().ok())
90 .unwrap_or("application/octet-stream");
91 let content_type = super::ContentType::from(content_type);
92
93 if !status.is_client_error() && !status.is_server_error() {
94 let content = resp.text().await?;
95 match content_type {
96 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSecret`"))),
98 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSecret`")))),
99 }
100 } else {
101 let content = resp.text().await?;
102 let entity: Option<CreateSecretError> = serde_json::from_str(&content).ok();
103 Err(Error::ResponseError(ResponseContent {
104 status,
105 content,
106 entity,
107 }))
108 }
109}
110
111pub async fn delete_secret(
113 configuration: &configuration::Configuration,
114 secret_id: &str,
115) -> Result<models::RespString, Error<DeleteSecretError>> {
116 let p_path_secret_id = secret_id;
118
119 let uri_str = format!(
120 "{}/v3/workflows/secrets/{secret_id}",
121 configuration.base_path,
122 secret_id = crate::apis::urlencode(p_path_secret_id)
123 );
124 let mut req_builder = configuration
125 .client
126 .request(reqwest::Method::DELETE, &uri_str);
127
128 if let Some(ref user_agent) = configuration.user_agent {
129 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130 }
131 if let Some(ref apikey) = configuration.api_key {
132 let key = apikey.key.clone();
133 let value = match apikey.prefix {
134 Some(ref prefix) => format!("{} {}", prefix, key),
135 None => key,
136 };
137 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
138 };
139
140 let req = req_builder.build()?;
141 let resp = configuration.client.execute(req).await?;
142
143 let status = resp.status();
144 let content_type = resp
145 .headers()
146 .get("content-type")
147 .and_then(|v| v.to_str().ok())
148 .unwrap_or("application/octet-stream");
149 let content_type = super::ContentType::from(content_type);
150
151 if !status.is_client_error() && !status.is_server_error() {
152 let content = resp.text().await?;
153 match content_type {
154 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
155 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespString`"))),
156 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespString`")))),
157 }
158 } else {
159 let content = resp.text().await?;
160 let entity: Option<DeleteSecretError> = serde_json::from_str(&content).ok();
161 Err(Error::ResponseError(ResponseContent {
162 status,
163 content,
164 entity,
165 }))
166 }
167}
168
169pub async fn get_secret(
171 configuration: &configuration::Configuration,
172 secret_id: &str,
173) -> Result<models::RespSecret, Error<GetSecretError>> {
174 let p_path_secret_id = secret_id;
176
177 let uri_str = format!(
178 "{}/v3/workflows/secrets/{secret_id}",
179 configuration.base_path,
180 secret_id = crate::apis::urlencode(p_path_secret_id)
181 );
182 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
183
184 if let Some(ref user_agent) = configuration.user_agent {
185 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
186 }
187 if let Some(ref apikey) = configuration.api_key {
188 let key = apikey.key.clone();
189 let value = match apikey.prefix {
190 Some(ref prefix) => format!("{} {}", prefix, key),
191 None => key,
192 };
193 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
194 };
195
196 let req = req_builder.build()?;
197 let resp = configuration.client.execute(req).await?;
198
199 let status = resp.status();
200 let content_type = resp
201 .headers()
202 .get("content-type")
203 .and_then(|v| v.to_str().ok())
204 .unwrap_or("application/octet-stream");
205 let content_type = super::ContentType::from(content_type);
206
207 if !status.is_client_error() && !status.is_server_error() {
208 let content = resp.text().await?;
209 match content_type {
210 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSecret`"))),
212 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSecret`")))),
213 }
214 } else {
215 let content = resp.text().await?;
216 let entity: Option<GetSecretError> = serde_json::from_str(&content).ok();
217 Err(Error::ResponseError(ResponseContent {
218 status,
219 content,
220 entity,
221 }))
222 }
223}
224
225pub async fn list_secrets(
227 configuration: &configuration::Configuration,
228) -> Result<models::RespSecretList, Error<ListSecretsError>> {
229 let uri_str = format!("{}/v3/workflows/secrets", configuration.base_path);
230 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
231
232 if let Some(ref user_agent) = configuration.user_agent {
233 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
234 }
235 if let Some(ref apikey) = configuration.api_key {
236 let key = apikey.key.clone();
237 let value = match apikey.prefix {
238 Some(ref prefix) => format!("{} {}", prefix, key),
239 None => key,
240 };
241 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
242 };
243
244 let req = req_builder.build()?;
245 let resp = configuration.client.execute(req).await?;
246
247 let status = resp.status();
248 let content_type = resp
249 .headers()
250 .get("content-type")
251 .and_then(|v| v.to_str().ok())
252 .unwrap_or("application/octet-stream");
253 let content_type = super::ContentType::from(content_type);
254
255 if !status.is_client_error() && !status.is_server_error() {
256 let content = resp.text().await?;
257 match content_type {
258 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
259 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSecretList`"))),
260 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSecretList`")))),
261 }
262 } else {
263 let content = resp.text().await?;
264 let entity: Option<ListSecretsError> = serde_json::from_str(&content).ok();
265 Err(Error::ResponseError(ResponseContent {
266 status,
267 content,
268 entity,
269 }))
270 }
271}