github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/rust/src/apis/import_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 [`import_cancel`] 19 #[derive(Debug, Clone, Serialize, Deserialize)] 20 #[serde(untagged)] 21 pub enum ImportCancelError { 22 Status401(models::Error), 23 Status403(models::Error), 24 Status404(models::Error), 25 Status409(models::Error), 26 Status420(), 27 DefaultResponse(models::Error), 28 UnknownValue(serde_json::Value), 29 } 30 31 /// struct for typed errors of method [`import_start`] 32 #[derive(Debug, Clone, Serialize, Deserialize)] 33 #[serde(untagged)] 34 pub enum ImportStartError { 35 Status400(models::Error), 36 Status401(models::Error), 37 Status403(models::Error), 38 Status404(models::Error), 39 Status420(), 40 DefaultResponse(models::Error), 41 UnknownValue(serde_json::Value), 42 } 43 44 /// struct for typed errors of method [`import_status`] 45 #[derive(Debug, Clone, Serialize, Deserialize)] 46 #[serde(untagged)] 47 pub enum ImportStatusError { 48 Status401(models::Error), 49 Status404(models::Error), 50 Status420(), 51 DefaultResponse(models::Error), 52 UnknownValue(serde_json::Value), 53 } 54 55 56 pub async fn import_cancel(configuration: &configuration::Configuration, repository: &str, branch: &str, id: &str) -> Result<(), Error<ImportCancelError>> { 57 let local_var_configuration = configuration; 58 59 let local_var_client = &local_var_configuration.client; 60 61 let local_var_uri_str = format!("{}/repositories/{repository}/branches/{branch}/import", local_var_configuration.base_path, repository=crate::apis::urlencode(repository), branch=crate::apis::urlencode(branch)); 62 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); 63 64 local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]); 65 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 66 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 67 } 68 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 69 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 70 }; 71 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 72 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 73 }; 74 75 let local_var_req = local_var_req_builder.build()?; 76 let local_var_resp = local_var_client.execute(local_var_req).await?; 77 78 let local_var_status = local_var_resp.status(); 79 let local_var_content = local_var_resp.text().await?; 80 81 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 82 Ok(()) 83 } else { 84 let local_var_entity: Option<ImportCancelError> = serde_json::from_str(&local_var_content).ok(); 85 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 86 Err(Error::ResponseError(local_var_error)) 87 } 88 } 89 90 pub async fn import_start(configuration: &configuration::Configuration, repository: &str, branch: &str, import_creation: models::ImportCreation) -> Result<models::ImportCreationResponse, Error<ImportStartError>> { 91 let local_var_configuration = configuration; 92 93 let local_var_client = &local_var_configuration.client; 94 95 let local_var_uri_str = format!("{}/repositories/{repository}/branches/{branch}/import", local_var_configuration.base_path, repository=crate::apis::urlencode(repository), branch=crate::apis::urlencode(branch)); 96 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); 97 98 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 99 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 100 } 101 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 102 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 103 }; 104 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 105 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 106 }; 107 local_var_req_builder = local_var_req_builder.json(&import_creation); 108 109 let local_var_req = local_var_req_builder.build()?; 110 let local_var_resp = local_var_client.execute(local_var_req).await?; 111 112 let local_var_status = local_var_resp.status(); 113 let local_var_content = local_var_resp.text().await?; 114 115 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 116 serde_json::from_str(&local_var_content).map_err(Error::from) 117 } else { 118 let local_var_entity: Option<ImportStartError> = serde_json::from_str(&local_var_content).ok(); 119 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 120 Err(Error::ResponseError(local_var_error)) 121 } 122 } 123 124 pub async fn import_status(configuration: &configuration::Configuration, repository: &str, branch: &str, id: &str) -> Result<models::ImportStatus, Error<ImportStatusError>> { 125 let local_var_configuration = configuration; 126 127 let local_var_client = &local_var_configuration.client; 128 129 let local_var_uri_str = format!("{}/repositories/{repository}/branches/{branch}/import", local_var_configuration.base_path, repository=crate::apis::urlencode(repository), branch=crate::apis::urlencode(branch)); 130 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); 131 132 local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]); 133 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 134 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 135 } 136 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 137 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 138 }; 139 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 140 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 141 }; 142 143 let local_var_req = local_var_req_builder.build()?; 144 let local_var_resp = local_var_client.execute(local_var_req).await?; 145 146 let local_var_status = local_var_resp.status(); 147 let local_var_content = local_var_resp.text().await?; 148 149 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 150 serde_json::from_str(&local_var_content).map_err(Error::from) 151 } else { 152 let local_var_entity: Option<ImportStatusError> = serde_json::from_str(&local_var_content).ok(); 153 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 154 Err(Error::ResponseError(local_var_error)) 155 } 156 } 157