github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/rust/src/apis/external_api.rs (about) 1 /* 2 * lakeFS API 3 * 4 * lakeFS HTTP API 5 * 6 * The version of the OpenAPI document: 1.0.0 7 * Contact: services@treeverse.io 8 * Generated by: https://openapi-generator.tech 9 */ 10 11 12 use reqwest; 13 14 use crate::{apis::ResponseContent, models}; 15 use super::{Error, configuration}; 16 17 18 /// struct for typed errors of method [`create_user_external_principal`] 19 #[derive(Debug, Clone, Serialize, Deserialize)] 20 #[serde(untagged)] 21 pub enum CreateUserExternalPrincipalError { 22 Status401(models::Error), 23 Status404(models::Error), 24 Status409(models::Error), 25 Status420(), 26 DefaultResponse(models::Error), 27 UnknownValue(serde_json::Value), 28 } 29 30 /// struct for typed errors of method [`delete_user_external_principal`] 31 #[derive(Debug, Clone, Serialize, Deserialize)] 32 #[serde(untagged)] 33 pub enum DeleteUserExternalPrincipalError { 34 Status401(models::Error), 35 Status404(models::Error), 36 Status420(), 37 DefaultResponse(models::Error), 38 UnknownValue(serde_json::Value), 39 } 40 41 /// struct for typed errors of method [`external_principal_login`] 42 #[derive(Debug, Clone, Serialize, Deserialize)] 43 #[serde(untagged)] 44 pub enum ExternalPrincipalLoginError { 45 Status400(models::Error), 46 Status401(models::Error), 47 Status403(models::Error), 48 Status404(models::Error), 49 Status420(), 50 DefaultResponse(models::Error), 51 UnknownValue(serde_json::Value), 52 } 53 54 /// struct for typed errors of method [`get_external_principal`] 55 #[derive(Debug, Clone, Serialize, Deserialize)] 56 #[serde(untagged)] 57 pub enum GetExternalPrincipalError { 58 Status401(models::Error), 59 Status404(models::Error), 60 Status420(), 61 DefaultResponse(models::Error), 62 UnknownValue(serde_json::Value), 63 } 64 65 /// struct for typed errors of method [`list_user_external_principals`] 66 #[derive(Debug, Clone, Serialize, Deserialize)] 67 #[serde(untagged)] 68 pub enum ListUserExternalPrincipalsError { 69 Status401(models::Error), 70 Status404(models::Error), 71 Status420(), 72 DefaultResponse(models::Error), 73 UnknownValue(serde_json::Value), 74 } 75 76 77 pub async fn create_user_external_principal(configuration: &configuration::Configuration, user_id: &str, principal_id: &str, external_principal_creation: Option<models::ExternalPrincipalCreation>) -> Result<(), Error<CreateUserExternalPrincipalError>> { 78 let local_var_configuration = configuration; 79 80 let local_var_client = &local_var_configuration.client; 81 82 let local_var_uri_str = format!("{}/auth/users/{userId}/external/principals", local_var_configuration.base_path, userId=crate::apis::urlencode(user_id)); 83 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); 84 85 local_var_req_builder = local_var_req_builder.query(&[("principalId", &principal_id.to_string())]); 86 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 87 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 88 } 89 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 90 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 91 }; 92 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 93 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 94 }; 95 local_var_req_builder = local_var_req_builder.json(&external_principal_creation); 96 97 let local_var_req = local_var_req_builder.build()?; 98 let local_var_resp = local_var_client.execute(local_var_req).await?; 99 100 let local_var_status = local_var_resp.status(); 101 let local_var_content = local_var_resp.text().await?; 102 103 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 104 Ok(()) 105 } else { 106 let local_var_entity: Option<CreateUserExternalPrincipalError> = serde_json::from_str(&local_var_content).ok(); 107 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 108 Err(Error::ResponseError(local_var_error)) 109 } 110 } 111 112 pub async fn delete_user_external_principal(configuration: &configuration::Configuration, user_id: &str, principal_id: &str) -> Result<(), Error<DeleteUserExternalPrincipalError>> { 113 let local_var_configuration = configuration; 114 115 let local_var_client = &local_var_configuration.client; 116 117 let local_var_uri_str = format!("{}/auth/users/{userId}/external/principals", local_var_configuration.base_path, userId=crate::apis::urlencode(user_id)); 118 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); 119 120 local_var_req_builder = local_var_req_builder.query(&[("principalId", &principal_id.to_string())]); 121 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 122 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 123 } 124 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 125 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 126 }; 127 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 128 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 129 }; 130 131 let local_var_req = local_var_req_builder.build()?; 132 let local_var_resp = local_var_client.execute(local_var_req).await?; 133 134 let local_var_status = local_var_resp.status(); 135 let local_var_content = local_var_resp.text().await?; 136 137 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 138 Ok(()) 139 } else { 140 let local_var_entity: Option<DeleteUserExternalPrincipalError> = serde_json::from_str(&local_var_content).ok(); 141 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 142 Err(Error::ResponseError(local_var_error)) 143 } 144 } 145 146 pub async fn external_principal_login(configuration: &configuration::Configuration, external_login_information: Option<models::ExternalLoginInformation>) -> Result<models::AuthenticationToken, Error<ExternalPrincipalLoginError>> { 147 let local_var_configuration = configuration; 148 149 let local_var_client = &local_var_configuration.client; 150 151 let local_var_uri_str = format!("{}/auth/external/principal/login", local_var_configuration.base_path); 152 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); 153 154 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 155 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 156 } 157 local_var_req_builder = local_var_req_builder.json(&external_login_information); 158 159 let local_var_req = local_var_req_builder.build()?; 160 let local_var_resp = local_var_client.execute(local_var_req).await?; 161 162 let local_var_status = local_var_resp.status(); 163 let local_var_content = local_var_resp.text().await?; 164 165 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 166 serde_json::from_str(&local_var_content).map_err(Error::from) 167 } else { 168 let local_var_entity: Option<ExternalPrincipalLoginError> = serde_json::from_str(&local_var_content).ok(); 169 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 170 Err(Error::ResponseError(local_var_error)) 171 } 172 } 173 174 pub async fn get_external_principal(configuration: &configuration::Configuration, principal_id: &str) -> Result<models::ExternalPrincipal, Error<GetExternalPrincipalError>> { 175 let local_var_configuration = configuration; 176 177 let local_var_client = &local_var_configuration.client; 178 179 let local_var_uri_str = format!("{}/auth/external/principals", local_var_configuration.base_path); 180 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); 181 182 local_var_req_builder = local_var_req_builder.query(&[("principalId", &principal_id.to_string())]); 183 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 184 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 185 } 186 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 187 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 188 }; 189 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 190 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 191 }; 192 193 let local_var_req = local_var_req_builder.build()?; 194 let local_var_resp = local_var_client.execute(local_var_req).await?; 195 196 let local_var_status = local_var_resp.status(); 197 let local_var_content = local_var_resp.text().await?; 198 199 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 200 serde_json::from_str(&local_var_content).map_err(Error::from) 201 } else { 202 let local_var_entity: Option<GetExternalPrincipalError> = serde_json::from_str(&local_var_content).ok(); 203 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 204 Err(Error::ResponseError(local_var_error)) 205 } 206 } 207 208 pub async fn list_user_external_principals(configuration: &configuration::Configuration, user_id: &str, prefix: Option<&str>, after: Option<&str>, amount: Option<i32>) -> Result<models::ExternalPrincipalList, Error<ListUserExternalPrincipalsError>> { 209 let local_var_configuration = configuration; 210 211 let local_var_client = &local_var_configuration.client; 212 213 let local_var_uri_str = format!("{}/auth/users/{userId}/external/principals/ls", local_var_configuration.base_path, userId=crate::apis::urlencode(user_id)); 214 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); 215 216 if let Some(ref local_var_str) = prefix { 217 local_var_req_builder = local_var_req_builder.query(&[("prefix", &local_var_str.to_string())]); 218 } 219 if let Some(ref local_var_str) = after { 220 local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]); 221 } 222 if let Some(ref local_var_str) = amount { 223 local_var_req_builder = local_var_req_builder.query(&[("amount", &local_var_str.to_string())]); 224 } 225 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 226 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 227 } 228 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 229 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 230 }; 231 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 232 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 233 }; 234 235 let local_var_req = local_var_req_builder.build()?; 236 let local_var_resp = local_var_client.execute(local_var_req).await?; 237 238 let local_var_status = local_var_resp.status(); 239 let local_var_content = local_var_resp.text().await?; 240 241 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 242 serde_json::from_str(&local_var_content).map_err(Error::from) 243 } else { 244 let local_var_entity: Option<ListUserExternalPrincipalsError> = serde_json::from_str(&local_var_content).ok(); 245 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 246 Err(Error::ResponseError(local_var_error)) 247 } 248 } 249