harbor_api/apis/
immutable_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_immu_rule`]
18#[derive(Clone, Debug)]
19pub struct CreateImmuRuleParams {
20    /// The name or id of the project
21    pub project_name_or_id: String,
22    pub immutable_rule: models::ImmutableRule,
23    /// An unique ID for the request
24    pub x_request_id: Option<String>,
25    /// 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.
26    pub x_is_resource_name: Option<bool>
27}
28
29/// struct for passing parameters to the method [`delete_immu_rule`]
30#[derive(Clone, Debug)]
31pub struct DeleteImmuRuleParams {
32    /// The name or id of the project
33    pub project_name_or_id: String,
34    /// The ID of the immutable rule
35    pub immutable_rule_id: i64,
36    /// An unique ID for the request
37    pub x_request_id: Option<String>,
38    /// 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.
39    pub x_is_resource_name: Option<bool>
40}
41
42/// struct for passing parameters to the method [`list_immu_rules`]
43#[derive(Clone, Debug)]
44pub struct ListImmuRulesParams {
45    /// The name or id of the project
46    pub project_name_or_id: String,
47    /// An unique ID for the request
48    pub x_request_id: Option<String>,
49    /// 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.
50    pub x_is_resource_name: Option<bool>,
51    /// The page number
52    pub page: Option<i64>,
53    /// The size of per page
54    pub page_size: Option<i64>,
55    /// 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]
56    pub q: Option<String>,
57    /// 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\"
58    pub sort: Option<String>
59}
60
61/// struct for passing parameters to the method [`update_immu_rule`]
62#[derive(Clone, Debug)]
63pub struct UpdateImmuRuleParams {
64    /// The name or id of the project
65    pub project_name_or_id: String,
66    /// The ID of the immutable rule
67    pub immutable_rule_id: i64,
68    pub immutable_rule: models::ImmutableRule,
69    /// An unique ID for the request
70    pub x_request_id: Option<String>,
71    /// 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.
72    pub x_is_resource_name: Option<bool>
73}
74
75
76/// struct for typed errors of method [`create_immu_rule`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum CreateImmuRuleError {
80    Status400(models::Errors),
81    Status401(models::Errors),
82    Status403(models::Errors),
83    Status404(models::Errors),
84    Status500(models::Errors),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`delete_immu_rule`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum DeleteImmuRuleError {
92    Status400(models::Errors),
93    Status401(models::Errors),
94    Status403(models::Errors),
95    Status500(models::Errors),
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`list_immu_rules`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum ListImmuRulesError {
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 [`update_immu_rule`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum UpdateImmuRuleError {
114    Status400(models::Errors),
115    Status401(models::Errors),
116    Status403(models::Errors),
117    Status500(models::Errors),
118    UnknownValue(serde_json::Value),
119}
120
121
122/// This endpoint add an immutable tag rule to the project 
123pub async fn create_immu_rule(configuration: &configuration::Configuration, params: CreateImmuRuleParams) -> Result<(), Error<CreateImmuRuleError>> {
124
125    let uri_str = format!("{}/projects/{project_name_or_id}/immutabletagrules", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
126    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
127
128    if let Some(ref user_agent) = configuration.user_agent {
129        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130    }
131    if let Some(param_value) = params.x_request_id {
132        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
133    }
134    if let Some(param_value) = params.x_is_resource_name {
135        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
136    }
137    if let Some(ref auth_conf) = configuration.basic_auth {
138        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
139    };
140    req_builder = req_builder.json(&params.immutable_rule);
141
142    let req = req_builder.build()?;
143    let resp = configuration.client.execute(req).await?;
144
145    let status = resp.status();
146
147    if !status.is_client_error() && !status.is_server_error() {
148        Ok(())
149    } else {
150        let content = resp.text().await?;
151        let entity: Option<CreateImmuRuleError> = serde_json::from_str(&content).ok();
152        Err(Error::ResponseError(ResponseContent { status, content, entity }))
153    }
154}
155
156pub async fn delete_immu_rule(configuration: &configuration::Configuration, params: DeleteImmuRuleParams) -> Result<(), Error<DeleteImmuRuleError>> {
157
158    let uri_str = format!("{}/projects/{project_name_or_id}/immutabletagrules/{immutable_rule_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), immutable_rule_id=params.immutable_rule_id);
159    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
160
161    if let Some(ref user_agent) = configuration.user_agent {
162        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
163    }
164    if let Some(param_value) = params.x_request_id {
165        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
166    }
167    if let Some(param_value) = params.x_is_resource_name {
168        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
169    }
170    if let Some(ref auth_conf) = configuration.basic_auth {
171        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
172    };
173
174    let req = req_builder.build()?;
175    let resp = configuration.client.execute(req).await?;
176
177    let status = resp.status();
178
179    if !status.is_client_error() && !status.is_server_error() {
180        Ok(())
181    } else {
182        let content = resp.text().await?;
183        let entity: Option<DeleteImmuRuleError> = serde_json::from_str(&content).ok();
184        Err(Error::ResponseError(ResponseContent { status, content, entity }))
185    }
186}
187
188/// This endpoint returns the immutable tag rules of a project 
189pub async fn list_immu_rules(configuration: &configuration::Configuration, params: ListImmuRulesParams) -> Result<Vec<models::ImmutableRule>, Error<ListImmuRulesError>> {
190
191    let uri_str = format!("{}/projects/{project_name_or_id}/immutabletagrules", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
192    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
193
194    if let Some(ref param_value) = params.page {
195        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
196    }
197    if let Some(ref param_value) = params.page_size {
198        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
199    }
200    if let Some(ref param_value) = params.q {
201        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
202    }
203    if let Some(ref param_value) = params.sort {
204        req_builder = req_builder.query(&[("sort", &param_value.to_string())]);
205    }
206    if let Some(ref user_agent) = configuration.user_agent {
207        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
208    }
209    if let Some(param_value) = params.x_request_id {
210        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
211    }
212    if let Some(param_value) = params.x_is_resource_name {
213        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
214    }
215    if let Some(ref auth_conf) = configuration.basic_auth {
216        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
217    };
218
219    let req = req_builder.build()?;
220    let resp = configuration.client.execute(req).await?;
221
222    let status = resp.status();
223    let content_type = resp
224        .headers()
225        .get("content-type")
226        .and_then(|v| v.to_str().ok())
227        .unwrap_or("application/octet-stream");
228    let content_type = super::ContentType::from(content_type);
229
230    if !status.is_client_error() && !status.is_server_error() {
231        let content = resp.text().await?;
232        match content_type {
233            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
234            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::ImmutableRule&gt;`"))),
235            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::ImmutableRule&gt;`")))),
236        }
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<ListImmuRulesError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent { status, content, entity }))
241    }
242}
243
244pub async fn update_immu_rule(configuration: &configuration::Configuration, params: UpdateImmuRuleParams) -> Result<(), Error<UpdateImmuRuleError>> {
245
246    let uri_str = format!("{}/projects/{project_name_or_id}/immutabletagrules/{immutable_rule_id}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), immutable_rule_id=params.immutable_rule_id);
247    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
248
249    if let Some(ref user_agent) = configuration.user_agent {
250        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
251    }
252    if let Some(param_value) = params.x_request_id {
253        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
254    }
255    if let Some(param_value) = params.x_is_resource_name {
256        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
257    }
258    if let Some(ref auth_conf) = configuration.basic_auth {
259        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
260    };
261    req_builder = req_builder.json(&params.immutable_rule);
262
263    let req = req_builder.build()?;
264    let resp = configuration.client.execute(req).await?;
265
266    let status = resp.status();
267
268    if !status.is_client_error() && !status.is_server_error() {
269        Ok(())
270    } else {
271        let content = resp.text().await?;
272        let entity: Option<UpdateImmuRuleError> = serde_json::from_str(&content).ok();
273        Err(Error::ResponseError(ResponseContent { status, content, entity }))
274    }
275}
276