harbor_api/apis/
scanner_api.rs

1/*
2 * Harbor API
3 *
4 * These APIs provide services for manipulating Harbor project.
5 *
6 * The version of the OpenAPI document: 2.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`create_scanner`]
18#[derive(Clone, Debug)]
19pub struct CreateScannerParams {
20    /// A scanner registration to be created.
21    pub registration: models::ScannerRegistrationReq,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>
24}
25
26/// struct for passing parameters to the method [`delete_scanner`]
27#[derive(Clone, Debug)]
28pub struct DeleteScannerParams {
29    /// The scanner registration identifier.
30    pub registration_id: String,
31    /// An unique ID for the request
32    pub x_request_id: Option<String>
33}
34
35/// struct for passing parameters to the method [`get_scanner`]
36#[derive(Clone, Debug)]
37pub struct GetScannerParams {
38    /// The scanner registration identifer.
39    pub registration_id: String,
40    /// An unique ID for the request
41    pub x_request_id: Option<String>
42}
43
44/// struct for passing parameters to the method [`get_scanner_metadata`]
45#[derive(Clone, Debug)]
46pub struct GetScannerMetadataParams {
47    /// The scanner registration identifier.
48    pub registration_id: String,
49    /// An unique ID for the request
50    pub x_request_id: Option<String>
51}
52
53/// struct for passing parameters to the method [`list_scanners`]
54#[derive(Clone, Debug)]
55pub struct ListScannersParams {
56    /// An unique ID for the request
57    pub x_request_id: Option<String>,
58    /// Query string to query resources. Supported query patterns are \"exact match(k=v)\", \"fuzzy match(k=~v)\", \"range(k=[min~max])\", \"list with union releationship(k={v1 v2 v3})\" and \"list with intersetion relationship(k=(v1 v2 v3))\". The value of range and list can be string(enclosed by \" or '), integer or time(in format \"2020-04-09 02:36:00\"). All of these query patterns should be put in the query string \"q=xxx\" and splitted by \",\". e.g. q=k1=v1,k2=~v2,k3=[min~max]
59    pub q: Option<String>,
60    /// Sort the resource list in ascending or descending order. e.g. sort by field1 in ascending order and field2 in descending order with \"sort=field1,-field2\"
61    pub sort: Option<String>,
62    /// The page number
63    pub page: Option<i64>,
64    /// The size of per page
65    pub page_size: Option<i64>
66}
67
68/// struct for passing parameters to the method [`ping_scanner`]
69#[derive(Clone, Debug)]
70pub struct PingScannerParams {
71    /// A scanner registration settings to be tested.
72    pub settings: models::ScannerRegistrationSettings,
73    /// An unique ID for the request
74    pub x_request_id: Option<String>
75}
76
77/// struct for passing parameters to the method [`set_scanner_as_default`]
78#[derive(Clone, Debug)]
79pub struct SetScannerAsDefaultParams {
80    /// The scanner registration identifier.
81    pub registration_id: String,
82    pub payload: models::IsDefault,
83    /// An unique ID for the request
84    pub x_request_id: Option<String>
85}
86
87/// struct for passing parameters to the method [`update_scanner`]
88#[derive(Clone, Debug)]
89pub struct UpdateScannerParams {
90    /// The scanner registration identifier.
91    pub registration_id: String,
92    /// A scanner registraiton to be updated.
93    pub registration: models::ScannerRegistrationReq,
94    /// An unique ID for the request
95    pub x_request_id: Option<String>
96}
97
98
99/// struct for typed errors of method [`create_scanner`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum CreateScannerError {
103    Status400(models::Errors),
104    Status401(models::Errors),
105    Status403(models::Errors),
106    Status500(models::Errors),
107    UnknownValue(serde_json::Value),
108}
109
110/// struct for typed errors of method [`delete_scanner`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum DeleteScannerError {
114    Status401(models::Errors),
115    Status403(models::Errors),
116    Status404(models::Errors),
117    Status500(models::Errors),
118    UnknownValue(serde_json::Value),
119}
120
121/// struct for typed errors of method [`get_scanner`]
122#[derive(Debug, Clone, Serialize, Deserialize)]
123#[serde(untagged)]
124pub enum GetScannerError {
125    Status401(models::Errors),
126    Status403(models::Errors),
127    Status404(models::Errors),
128    Status500(models::Errors),
129    UnknownValue(serde_json::Value),
130}
131
132/// struct for typed errors of method [`get_scanner_metadata`]
133#[derive(Debug, Clone, Serialize, Deserialize)]
134#[serde(untagged)]
135pub enum GetScannerMetadataError {
136    Status401(models::Errors),
137    Status403(models::Errors),
138    Status500(models::Errors),
139    UnknownValue(serde_json::Value),
140}
141
142/// struct for typed errors of method [`list_scanners`]
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(untagged)]
145pub enum ListScannersError {
146    Status400(models::Errors),
147    Status401(models::Errors),
148    Status403(models::Errors),
149    Status500(models::Errors),
150    UnknownValue(serde_json::Value),
151}
152
153/// struct for typed errors of method [`ping_scanner`]
154#[derive(Debug, Clone, Serialize, Deserialize)]
155#[serde(untagged)]
156pub enum PingScannerError {
157    Status400(models::Errors),
158    Status401(models::Errors),
159    Status403(models::Errors),
160    Status500(models::Errors),
161    UnknownValue(serde_json::Value),
162}
163
164/// struct for typed errors of method [`set_scanner_as_default`]
165#[derive(Debug, Clone, Serialize, Deserialize)]
166#[serde(untagged)]
167pub enum SetScannerAsDefaultError {
168    Status401(models::Errors),
169    Status403(models::Errors),
170    Status500(models::Errors),
171    UnknownValue(serde_json::Value),
172}
173
174/// struct for typed errors of method [`update_scanner`]
175#[derive(Debug, Clone, Serialize, Deserialize)]
176#[serde(untagged)]
177pub enum UpdateScannerError {
178    Status401(models::Errors),
179    Status403(models::Errors),
180    Status404(models::Errors),
181    Status500(models::Errors),
182    UnknownValue(serde_json::Value),
183}
184
185
186/// Creats a new scanner registration with the given data. 
187pub async fn create_scanner(configuration: &configuration::Configuration, params: CreateScannerParams) -> Result<(), Error<CreateScannerError>> {
188
189    let uri_str = format!("{}/scanners", configuration.base_path);
190    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
191
192    if let Some(ref user_agent) = configuration.user_agent {
193        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
194    }
195    if let Some(param_value) = params.x_request_id {
196        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
197    }
198    if let Some(ref auth_conf) = configuration.basic_auth {
199        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
200    };
201    req_builder = req_builder.json(&params.registration);
202
203    let req = req_builder.build()?;
204    let resp = configuration.client.execute(req).await?;
205
206    let status = resp.status();
207
208    if !status.is_client_error() && !status.is_server_error() {
209        Ok(())
210    } else {
211        let content = resp.text().await?;
212        let entity: Option<CreateScannerError> = serde_json::from_str(&content).ok();
213        Err(Error::ResponseError(ResponseContent { status, content, entity }))
214    }
215}
216
217/// Deletes the specified scanner registration. 
218pub async fn delete_scanner(configuration: &configuration::Configuration, params: DeleteScannerParams) -> Result<models::ScannerRegistration, Error<DeleteScannerError>> {
219
220    let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
221    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
222
223    if let Some(ref user_agent) = configuration.user_agent {
224        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
225    }
226    if let Some(param_value) = params.x_request_id {
227        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
228    }
229    if let Some(ref auth_conf) = configuration.basic_auth {
230        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
231    };
232
233    let req = req_builder.build()?;
234    let resp = configuration.client.execute(req).await?;
235
236    let status = resp.status();
237    let content_type = resp
238        .headers()
239        .get("content-type")
240        .and_then(|v| v.to_str().ok())
241        .unwrap_or("application/octet-stream");
242    let content_type = super::ContentType::from(content_type);
243
244    if !status.is_client_error() && !status.is_server_error() {
245        let content = resp.text().await?;
246        match content_type {
247            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
248            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScannerRegistration`"))),
249            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::ScannerRegistration`")))),
250        }
251    } else {
252        let content = resp.text().await?;
253        let entity: Option<DeleteScannerError> = serde_json::from_str(&content).ok();
254        Err(Error::ResponseError(ResponseContent { status, content, entity }))
255    }
256}
257
258/// Retruns the details of the specified scanner registration. 
259pub async fn get_scanner(configuration: &configuration::Configuration, params: GetScannerParams) -> Result<models::ScannerRegistration, Error<GetScannerError>> {
260
261    let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
262    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
263
264    if let Some(ref user_agent) = configuration.user_agent {
265        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
266    }
267    if let Some(param_value) = params.x_request_id {
268        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
269    }
270    if let Some(ref auth_conf) = configuration.basic_auth {
271        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
272    };
273
274    let req = req_builder.build()?;
275    let resp = configuration.client.execute(req).await?;
276
277    let status = resp.status();
278    let content_type = resp
279        .headers()
280        .get("content-type")
281        .and_then(|v| v.to_str().ok())
282        .unwrap_or("application/octet-stream");
283    let content_type = super::ContentType::from(content_type);
284
285    if !status.is_client_error() && !status.is_server_error() {
286        let content = resp.text().await?;
287        match content_type {
288            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
289            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScannerRegistration`"))),
290            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::ScannerRegistration`")))),
291        }
292    } else {
293        let content = resp.text().await?;
294        let entity: Option<GetScannerError> = serde_json::from_str(&content).ok();
295        Err(Error::ResponseError(ResponseContent { status, content, entity }))
296    }
297}
298
299/// Get the metadata of the specified scanner registration, including the capabilities and customized properties. 
300pub async fn get_scanner_metadata(configuration: &configuration::Configuration, params: GetScannerMetadataParams) -> Result<models::ScannerAdapterMetadata, Error<GetScannerMetadataError>> {
301
302    let uri_str = format!("{}/scanners/{registration_id}/metadata", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
303    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
304
305    if let Some(ref user_agent) = configuration.user_agent {
306        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
307    }
308    if let Some(param_value) = params.x_request_id {
309        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
310    }
311    if let Some(ref auth_conf) = configuration.basic_auth {
312        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
313    };
314
315    let req = req_builder.build()?;
316    let resp = configuration.client.execute(req).await?;
317
318    let status = resp.status();
319    let content_type = resp
320        .headers()
321        .get("content-type")
322        .and_then(|v| v.to_str().ok())
323        .unwrap_or("application/octet-stream");
324    let content_type = super::ContentType::from(content_type);
325
326    if !status.is_client_error() && !status.is_server_error() {
327        let content = resp.text().await?;
328        match content_type {
329            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
330            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScannerAdapterMetadata`"))),
331            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::ScannerAdapterMetadata`")))),
332        }
333    } else {
334        let content = resp.text().await?;
335        let entity: Option<GetScannerMetadataError> = serde_json::from_str(&content).ok();
336        Err(Error::ResponseError(ResponseContent { status, content, entity }))
337    }
338}
339
340/// Returns a list of currently configured scanner registrations. 
341pub async fn list_scanners(configuration: &configuration::Configuration, params: ListScannersParams) -> Result<Vec<models::ScannerRegistration>, Error<ListScannersError>> {
342
343    let uri_str = format!("{}/scanners", configuration.base_path);
344    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
345
346    if let Some(ref param_value) = params.q {
347        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
348    }
349    if let Some(ref param_value) = params.sort {
350        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
351    }
352    if let Some(ref param_value) = params.page {
353        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
354    }
355    if let Some(ref param_value) = params.page_size {
356        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
357    }
358    if let Some(ref user_agent) = configuration.user_agent {
359        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
360    }
361    if let Some(param_value) = params.x_request_id {
362        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
363    }
364    if let Some(ref auth_conf) = configuration.basic_auth {
365        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
366    };
367
368    let req = req_builder.build()?;
369    let resp = configuration.client.execute(req).await?;
370
371    let status = resp.status();
372    let content_type = resp
373        .headers()
374        .get("content-type")
375        .and_then(|v| v.to_str().ok())
376        .unwrap_or("application/octet-stream");
377    let content_type = super::ContentType::from(content_type);
378
379    if !status.is_client_error() && !status.is_server_error() {
380        let content = resp.text().await?;
381        match content_type {
382            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
383            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::ScannerRegistration&gt;`"))),
384            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::ScannerRegistration&gt;`")))),
385        }
386    } else {
387        let content = resp.text().await?;
388        let entity: Option<ListScannersError> = serde_json::from_str(&content).ok();
389        Err(Error::ResponseError(ResponseContent { status, content, entity }))
390    }
391}
392
393/// Pings scanner adapter to test endpoint URL and authorization settings. 
394pub async fn ping_scanner(configuration: &configuration::Configuration, params: PingScannerParams) -> Result<(), Error<PingScannerError>> {
395
396    let uri_str = format!("{}/scanners/ping", configuration.base_path);
397    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
398
399    if let Some(ref user_agent) = configuration.user_agent {
400        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
401    }
402    if let Some(param_value) = params.x_request_id {
403        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
404    }
405    if let Some(ref auth_conf) = configuration.basic_auth {
406        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
407    };
408    req_builder = req_builder.json(&params.settings);
409
410    let req = req_builder.build()?;
411    let resp = configuration.client.execute(req).await?;
412
413    let status = resp.status();
414
415    if !status.is_client_error() && !status.is_server_error() {
416        Ok(())
417    } else {
418        let content = resp.text().await?;
419        let entity: Option<PingScannerError> = serde_json::from_str(&content).ok();
420        Err(Error::ResponseError(ResponseContent { status, content, entity }))
421    }
422}
423
424/// Set the specified scanner registration as the system default one. 
425pub async fn set_scanner_as_default(configuration: &configuration::Configuration, params: SetScannerAsDefaultParams) -> Result<(), Error<SetScannerAsDefaultError>> {
426
427    let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
428    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
429
430    if let Some(ref user_agent) = configuration.user_agent {
431        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
432    }
433    if let Some(param_value) = params.x_request_id {
434        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
435    }
436    if let Some(ref auth_conf) = configuration.basic_auth {
437        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
438    };
439    req_builder = req_builder.json(&params.payload);
440
441    let req = req_builder.build()?;
442    let resp = configuration.client.execute(req).await?;
443
444    let status = resp.status();
445
446    if !status.is_client_error() && !status.is_server_error() {
447        Ok(())
448    } else {
449        let content = resp.text().await?;
450        let entity: Option<SetScannerAsDefaultError> = serde_json::from_str(&content).ok();
451        Err(Error::ResponseError(ResponseContent { status, content, entity }))
452    }
453}
454
455/// Updates the specified scanner registration. 
456pub async fn update_scanner(configuration: &configuration::Configuration, params: UpdateScannerParams) -> Result<(), Error<UpdateScannerError>> {
457
458    let uri_str = format!("{}/scanners/{registration_id}", configuration.base_path, registration_id=crate::apis::urlencode(params.registration_id));
459    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
460
461    if let Some(ref user_agent) = configuration.user_agent {
462        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
463    }
464    if let Some(param_value) = params.x_request_id {
465        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
466    }
467    if let Some(ref auth_conf) = configuration.basic_auth {
468        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
469    };
470    req_builder = req_builder.json(&params.registration);
471
472    let req = req_builder.build()?;
473    let resp = configuration.client.execute(req).await?;
474
475    let status = resp.status();
476
477    if !status.is_client_error() && !status.is_server_error() {
478        Ok(())
479    } else {
480        let content = resp.text().await?;
481        let entity: Option<UpdateScannerError> = serde_json::from_str(&content).ok();
482        Err(Error::ResponseError(ResponseContent { status, content, entity }))
483    }
484}
485