Skip to main content

openapi_service_fabric/apis/
mesh_secrets_api.rs

1/*
2 * Service Fabric Client APIs
3 *
4 * Service Fabric REST Client APIs allows management of Service Fabric clusters, applications and services.
5 *
6 * The version of the OpenAPI document: 8.2
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`mesh_secret_create_or_update`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum MeshSecretCreateOrUpdateError {
20    DefaultResponse(models::FabricError),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`mesh_secret_delete`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum MeshSecretDeleteError {
28    DefaultResponse(models::FabricError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`mesh_secret_get`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum MeshSecretGetError {
36    DefaultResponse(models::FabricError),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`mesh_secret_list`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum MeshSecretListError {
44    DefaultResponse(models::FabricError),
45    UnknownValue(serde_json::Value),
46}
47
48/// Creates a Secret resource with the specified name, description and properties. If Secret resource with the same name exists, then it is updated with the specified description and properties. Once created, the kind and contentType of a secret resource cannot be updated.
49pub async fn mesh_secret_create_or_update(
50    configuration: &configuration::Configuration,
51    api_version: &str,
52    secret_resource_name: &str,
53    secret_resource_description: models::SecretResourceDescription,
54) -> Result<models::SecretResourceDescription, Error<MeshSecretCreateOrUpdateError>> {
55    // add a prefix to parameters to efficiently prevent name collisions
56    let p_query_api_version = api_version;
57    let p_path_secret_resource_name = secret_resource_name;
58    let p_body_secret_resource_description = secret_resource_description;
59
60    let uri_str = format!(
61        "{}/Resources/Secrets/{secretResourceName}",
62        configuration.base_path,
63        secretResourceName = crate::apis::urlencode(p_path_secret_resource_name)
64    );
65    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
66
67    req_builder = req_builder.query(&[("api-version", &p_query_api_version.to_string())]);
68    if let Some(ref user_agent) = configuration.user_agent {
69        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
70    }
71    req_builder = req_builder.json(&p_body_secret_resource_description);
72
73    let req = req_builder.build()?;
74    let resp = configuration.client.execute(req).await?;
75
76    let status = resp.status();
77    let content_type = resp
78        .headers()
79        .get("content-type")
80        .and_then(|v| v.to_str().ok())
81        .unwrap_or("application/octet-stream");
82    let content_type = super::ContentType::from(content_type);
83
84    if !status.is_client_error() && !status.is_server_error() {
85        let content = resp.text().await?;
86        match content_type {
87            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
88            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretResourceDescription`"))),
89            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SecretResourceDescription`")))),
90        }
91    } else {
92        let content = resp.text().await?;
93        let entity: Option<MeshSecretCreateOrUpdateError> = serde_json::from_str(&content).ok();
94        Err(Error::ResponseError(ResponseContent {
95            status,
96            content,
97            entity,
98        }))
99    }
100}
101
102/// Deletes the specified Secret resource and all of its named values.
103pub async fn mesh_secret_delete(
104    configuration: &configuration::Configuration,
105    api_version: &str,
106    secret_resource_name: &str,
107) -> Result<(), Error<MeshSecretDeleteError>> {
108    // add a prefix to parameters to efficiently prevent name collisions
109    let p_query_api_version = api_version;
110    let p_path_secret_resource_name = secret_resource_name;
111
112    let uri_str = format!(
113        "{}/Resources/Secrets/{secretResourceName}",
114        configuration.base_path,
115        secretResourceName = crate::apis::urlencode(p_path_secret_resource_name)
116    );
117    let mut req_builder = configuration
118        .client
119        .request(reqwest::Method::DELETE, &uri_str);
120
121    req_builder = req_builder.query(&[("api-version", &p_query_api_version.to_string())]);
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125
126    let req = req_builder.build()?;
127    let resp = configuration.client.execute(req).await?;
128
129    let status = resp.status();
130
131    if !status.is_client_error() && !status.is_server_error() {
132        Ok(())
133    } else {
134        let content = resp.text().await?;
135        let entity: Option<MeshSecretDeleteError> = serde_json::from_str(&content).ok();
136        Err(Error::ResponseError(ResponseContent {
137            status,
138            content,
139            entity,
140        }))
141    }
142}
143
144/// Gets the information about the Secret resource with the given name. The information include the description and other properties of the Secret.
145pub async fn mesh_secret_get(
146    configuration: &configuration::Configuration,
147    api_version: &str,
148    secret_resource_name: &str,
149) -> Result<models::SecretResourceDescription, Error<MeshSecretGetError>> {
150    // add a prefix to parameters to efficiently prevent name collisions
151    let p_query_api_version = api_version;
152    let p_path_secret_resource_name = secret_resource_name;
153
154    let uri_str = format!(
155        "{}/Resources/Secrets/{secretResourceName}",
156        configuration.base_path,
157        secretResourceName = crate::apis::urlencode(p_path_secret_resource_name)
158    );
159    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
160
161    req_builder = req_builder.query(&[("api-version", &p_query_api_version.to_string())]);
162    if let Some(ref user_agent) = configuration.user_agent {
163        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
164    }
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170    let content_type = resp
171        .headers()
172        .get("content-type")
173        .and_then(|v| v.to_str().ok())
174        .unwrap_or("application/octet-stream");
175    let content_type = super::ContentType::from(content_type);
176
177    if !status.is_client_error() && !status.is_server_error() {
178        let content = resp.text().await?;
179        match content_type {
180            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
181            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretResourceDescription`"))),
182            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SecretResourceDescription`")))),
183        }
184    } else {
185        let content = resp.text().await?;
186        let entity: Option<MeshSecretGetError> = serde_json::from_str(&content).ok();
187        Err(Error::ResponseError(ResponseContent {
188            status,
189            content,
190            entity,
191        }))
192    }
193}
194
195/// Gets the information about all secret resources in a given resource group. The information include the description and other properties of the Secret.
196pub async fn mesh_secret_list(
197    configuration: &configuration::Configuration,
198    api_version: &str,
199) -> Result<models::PagedSecretResourceDescriptionList, Error<MeshSecretListError>> {
200    // add a prefix to parameters to efficiently prevent name collisions
201    let p_query_api_version = api_version;
202
203    let uri_str = format!("{}/Resources/Secrets", configuration.base_path);
204    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
205
206    req_builder = req_builder.query(&[("api-version", &p_query_api_version.to_string())]);
207    if let Some(ref user_agent) = configuration.user_agent {
208        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
209    }
210
211    let req = req_builder.build()?;
212    let resp = configuration.client.execute(req).await?;
213
214    let status = resp.status();
215    let content_type = resp
216        .headers()
217        .get("content-type")
218        .and_then(|v| v.to_str().ok())
219        .unwrap_or("application/octet-stream");
220    let content_type = super::ContentType::from(content_type);
221
222    if !status.is_client_error() && !status.is_server_error() {
223        let content = resp.text().await?;
224        match content_type {
225            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
226            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PagedSecretResourceDescriptionList`"))),
227            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PagedSecretResourceDescriptionList`")))),
228        }
229    } else {
230        let content = resp.text().await?;
231        let entity: Option<MeshSecretListError> = serde_json::from_str(&content).ok();
232        Err(Error::ResponseError(ResponseContent {
233            status,
234            content,
235            entity,
236        }))
237    }
238}