hab_rs_api_client/apis/
discovery_api.rs1use super::{Error, configuration};
12use crate::apis::ContentType;
13use crate::{apis::ResponseContent, models};
14use async_trait::async_trait;
15#[cfg(feature = "mockall")]
16use mockall::automock;
17use reqwest;
18use serde::{Deserialize, Serialize, de::Error as _};
19use std::sync::Arc;
20
21#[cfg_attr(feature = "mockall", automock)]
22#[async_trait]
23pub trait DiscoveryApi: Send + Sync {
24 async fn get_bindings_with_discovery_support(
28 &self,
29 ) -> Result<Vec<String>, Error<GetBindingsWithDiscoverySupportError>>;
30
31 async fn get_discovery_services_info<'binding_id, 'accept_language>(
35 &self,
36 binding_id: &'binding_id str,
37 accept_language: Option<&'accept_language str>,
38 ) -> Result<models::DiscoveryInfoDto, Error<GetDiscoveryServicesInfoError>>;
39
40 async fn scan<'binding_id, 'input>(
44 &self,
45 binding_id: &'binding_id str,
46 input: Option<&'input str>,
47 ) -> Result<i32, Error<ScanError>>;
48}
49
50pub struct DiscoveryApiClient {
51 configuration: Arc<configuration::Configuration>,
52}
53
54impl DiscoveryApiClient {
55 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
56 Self { configuration }
57 }
58}
59
60#[async_trait]
61impl DiscoveryApi for DiscoveryApiClient {
62 async fn get_bindings_with_discovery_support(
63 &self,
64 ) -> Result<Vec<String>, Error<GetBindingsWithDiscoverySupportError>> {
65 let local_var_configuration = &self.configuration;
66
67 let local_var_client = &local_var_configuration.client;
68
69 let local_var_uri_str = format!("{}/discovery", local_var_configuration.base_path);
70 let mut local_var_req_builder =
71 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
72
73 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
74 local_var_req_builder = local_var_req_builder
75 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
76 }
77 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
78 local_var_req_builder = local_var_req_builder.basic_auth(
79 local_var_auth_conf.0.to_owned(),
80 local_var_auth_conf.1.to_owned(),
81 );
82 };
83 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
84 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
85 };
86
87 let local_var_req = local_var_req_builder.build()?;
88 let local_var_resp = local_var_client.execute(local_var_req).await?;
89
90 let local_var_status = local_var_resp.status();
91 let local_var_content_type = local_var_resp
92 .headers()
93 .get("content-type")
94 .and_then(|v| v.to_str().ok())
95 .unwrap_or("application/octet-stream");
96 let local_var_content_type = super::ContentType::from(local_var_content_type);
97 let local_var_content = local_var_resp.text().await?;
98
99 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
100 match local_var_content_type {
101 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
102 ContentType::Text => {
103 return Err(Error::from(serde_json::Error::custom(
104 "Received `text/plain` content type response that cannot be converted to `Vec<String>`",
105 )));
106 }
107 ContentType::Unsupported(local_var_unknown_type) => {
108 return Err(Error::from(serde_json::Error::custom(format!(
109 "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<String>`"
110 ))));
111 }
112 }
113 } else {
114 let local_var_entity: Option<GetBindingsWithDiscoverySupportError> =
115 serde_json::from_str(&local_var_content).ok();
116 let local_var_error = ResponseContent {
117 status: local_var_status,
118 content: local_var_content,
119 entity: local_var_entity,
120 };
121 Err(Error::ResponseError(local_var_error))
122 }
123 }
124
125 async fn get_discovery_services_info<'binding_id, 'accept_language>(
126 &self,
127 binding_id: &'binding_id str,
128 accept_language: Option<&'accept_language str>,
129 ) -> Result<models::DiscoveryInfoDto, Error<GetDiscoveryServicesInfoError>> {
130 let local_var_configuration = &self.configuration;
131
132 let local_var_client = &local_var_configuration.client;
133
134 let local_var_uri_str = format!(
135 "{}/discovery/bindings/{bindingId}/info",
136 local_var_configuration.base_path,
137 bindingId = crate::apis::urlencode(binding_id)
138 );
139 let mut local_var_req_builder =
140 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
141
142 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
143 local_var_req_builder = local_var_req_builder
144 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
145 }
146 if let Some(local_var_param_value) = accept_language {
147 local_var_req_builder =
148 local_var_req_builder.header("Accept-Language", local_var_param_value.to_string());
149 }
150 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
151 local_var_req_builder = local_var_req_builder.basic_auth(
152 local_var_auth_conf.0.to_owned(),
153 local_var_auth_conf.1.to_owned(),
154 );
155 };
156 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
157 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
158 };
159
160 let local_var_req = local_var_req_builder.build()?;
161 let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163 let local_var_status = local_var_resp.status();
164 let local_var_content_type = local_var_resp
165 .headers()
166 .get("content-type")
167 .and_then(|v| v.to_str().ok())
168 .unwrap_or("application/octet-stream");
169 let local_var_content_type = super::ContentType::from(local_var_content_type);
170 let local_var_content = local_var_resp.text().await?;
171
172 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173 match local_var_content_type {
174 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
175 ContentType::Text => {
176 return Err(Error::from(serde_json::Error::custom(
177 "Received `text/plain` content type response that cannot be converted to `models::DiscoveryInfoDto`",
178 )));
179 }
180 ContentType::Unsupported(local_var_unknown_type) => {
181 return Err(Error::from(serde_json::Error::custom(format!(
182 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DiscoveryInfoDto`"
183 ))));
184 }
185 }
186 } else {
187 let local_var_entity: Option<GetDiscoveryServicesInfoError> =
188 serde_json::from_str(&local_var_content).ok();
189 let local_var_error = ResponseContent {
190 status: local_var_status,
191 content: local_var_content,
192 entity: local_var_entity,
193 };
194 Err(Error::ResponseError(local_var_error))
195 }
196 }
197
198 async fn scan<'binding_id, 'input>(
199 &self,
200 binding_id: &'binding_id str,
201 input: Option<&'input str>,
202 ) -> Result<i32, Error<ScanError>> {
203 let local_var_configuration = &self.configuration;
204
205 let local_var_client = &local_var_configuration.client;
206
207 let local_var_uri_str = format!(
208 "{}/discovery/bindings/{bindingId}/scan",
209 local_var_configuration.base_path,
210 bindingId = crate::apis::urlencode(binding_id)
211 );
212 let mut local_var_req_builder =
213 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
214
215 if let Some(ref local_var_str) = input {
216 local_var_req_builder =
217 local_var_req_builder.query(&[("input", &local_var_str.to_string())]);
218 }
219 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
220 local_var_req_builder = local_var_req_builder
221 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
222 }
223 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
224 local_var_req_builder = local_var_req_builder.basic_auth(
225 local_var_auth_conf.0.to_owned(),
226 local_var_auth_conf.1.to_owned(),
227 );
228 };
229 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
230 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
231 };
232
233 let local_var_req = local_var_req_builder.build()?;
234 let local_var_resp = local_var_client.execute(local_var_req).await?;
235
236 let local_var_status = local_var_resp.status();
237 let local_var_content_type = local_var_resp
238 .headers()
239 .get("content-type")
240 .and_then(|v| v.to_str().ok())
241 .unwrap_or("application/octet-stream");
242 let local_var_content_type = super::ContentType::from(local_var_content_type);
243 let local_var_content = local_var_resp.text().await?;
244
245 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
246 match local_var_content_type {
247 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
248 ContentType::Text => {
249 return Err(Error::from(serde_json::Error::custom(
250 "Received `text/plain` content type response that cannot be converted to `i32`",
251 )));
252 }
253 ContentType::Unsupported(local_var_unknown_type) => {
254 return Err(Error::from(serde_json::Error::custom(format!(
255 "Received `{local_var_unknown_type}` content type response that cannot be converted to `i32`"
256 ))));
257 }
258 }
259 } else {
260 let local_var_entity: Option<ScanError> = serde_json::from_str(&local_var_content).ok();
261 let local_var_error = ResponseContent {
262 status: local_var_status,
263 content: local_var_content,
264 entity: local_var_entity,
265 };
266 Err(Error::ResponseError(local_var_error))
267 }
268 }
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize)]
273#[serde(untagged)]
274pub enum GetBindingsWithDiscoverySupportError {
275 UnknownValue(serde_json::Value),
276}
277
278#[derive(Debug, Clone, Serialize, Deserialize)]
280#[serde(untagged)]
281pub enum GetDiscoveryServicesInfoError {
282 Status404(),
283 UnknownValue(serde_json::Value),
284}
285
286#[derive(Debug, Clone, Serialize, Deserialize)]
288#[serde(untagged)]
289pub enum ScanError {
290 Status404(),
291 UnknownValue(serde_json::Value),
292}