harbor_api/apis/
member_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_project_member`]
18#[derive(Clone, Debug)]
19pub struct CreateProjectMemberParams {
20    /// The name or id of the project
21    pub project_name_or_id: String,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>,
24    /// 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.
25    pub x_is_resource_name: Option<bool>,
26    pub project_member: Option<models::ProjectMember>
27}
28
29/// struct for passing parameters to the method [`delete_project_member`]
30#[derive(Clone, Debug)]
31pub struct DeleteProjectMemberParams {
32    /// The name or id of the project
33    pub project_name_or_id: String,
34    /// Member ID.
35    pub mid: 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 [`get_project_member`]
43#[derive(Clone, Debug)]
44pub struct GetProjectMemberParams {
45    /// The name or id of the project
46    pub project_name_or_id: String,
47    /// The member ID
48    pub mid: i64,
49    /// An unique ID for the request
50    pub x_request_id: Option<String>,
51    /// 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.
52    pub x_is_resource_name: Option<bool>
53}
54
55/// struct for passing parameters to the method [`list_project_members`]
56#[derive(Clone, Debug)]
57pub struct ListProjectMembersParams {
58    /// The name or id of the project
59    pub project_name_or_id: String,
60    /// An unique ID for the request
61    pub x_request_id: Option<String>,
62    /// 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.
63    pub x_is_resource_name: Option<bool>,
64    /// The page number
65    pub page: Option<i64>,
66    /// The size of per page
67    pub page_size: Option<i64>,
68    /// The entity name to search.
69    pub entityname: Option<String>
70}
71
72/// struct for passing parameters to the method [`update_project_member`]
73#[derive(Clone, Debug)]
74pub struct UpdateProjectMemberParams {
75    /// The name or id of the project
76    pub project_name_or_id: String,
77    /// Member ID.
78    pub mid: i64,
79    /// An unique ID for the request
80    pub x_request_id: Option<String>,
81    /// 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.
82    pub x_is_resource_name: Option<bool>,
83    pub role: Option<models::RoleRequest>
84}
85
86
87/// struct for typed errors of method [`create_project_member`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum CreateProjectMemberError {
91    Status400(models::Errors),
92    Status401(models::Errors),
93    Status403(models::Errors),
94    Status409(models::Errors),
95    Status500(models::Errors),
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`delete_project_member`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum DeleteProjectMemberError {
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 [`get_project_member`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum GetProjectMemberError {
114    Status400(models::Errors),
115    Status401(models::Errors),
116    Status403(models::Errors),
117    Status404(models::Errors),
118    Status500(models::Errors),
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method [`list_project_members`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum ListProjectMembersError {
126    Status400(models::Errors),
127    Status401(models::Errors),
128    Status403(models::Errors),
129    Status404(models::Errors),
130    Status500(models::Errors),
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`update_project_member`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum UpdateProjectMemberError {
138    Status400(models::Errors),
139    Status401(models::Errors),
140    Status403(models::Errors),
141    Status404(models::Errors),
142    Status500(models::Errors),
143    UnknownValue(serde_json::Value),
144}
145
146
147/// Create project member relationship, the member can be one of the user_member and group_member,  The user_member need to specify user_id or username. If the user already exist in harbor DB, specify the user_id,  If does not exist in harbor DB, it will SearchAndOnBoard the user. The group_member need to specify id or ldap_group_dn. If the group already exist in harbor DB. specify the user group's id,  If does not exist, it will SearchAndOnBoard the group. 
148pub async fn create_project_member(configuration: &configuration::Configuration, params: CreateProjectMemberParams) -> Result<(), Error<CreateProjectMemberError>> {
149
150    let uri_str = format!("{}/projects/{project_name_or_id}/members", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
151    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
152
153    if let Some(ref user_agent) = configuration.user_agent {
154        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
155    }
156    if let Some(param_value) = params.x_request_id {
157        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
158    }
159    if let Some(param_value) = params.x_is_resource_name {
160        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
161    }
162    if let Some(ref auth_conf) = configuration.basic_auth {
163        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
164    };
165    req_builder = req_builder.json(&params.project_member);
166
167    let req = req_builder.build()?;
168    let resp = configuration.client.execute(req).await?;
169
170    let status = resp.status();
171
172    if !status.is_client_error() && !status.is_server_error() {
173        Ok(())
174    } else {
175        let content = resp.text().await?;
176        let entity: Option<CreateProjectMemberError> = serde_json::from_str(&content).ok();
177        Err(Error::ResponseError(ResponseContent { status, content, entity }))
178    }
179}
180
181pub async fn delete_project_member(configuration: &configuration::Configuration, params: DeleteProjectMemberParams) -> Result<(), Error<DeleteProjectMemberError>> {
182
183    let uri_str = format!("{}/projects/{project_name_or_id}/members/{mid}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), mid=params.mid);
184    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
185
186    if let Some(ref user_agent) = configuration.user_agent {
187        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188    }
189    if let Some(param_value) = params.x_request_id {
190        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
191    }
192    if let Some(param_value) = params.x_is_resource_name {
193        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
194    }
195    if let Some(ref auth_conf) = configuration.basic_auth {
196        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
197    };
198
199    let req = req_builder.build()?;
200    let resp = configuration.client.execute(req).await?;
201
202    let status = resp.status();
203
204    if !status.is_client_error() && !status.is_server_error() {
205        Ok(())
206    } else {
207        let content = resp.text().await?;
208        let entity: Option<DeleteProjectMemberError> = serde_json::from_str(&content).ok();
209        Err(Error::ResponseError(ResponseContent { status, content, entity }))
210    }
211}
212
213/// Get the project member information
214pub async fn get_project_member(configuration: &configuration::Configuration, params: GetProjectMemberParams) -> Result<models::ProjectMemberEntity, Error<GetProjectMemberError>> {
215
216    let uri_str = format!("{}/projects/{project_name_or_id}/members/{mid}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), mid=params.mid);
217    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
218
219    if let Some(ref user_agent) = configuration.user_agent {
220        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
221    }
222    if let Some(param_value) = params.x_request_id {
223        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
224    }
225    if let Some(param_value) = params.x_is_resource_name {
226        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
227    }
228    if let Some(ref auth_conf) = configuration.basic_auth {
229        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
230    };
231
232    let req = req_builder.build()?;
233    let resp = configuration.client.execute(req).await?;
234
235    let status = resp.status();
236    let content_type = resp
237        .headers()
238        .get("content-type")
239        .and_then(|v| v.to_str().ok())
240        .unwrap_or("application/octet-stream");
241    let content_type = super::ContentType::from(content_type);
242
243    if !status.is_client_error() && !status.is_server_error() {
244        let content = resp.text().await?;
245        match content_type {
246            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
247            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectMemberEntity`"))),
248            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::ProjectMemberEntity`")))),
249        }
250    } else {
251        let content = resp.text().await?;
252        let entity: Option<GetProjectMemberError> = serde_json::from_str(&content).ok();
253        Err(Error::ResponseError(ResponseContent { status, content, entity }))
254    }
255}
256
257/// Get all project member information
258pub async fn list_project_members(configuration: &configuration::Configuration, params: ListProjectMembersParams) -> Result<Vec<models::ProjectMemberEntity>, Error<ListProjectMembersError>> {
259
260    let uri_str = format!("{}/projects/{project_name_or_id}/members", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
261    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263    if let Some(ref param_value) = params.page {
264        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
265    }
266    if let Some(ref param_value) = params.page_size {
267        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
268    }
269    if let Some(ref param_value) = params.entityname {
270        req_builder = req_builder.query(&[("entityname", &param_value.to_string())]);
271    }
272    if let Some(ref user_agent) = configuration.user_agent {
273        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
274    }
275    if let Some(param_value) = params.x_request_id {
276        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
277    }
278    if let Some(param_value) = params.x_is_resource_name {
279        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
280    }
281    if let Some(ref auth_conf) = configuration.basic_auth {
282        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
283    };
284
285    let req = req_builder.build()?;
286    let resp = configuration.client.execute(req).await?;
287
288    let status = resp.status();
289    let content_type = resp
290        .headers()
291        .get("content-type")
292        .and_then(|v| v.to_str().ok())
293        .unwrap_or("application/octet-stream");
294    let content_type = super::ContentType::from(content_type);
295
296    if !status.is_client_error() && !status.is_server_error() {
297        let content = resp.text().await?;
298        match content_type {
299            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
300            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::ProjectMemberEntity&gt;`"))),
301            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::ProjectMemberEntity&gt;`")))),
302        }
303    } else {
304        let content = resp.text().await?;
305        let entity: Option<ListProjectMembersError> = serde_json::from_str(&content).ok();
306        Err(Error::ResponseError(ResponseContent { status, content, entity }))
307    }
308}
309
310/// Update project member relationship
311pub async fn update_project_member(configuration: &configuration::Configuration, params: UpdateProjectMemberParams) -> Result<(), Error<UpdateProjectMemberError>> {
312
313    let uri_str = format!("{}/projects/{project_name_or_id}/members/{mid}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), mid=params.mid);
314    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
315
316    if let Some(ref user_agent) = configuration.user_agent {
317        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
318    }
319    if let Some(param_value) = params.x_request_id {
320        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
321    }
322    if let Some(param_value) = params.x_is_resource_name {
323        req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
324    }
325    if let Some(ref auth_conf) = configuration.basic_auth {
326        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
327    };
328    req_builder = req_builder.json(&params.role);
329
330    let req = req_builder.build()?;
331    let resp = configuration.client.execute(req).await?;
332
333    let status = resp.status();
334
335    if !status.is_client_error() && !status.is_server_error() {
336        Ok(())
337    } else {
338        let content = resp.text().await?;
339        let entity: Option<UpdateProjectMemberError> = serde_json::from_str(&content).ok();
340        Err(Error::ResponseError(ResponseContent { status, content, entity }))
341    }
342}
343