use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeletePathError {
Status401(models::RespBasic),
Status407(models::RespEndpointArray),
Status500(models::RespBasic),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFilesError {
Status401(models::RespBasic),
Status404(models::RespBasic),
Status407(models::RespEndpointArray),
Status500(models::RespBasic),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MakeDirError {
Status401(models::RespBasic),
Status407(models::RespEndpointArray),
Status409(models::RespBasic),
Status500(models::RespBasic),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RenamePathError {
Status400(models::RespBasic),
Status401(models::RespBasic),
Status404(models::RespBasic),
Status407(models::RespEndpointArray),
Status500(models::RespBasic),
UnknownValue(serde_json::Value),
}
pub async fn delete_path(
configuration: &configuration::Configuration,
client_id: &str,
endpoint_id: &str,
path: &str,
access_token: &str,
refresh_token: &str,
recurse: Option<bool>,
) -> Result<models::RespBasic, Error<DeletePathError>> {
let p_path_client_id = client_id;
let p_path_endpoint_id = endpoint_id;
let p_path_path = path;
let p_query_access_token = access_token;
let p_query_refresh_token = refresh_token;
let p_query_recurse = recurse;
let uri_str = format!(
"{}/v3/globus-proxy/ops/{client_id}/{endpoint_id}/{path}",
configuration.base_path,
client_id = crate::apis::urlencode(p_path_client_id),
endpoint_id = crate::apis::urlencode(p_path_endpoint_id),
path = crate::apis::urlencode(p_path_path)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
req_builder = req_builder.query(&[("access_token", &p_query_access_token.to_string())]);
req_builder = req_builder.query(&[("refresh_token", &p_query_refresh_token.to_string())]);
if let Some(ref param_value) = p_query_recurse {
req_builder = req_builder.query(&[("recurse", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeletePathError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn list_files(
configuration: &configuration::Configuration,
client_id: &str,
endpoint_id: &str,
path: &str,
access_token: &str,
refresh_token: &str,
limit: Option<i32>,
offset: Option<i32>,
filter: Option<&str>,
) -> Result<models::RespFileList, Error<ListFilesError>> {
let p_path_client_id = client_id;
let p_path_endpoint_id = endpoint_id;
let p_path_path = path;
let p_query_access_token = access_token;
let p_query_refresh_token = refresh_token;
let p_query_limit = limit;
let p_query_offset = offset;
let p_query_filter = filter;
let uri_str = format!(
"{}/v3/globus-proxy/ops/{client_id}/{endpoint_id}/{path}",
configuration.base_path,
client_id = crate::apis::urlencode(p_path_client_id),
endpoint_id = crate::apis::urlencode(p_path_endpoint_id),
path = crate::apis::urlencode(p_path_path)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("access_token", &p_query_access_token.to_string())]);
req_builder = req_builder.query(&[("refresh_token", &p_query_refresh_token.to_string())]);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_filter {
req_builder = req_builder.query(&[("filter", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespFileList`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespFileList`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFilesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn make_dir(
configuration: &configuration::Configuration,
client_id: &str,
endpoint_id: &str,
path: &str,
access_token: &str,
refresh_token: &str,
req_make_dir: Option<models::ReqMakeDir>,
) -> Result<models::RespBasic, Error<MakeDirError>> {
let p_path_client_id = client_id;
let p_path_endpoint_id = endpoint_id;
let p_path_path = path;
let p_query_access_token = access_token;
let p_query_refresh_token = refresh_token;
let p_body_req_make_dir = req_make_dir;
let uri_str = format!(
"{}/v3/globus-proxy/ops/{client_id}/{endpoint_id}/{path}",
configuration.base_path,
client_id = crate::apis::urlencode(p_path_client_id),
endpoint_id = crate::apis::urlencode(p_path_endpoint_id),
path = crate::apis::urlencode(p_path_path)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("access_token", &p_query_access_token.to_string())]);
req_builder = req_builder.query(&[("refresh_token", &p_query_refresh_token.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_req_make_dir);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<MakeDirError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn rename_path(
configuration: &configuration::Configuration,
client_id: &str,
endpoint_id: &str,
path: &str,
access_token: &str,
refresh_token: &str,
req_rename: Option<models::ReqRename>,
) -> Result<models::RespBasic, Error<RenamePathError>> {
let p_path_client_id = client_id;
let p_path_endpoint_id = endpoint_id;
let p_path_path = path;
let p_query_access_token = access_token;
let p_query_refresh_token = refresh_token;
let p_body_req_rename = req_rename;
let uri_str = format!(
"{}/v3/globus-proxy/ops/{client_id}/{endpoint_id}/{path}",
configuration.base_path,
client_id = crate::apis::urlencode(p_path_client_id),
endpoint_id = crate::apis::urlencode(p_path_endpoint_id),
path = crate::apis::urlencode(p_path_path)
);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
req_builder = req_builder.query(&[("access_token", &p_query_access_token.to_string())]);
req_builder = req_builder.query(&[("refresh_token", &p_query_refresh_token.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_body_req_rename);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RenamePathError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}