tapis-globus-proxy 0.3.1

The Tapis Globus Proxy API proxies calls to Globus coming from a Tapis service.
Documentation
/*
 * Tapis Globus Proxy API
 *
 * The Tapis Globus Proxy API proxies calls to Globus coming from a Tapis service.
 *
 * The version of the OpenAPI document: 1.3.0
 * Contact: cicsupport@tacc.utexas.edu
 * Generated by: https://openapi-generator.tech
 */

use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};

/// struct for typed errors of method [`delete_path`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeletePathError {
    Status401(models::RespBasic),
    Status407(models::RespEndpointArray),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`list_files`]
#[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),
}

/// struct for typed errors of method [`make_dir`]
#[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),
}

/// struct for typed errors of method [`rename_path`]
#[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),
}

/// Delete a file or directory on an endpoint at path {path} relative to the default directory. Access token and refresh token must be provided as a query parameters.
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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    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", &param_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,
        }))
    }
}

/// List files for an endpoint at given path relative to the default directory of the endpoint. Access token and refresh token must be provided as a query parameters.
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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    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", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_offset {
        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_filter {
        req_builder = req_builder.query(&[("filter", &param_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,
        }))
    }
}

/// Create a directory on the endpoint. Path is relative to the endpoint default directory. Access token and refresh token must be provided as a query parameters.
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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    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,
        }))
    }
}

/// Rename a file or directory on the endpoint. Paths are relative to the endpoint default directory. Source and destination paths must be specified in the request body. When renaming to a different parent directory, the parent directory of the new path must already exist. Access token and refresh token must be provided as a query parameters.
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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    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,
        }))
    }
}