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 CreateIdentityError {
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 DeleteIdentityError {
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 GetIdentityError {
42 Status401(models::RespError),
43 Status403(models::RespError),
44 Status404(models::RespError),
45 Status500(models::RespError),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum ListIdentitiesError {
53 Status401(models::RespError),
54 Status403(models::RespError),
55 Status404(models::RespError),
56 Status500(models::RespError),
57 UnknownValue(serde_json::Value),
58}
59
60pub async fn create_identity(
62 configuration: &configuration::Configuration,
63 req_identity: models::ReqIdentity,
64) -> Result<models::RespResourceUrl, Error<CreateIdentityError>> {
65 let p_body_req_identity = req_identity;
67
68 let uri_str = format!("{}/v3/workflows/identities", configuration.base_path);
69 let mut req_builder = configuration
70 .client
71 .request(reqwest::Method::POST, &uri_str);
72
73 if let Some(ref user_agent) = configuration.user_agent {
74 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75 }
76 if let Some(ref apikey) = configuration.api_key {
77 let key = apikey.key.clone();
78 let value = match apikey.prefix {
79 Some(ref prefix) => format!("{} {}", prefix, key),
80 None => key,
81 };
82 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
83 };
84 req_builder = req_builder.json(&p_body_req_identity);
85
86 let req = req_builder.build()?;
87 let resp = configuration.client.execute(req).await?;
88
89 let status = resp.status();
90 let content_type = resp
91 .headers()
92 .get("content-type")
93 .and_then(|v| v.to_str().ok())
94 .unwrap_or("application/octet-stream");
95 let content_type = super::ContentType::from(content_type);
96
97 if !status.is_client_error() && !status.is_server_error() {
98 let content = resp.text().await?;
99 match content_type {
100 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
102 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespResourceUrl`")))),
103 }
104 } else {
105 let content = resp.text().await?;
106 let entity: Option<CreateIdentityError> = serde_json::from_str(&content).ok();
107 Err(Error::ResponseError(ResponseContent {
108 status,
109 content,
110 entity,
111 }))
112 }
113}
114
115pub async fn delete_identity(
117 configuration: &configuration::Configuration,
118 identity_uuid: &str,
119) -> Result<models::RespString, Error<DeleteIdentityError>> {
120 let p_path_identity_uuid = identity_uuid;
122
123 let uri_str = format!(
124 "{}/v3/workflows/identities/{identity_uuid}",
125 configuration.base_path,
126 identity_uuid = crate::apis::urlencode(p_path_identity_uuid)
127 );
128 let mut req_builder = configuration
129 .client
130 .request(reqwest::Method::DELETE, &uri_str);
131
132 if let Some(ref user_agent) = configuration.user_agent {
133 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134 }
135 if let Some(ref apikey) = configuration.api_key {
136 let key = apikey.key.clone();
137 let value = match apikey.prefix {
138 Some(ref prefix) => format!("{} {}", prefix, key),
139 None => key,
140 };
141 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
142 };
143
144 let req = req_builder.build()?;
145 let resp = configuration.client.execute(req).await?;
146
147 let status = resp.status();
148 let content_type = resp
149 .headers()
150 .get("content-type")
151 .and_then(|v| v.to_str().ok())
152 .unwrap_or("application/octet-stream");
153 let content_type = super::ContentType::from(content_type);
154
155 if !status.is_client_error() && !status.is_server_error() {
156 let content = resp.text().await?;
157 match content_type {
158 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespString`"))),
160 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`")))),
161 }
162 } else {
163 let content = resp.text().await?;
164 let entity: Option<DeleteIdentityError> = serde_json::from_str(&content).ok();
165 Err(Error::ResponseError(ResponseContent {
166 status,
167 content,
168 entity,
169 }))
170 }
171}
172
173pub async fn get_identity(
175 configuration: &configuration::Configuration,
176 identity_uuid: &str,
177) -> Result<models::RespIdentity, Error<GetIdentityError>> {
178 let p_path_identity_uuid = identity_uuid;
180
181 let uri_str = format!(
182 "{}/v3/workflows/identities/{identity_uuid}",
183 configuration.base_path,
184 identity_uuid = crate::apis::urlencode(p_path_identity_uuid)
185 );
186 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
187
188 if let Some(ref user_agent) = configuration.user_agent {
189 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
190 }
191 if let Some(ref apikey) = configuration.api_key {
192 let key = apikey.key.clone();
193 let value = match apikey.prefix {
194 Some(ref prefix) => format!("{} {}", prefix, key),
195 None => key,
196 };
197 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
198 };
199
200 let req = req_builder.build()?;
201 let resp = configuration.client.execute(req).await?;
202
203 let status = resp.status();
204 let content_type = resp
205 .headers()
206 .get("content-type")
207 .and_then(|v| v.to_str().ok())
208 .unwrap_or("application/octet-stream");
209 let content_type = super::ContentType::from(content_type);
210
211 if !status.is_client_error() && !status.is_server_error() {
212 let content = resp.text().await?;
213 match content_type {
214 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
215 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespIdentity`"))),
216 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespIdentity`")))),
217 }
218 } else {
219 let content = resp.text().await?;
220 let entity: Option<GetIdentityError> = serde_json::from_str(&content).ok();
221 Err(Error::ResponseError(ResponseContent {
222 status,
223 content,
224 entity,
225 }))
226 }
227}
228
229pub async fn list_identities(
231 configuration: &configuration::Configuration,
232) -> Result<models::RespIdentityList, Error<ListIdentitiesError>> {
233 let uri_str = format!("{}/v3/workflows/identities", configuration.base_path);
234 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
235
236 if let Some(ref user_agent) = configuration.user_agent {
237 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
238 }
239 if let Some(ref apikey) = configuration.api_key {
240 let key = apikey.key.clone();
241 let value = match apikey.prefix {
242 Some(ref prefix) => format!("{} {}", prefix, key),
243 None => key,
244 };
245 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
246 };
247
248 let req = req_builder.build()?;
249 let resp = configuration.client.execute(req).await?;
250
251 let status = resp.status();
252 let content_type = resp
253 .headers()
254 .get("content-type")
255 .and_then(|v| v.to_str().ok())
256 .unwrap_or("application/octet-stream");
257 let content_type = super::ContentType::from(content_type);
258
259 if !status.is_client_error() && !status.is_server_error() {
260 let content = resp.text().await?;
261 match content_type {
262 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
263 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespIdentityList`"))),
264 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespIdentityList`")))),
265 }
266 } else {
267 let content = resp.text().await?;
268 let entity: Option<ListIdentitiesError> = serde_json::from_str(&content).ok();
269 Err(Error::ResponseError(ResponseContent {
270 status,
271 content,
272 entity,
273 }))
274 }
275}