harbor_api/apis/
webhookjob_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 [`list_webhook_jobs`]
18#[derive(Clone, Debug)]
19pub struct ListWebhookJobsParams {
20    /// The name or id of the project
21    pub project_name_or_id: String,
22    /// The policy ID.
23    pub policy_id: i64,
24    /// An unique ID for the request
25    pub x_request_id: Option<String>,
26    /// The flag to indicate whether the parameter which supports both name and id in the path is the name of the resource. When the X-Is-Resource-Name is false and the parameter can be converted to an integer, the parameter will be as an id, otherwise, it will be as a name.
27    pub x_is_resource_name: Option<bool>,
28    /// 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]
29    pub q: Option<String>,
30    /// 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\"
31    pub sort: Option<String>,
32    /// The page number
33    pub page: Option<i64>,
34    /// The size of per page
35    pub page_size: Option<i64>,
36    /// The status of webhook job.
37    pub status: Option<Vec<String>>
38}
39
40
41/// struct for typed errors of method [`list_webhook_jobs`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum ListWebhookJobsError {
45    Status400(models::Errors),
46    Status401(models::Errors),
47    Status403(models::Errors),
48    Status500(models::Errors),
49    UnknownValue(serde_json::Value),
50}
51
52
53/// This endpoint returns webhook jobs of a project. 
54#[deprecated]
55pub async fn list_webhook_jobs(configuration: &configuration::Configuration, params: ListWebhookJobsParams) -> Result<Vec<models::WebhookJob>, Error<ListWebhookJobsError>> {
56
57    let uri_str = format!("{}/projects/{project_name_or_id}/webhook/jobs", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
58    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
59
60    if let Some(ref param_value) = params.q {
61        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
62    }
63    if let Some(ref param_value) = params.sort {
64        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
65    }
66    if let Some(ref param_value) = params.page {
67        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
68    }
69    if let Some(ref param_value) = params.page_size {
70        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
71    }
72    req_builder = req_builder.query(&[("policy_id", &params.policy_id.to_string())]);
73    if let Some(ref param_value) = params.status {
74        req_builder = match "csv" {
75            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
76            _ => req_builder.query(&[("status", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
77        };
78    }
79    if let Some(ref user_agent) = configuration.user_agent {
80        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
81    }
82    if let Some(param_value) = params.x_request_id {
83        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
84    }
85    if let Some(param_value) = params.x_is_resource_name {
86        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
87    }
88    if let Some(ref auth_conf) = configuration.basic_auth {
89        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
90    };
91
92    let req = req_builder.build()?;
93    let resp = configuration.client.execute(req).await?;
94
95    let status = resp.status();
96    let content_type = resp
97        .headers()
98        .get("content-type")
99        .and_then(|v| v.to_str().ok())
100        .unwrap_or("application/octet-stream");
101    let content_type = super::ContentType::from(content_type);
102
103    if !status.is_client_error() && !status.is_server_error() {
104        let content = resp.text().await?;
105        match content_type {
106            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::WebhookJob&gt;`"))),
108            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::WebhookJob&gt;`")))),
109        }
110    } else {
111        let content = resp.text().await?;
112        let entity: Option<ListWebhookJobsError> = serde_json::from_str(&content).ok();
113        Err(Error::ResponseError(ResponseContent { status, content, entity }))
114    }
115}
116