harbor_api/apis/
permissions_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct GetPermissionsParams {
20 pub x_request_id: Option<String>
22}
23
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetPermissionsError {
29 Status401(models::Errors),
30 Status403(models::Errors),
31 Status404(models::Errors),
32 Status500(models::Errors),
33 UnknownValue(serde_json::Value),
34}
35
36
37pub async fn get_permissions(configuration: &configuration::Configuration, params: GetPermissionsParams) -> Result<models::Permissions, Error<GetPermissionsError>> {
39
40 let uri_str = format!("{}/permissions", configuration.base_path);
41 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
42
43 if let Some(ref user_agent) = configuration.user_agent {
44 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
45 }
46 if let Some(param_value) = params.x_request_id {
47 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
48 }
49 if let Some(ref auth_conf) = configuration.basic_auth {
50 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
51 };
52
53 let req = req_builder.build()?;
54 let resp = configuration.client.execute(req).await?;
55
56 let status = resp.status();
57 let content_type = resp
58 .headers()
59 .get("content-type")
60 .and_then(|v| v.to_str().ok())
61 .unwrap_or("application/octet-stream");
62 let content_type = super::ContentType::from(content_type);
63
64 if !status.is_client_error() && !status.is_server_error() {
65 let content = resp.text().await?;
66 match content_type {
67 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
68 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Permissions`"))),
69 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::Permissions`")))),
70 }
71 } else {
72 let content = resp.text().await?;
73 let entity: Option<GetPermissionsError> = serde_json::from_str(&content).ok();
74 Err(Error::ResponseError(ResponseContent { status, content, entity }))
75 }
76}
77