github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/rust/src/apis/commits_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 [`commit`] 19 #[derive(Debug, Clone, Serialize, Deserialize)] 20 #[serde(untagged)] 21 pub enum CommitError { 22 Status400(models::Error), 23 Status401(models::Error), 24 Status403(models::Error), 25 Status404(models::Error), 26 Status409(models::Error), 27 Status412(models::Error), 28 Status420(), 29 DefaultResponse(models::Error), 30 UnknownValue(serde_json::Value), 31 } 32 33 /// struct for typed errors of method [`get_commit`] 34 #[derive(Debug, Clone, Serialize, Deserialize)] 35 #[serde(untagged)] 36 pub enum GetCommitError { 37 Status401(models::Error), 38 Status404(models::Error), 39 Status420(), 40 DefaultResponse(models::Error), 41 UnknownValue(serde_json::Value), 42 } 43 44 45 pub async fn commit(configuration: &configuration::Configuration, repository: &str, branch: &str, commit_creation: models::CommitCreation, source_metarange: Option<&str>) -> Result<models::Commit, Error<CommitError>> { 46 let local_var_configuration = configuration; 47 48 let local_var_client = &local_var_configuration.client; 49 50 let local_var_uri_str = format!("{}/repositories/{repository}/branches/{branch}/commits", local_var_configuration.base_path, repository=crate::apis::urlencode(repository), branch=crate::apis::urlencode(branch)); 51 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); 52 53 if let Some(ref local_var_str) = source_metarange { 54 local_var_req_builder = local_var_req_builder.query(&[("source_metarange", &local_var_str.to_string())]); 55 } 56 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 57 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 58 } 59 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 60 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 61 }; 62 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 63 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 64 }; 65 local_var_req_builder = local_var_req_builder.json(&commit_creation); 66 67 let local_var_req = local_var_req_builder.build()?; 68 let local_var_resp = local_var_client.execute(local_var_req).await?; 69 70 let local_var_status = local_var_resp.status(); 71 let local_var_content = local_var_resp.text().await?; 72 73 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 74 serde_json::from_str(&local_var_content).map_err(Error::from) 75 } else { 76 let local_var_entity: Option<CommitError> = serde_json::from_str(&local_var_content).ok(); 77 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 78 Err(Error::ResponseError(local_var_error)) 79 } 80 } 81 82 pub async fn get_commit(configuration: &configuration::Configuration, repository: &str, commit_id: &str) -> Result<models::Commit, Error<GetCommitError>> { 83 let local_var_configuration = configuration; 84 85 let local_var_client = &local_var_configuration.client; 86 87 let local_var_uri_str = format!("{}/repositories/{repository}/commits/{commitId}", local_var_configuration.base_path, repository=crate::apis::urlencode(repository), commitId=crate::apis::urlencode(commit_id)); 88 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); 89 90 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 91 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 92 } 93 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { 94 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); 95 }; 96 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 97 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 98 }; 99 100 let local_var_req = local_var_req_builder.build()?; 101 let local_var_resp = local_var_client.execute(local_var_req).await?; 102 103 let local_var_status = local_var_resp.status(); 104 let local_var_content = local_var_resp.text().await?; 105 106 if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 107 serde_json::from_str(&local_var_content).map_err(Error::from) 108 } else { 109 let local_var_entity: Option<GetCommitError> = serde_json::from_str(&local_var_content).ok(); 110 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; 111 Err(Error::ResponseError(local_var_error)) 112 } 113 } 114