harbor_api/apis/
ldap_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 [`import_ldap_user`]
18#[derive(Clone, Debug)]
19pub struct ImportLdapUserParams {
20    /// The uid listed for importing. This list will check users validity of ldap service based on configuration from the system.
21    pub uid_list: models::LdapImportUsers,
22    /// An unique ID for the request
23    pub x_request_id: Option<String>
24}
25
26/// struct for passing parameters to the method [`ping_ldap`]
27#[derive(Clone, Debug)]
28pub struct PingLdapParams {
29    /// An unique ID for the request
30    pub x_request_id: Option<String>,
31    /// ldap configuration. support input ldap service configuration. If it is a empty request, will load current configuration from the system.
32    pub ldapconf: Option<models::LdapConf>
33}
34
35/// struct for passing parameters to the method [`search_ldap_group`]
36#[derive(Clone, Debug)]
37pub struct SearchLdapGroupParams {
38    /// An unique ID for the request
39    pub x_request_id: Option<String>,
40    /// Ldap group name
41    pub groupname: Option<String>,
42    /// The LDAP group DN
43    pub groupdn: Option<String>
44}
45
46/// struct for passing parameters to the method [`search_ldap_user`]
47#[derive(Clone, Debug)]
48pub struct SearchLdapUserParams {
49    /// An unique ID for the request
50    pub x_request_id: Option<String>,
51    /// Registered user ID
52    pub username: Option<String>
53}
54
55
56/// struct for typed errors of method [`import_ldap_user`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum ImportLdapUserError {
60    Status400(models::Errors),
61    Status401(models::Errors),
62    Status403(models::Errors),
63    Status404(Vec<models::LdapFailedImportUser>),
64    Status500(models::Errors),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`ping_ldap`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum PingLdapError {
72    Status400(models::Errors),
73    Status401(models::Errors),
74    Status403(models::Errors),
75    Status500(models::Errors),
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`search_ldap_group`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum SearchLdapGroupError {
83    Status400(models::Errors),
84    Status401(models::Errors),
85    Status403(models::Errors),
86    Status500(models::Errors),
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`search_ldap_user`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum SearchLdapUserError {
94    Status400(models::Errors),
95    Status401(models::Errors),
96    Status403(models::Errors),
97    Status500(models::Errors),
98    UnknownValue(serde_json::Value),
99}
100
101
102/// This endpoint adds the selected available ldap users to harbor based on related configuration parameters from the system. System will try to guess the user email address and realname, add to harbor user information. If have errors when import user, will return the list of importing failed uid and the failed reason. 
103pub async fn import_ldap_user(configuration: &configuration::Configuration, params: ImportLdapUserParams) -> Result<(), Error<ImportLdapUserError>> {
104
105    let uri_str = format!("{}/ldap/users/import", configuration.base_path);
106    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
107
108    if let Some(ref user_agent) = configuration.user_agent {
109        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
110    }
111    if let Some(param_value) = params.x_request_id {
112        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
113    }
114    if let Some(ref auth_conf) = configuration.basic_auth {
115        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
116    };
117    req_builder = req_builder.json(&params.uid_list);
118
119    let req = req_builder.build()?;
120    let resp = configuration.client.execute(req).await?;
121
122    let status = resp.status();
123
124    if !status.is_client_error() && !status.is_server_error() {
125        Ok(())
126    } else {
127        let content = resp.text().await?;
128        let entity: Option<ImportLdapUserError> = serde_json::from_str(&content).ok();
129        Err(Error::ResponseError(ResponseContent { status, content, entity }))
130    }
131}
132
133/// This endpoint ping the available ldap service for test related configuration parameters. 
134pub async fn ping_ldap(configuration: &configuration::Configuration, params: PingLdapParams) -> Result<models::LdapPingResult, Error<PingLdapError>> {
135
136    let uri_str = format!("{}/ldap/ping", configuration.base_path);
137    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
138
139    if let Some(ref user_agent) = configuration.user_agent {
140        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
141    }
142    if let Some(param_value) = params.x_request_id {
143        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
144    }
145    if let Some(ref auth_conf) = configuration.basic_auth {
146        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
147    };
148    req_builder = req_builder.json(&params.ldapconf);
149
150    let req = req_builder.build()?;
151    let resp = configuration.client.execute(req).await?;
152
153    let status = resp.status();
154    let content_type = resp
155        .headers()
156        .get("content-type")
157        .and_then(|v| v.to_str().ok())
158        .unwrap_or("application/octet-stream");
159    let content_type = super::ContentType::from(content_type);
160
161    if !status.is_client_error() && !status.is_server_error() {
162        let content = resp.text().await?;
163        match content_type {
164            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
165            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LdapPingResult`"))),
166            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::LdapPingResult`")))),
167        }
168    } else {
169        let content = resp.text().await?;
170        let entity: Option<PingLdapError> = serde_json::from_str(&content).ok();
171        Err(Error::ResponseError(ResponseContent { status, content, entity }))
172    }
173}
174
175/// This endpoint searches the available ldap groups based on related configuration parameters. support to search by groupname or groupdn. 
176pub async fn search_ldap_group(configuration: &configuration::Configuration, params: SearchLdapGroupParams) -> Result<Vec<models::UserGroup>, Error<SearchLdapGroupError>> {
177
178    let uri_str = format!("{}/ldap/groups/search", configuration.base_path);
179    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
180
181    if let Some(ref param_value) = params.groupname {
182        req_builder = req_builder.query(&[("groupname", &param_value.to_string())]);
183    }
184    if let Some(ref param_value) = params.groupdn {
185        req_builder = req_builder.query(&[("groupdn", &param_value.to_string())]);
186    }
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190    if let Some(param_value) = params.x_request_id {
191        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
192    }
193    if let Some(ref auth_conf) = configuration.basic_auth {
194        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
195    };
196
197    let req = req_builder.build()?;
198    let resp = configuration.client.execute(req).await?;
199
200    let status = resp.status();
201    let content_type = resp
202        .headers()
203        .get("content-type")
204        .and_then(|v| v.to_str().ok())
205        .unwrap_or("application/octet-stream");
206    let content_type = super::ContentType::from(content_type);
207
208    if !status.is_client_error() && !status.is_server_error() {
209        let content = resp.text().await?;
210        match content_type {
211            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
212            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::UserGroup&gt;`"))),
213            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::UserGroup&gt;`")))),
214        }
215    } else {
216        let content = resp.text().await?;
217        let entity: Option<SearchLdapGroupError> = serde_json::from_str(&content).ok();
218        Err(Error::ResponseError(ResponseContent { status, content, entity }))
219    }
220}
221
222/// This endpoint searches the available ldap users based on related configuration parameters. Support searched by input ldap configuration, load configuration from the system and specific filter. 
223pub async fn search_ldap_user(configuration: &configuration::Configuration, params: SearchLdapUserParams) -> Result<Vec<models::LdapUser>, Error<SearchLdapUserError>> {
224
225    let uri_str = format!("{}/ldap/users/search", configuration.base_path);
226    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
227
228    if let Some(ref param_value) = params.username {
229        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
230    }
231    if let Some(ref user_agent) = configuration.user_agent {
232        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233    }
234    if let Some(param_value) = params.x_request_id {
235        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
236    }
237    if let Some(ref auth_conf) = configuration.basic_auth {
238        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
239    };
240
241    let req = req_builder.build()?;
242    let resp = configuration.client.execute(req).await?;
243
244    let status = resp.status();
245    let content_type = resp
246        .headers()
247        .get("content-type")
248        .and_then(|v| v.to_str().ok())
249        .unwrap_or("application/octet-stream");
250    let content_type = super::ContentType::from(content_type);
251
252    if !status.is_client_error() && !status.is_server_error() {
253        let content = resp.text().await?;
254        match content_type {
255            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
256            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::LdapUser&gt;`"))),
257            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::LdapUser&gt;`")))),
258        }
259    } else {
260        let content = resp.text().await?;
261        let entity: Option<SearchLdapUserError> = serde_json::from_str(&content).ok();
262        Err(Error::ResponseError(ResponseContent { status, content, entity }))
263    }
264}
265