openapi_service_fabric/apis/
infrastructure_api.rs1use 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 InvokeInfrastructureCommandError {
20 DefaultResponse(models::FabricError),
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum InvokeInfrastructureQueryError {
28 DefaultResponse(models::FabricError),
29 UnknownValue(serde_json::Value),
30}
31
32pub async fn invoke_infrastructure_command(
34 configuration: &configuration::Configuration,
35 api_version: &str,
36 command: &str,
37 service_id: Option<&str>,
38 timeout: Option<i64>,
39) -> Result<String, Error<InvokeInfrastructureCommandError>> {
40 let p_query_api_version = api_version;
42 let p_query_command = command;
43 let p_query_service_id = service_id;
44 let p_query_timeout = timeout;
45
46 let uri_str = format!("{}/$/InvokeInfrastructureCommand", configuration.base_path);
47 let mut req_builder = configuration
48 .client
49 .request(reqwest::Method::POST, &uri_str);
50
51 req_builder = req_builder.query(&[("api-version", &p_query_api_version.to_string())]);
52 req_builder = req_builder.query(&[("Command", &p_query_command.to_string())]);
53 if let Some(ref param_value) = p_query_service_id {
54 req_builder = req_builder.query(&[("ServiceId", ¶m_value.to_string())]);
55 }
56 if let Some(ref param_value) = p_query_timeout {
57 req_builder = req_builder.query(&[("timeout", ¶m_value.to_string())]);
58 }
59 if let Some(ref user_agent) = configuration.user_agent {
60 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61 }
62
63 let req = req_builder.build()?;
64 let resp = configuration.client.execute(req).await?;
65
66 let status = resp.status();
67 let content_type = resp
68 .headers()
69 .get("content-type")
70 .and_then(|v| v.to_str().ok())
71 .unwrap_or("application/octet-stream");
72 let content_type = super::ContentType::from(content_type);
73
74 if !status.is_client_error() && !status.is_server_error() {
75 let content = resp.text().await?;
76 match content_type {
77 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))),
79 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
80 }
81 } else {
82 let content = resp.text().await?;
83 let entity: Option<InvokeInfrastructureCommandError> = serde_json::from_str(&content).ok();
84 Err(Error::ResponseError(ResponseContent {
85 status,
86 content,
87 entity,
88 }))
89 }
90}
91
92pub async fn invoke_infrastructure_query(
94 configuration: &configuration::Configuration,
95 api_version: &str,
96 command: &str,
97 service_id: Option<&str>,
98 timeout: Option<i64>,
99) -> Result<String, Error<InvokeInfrastructureQueryError>> {
100 let p_query_api_version = api_version;
102 let p_query_command = command;
103 let p_query_service_id = service_id;
104 let p_query_timeout = timeout;
105
106 let uri_str = format!("{}/$/InvokeInfrastructureQuery", configuration.base_path);
107 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
108
109 req_builder = req_builder.query(&[("api-version", &p_query_api_version.to_string())]);
110 req_builder = req_builder.query(&[("Command", &p_query_command.to_string())]);
111 if let Some(ref param_value) = p_query_service_id {
112 req_builder = req_builder.query(&[("ServiceId", ¶m_value.to_string())]);
113 }
114 if let Some(ref param_value) = p_query_timeout {
115 req_builder = req_builder.query(&[("timeout", ¶m_value.to_string())]);
116 }
117 if let Some(ref user_agent) = configuration.user_agent {
118 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119 }
120
121 let req = req_builder.build()?;
122 let resp = configuration.client.execute(req).await?;
123
124 let status = resp.status();
125 let content_type = resp
126 .headers()
127 .get("content-type")
128 .and_then(|v| v.to_str().ok())
129 .unwrap_or("application/octet-stream");
130 let content_type = super::ContentType::from(content_type);
131
132 if !status.is_client_error() && !status.is_server_error() {
133 let content = resp.text().await?;
134 match content_type {
135 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))),
137 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
138 }
139 } else {
140 let content = resp.text().await?;
141 let entity: Option<InvokeInfrastructureQueryError> = serde_json::from_str(&content).ok();
142 Err(Error::ResponseError(ResponseContent {
143 status,
144 content,
145 entity,
146 }))
147 }
148}