tapis-files 0.3.0

The Tapis Files API provides for management of file resources on Tapis systems
Documentation
/*
 * Tapis Files API
 *
 * The Tapis Files API provides for management of file resources on Tapis systems
 *
 * The version of the OpenAPI document: 1.8.2
 * 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 [`get_contents`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetContentsError {
    Status400(),
    Status401(),
    Status404(),
    Status403(),
    UnknownValue(serde_json::Value),
}

/// Get file or directory contents as a stream of data.  Certain services may use the query parameter *impersonationId* to be used in place of the requesting Tapis user. Tapis will use this user Id when performing authorization and resolving the *effectiveUserId* for the system.  Use the query parameter *zip* to request a stream compressed using the ZIP file format. This is not allowed if system *rootDir* plus *path* would result in all files on the host being included. Please download individual directories, files or objects.  Certain services may use the query parameter *sharedCtx* to indicate that the request is in a shared context. *sharedCtx* must be set to the share grantor. Tapis will include the share grantor as part of authorization checks.
pub async fn get_contents(
    configuration: &configuration::Configuration,
    system_id: &str,
    path: &str,
    range: Option<models::HeaderByteRange>,
    zip: Option<bool>,
    more: Option<i64>,
    impersonation_id: Option<&str>,
    shared_ctx: Option<&str>,
) -> Result<(), Error<GetContentsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_system_id = system_id;
    let p_path_path = path;
    let p_header_range = range;
    let p_query_zip = zip;
    let p_header_more = more;
    let p_query_impersonation_id = impersonation_id;
    let p_query_shared_ctx = shared_ctx;

    let uri_str = format!(
        "{}/v3/files/content/{systemId}/{path}",
        configuration.base_path,
        systemId = crate::apis::urlencode(p_path_system_id),
        path = crate::apis::urlencode(p_path_path)
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_zip {
        req_builder = req_builder.query(&[("zip", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_impersonation_id {
        req_builder = req_builder.query(&[("impersonationId", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_shared_ctx {
        req_builder = req_builder.query(&[("sharedCtx", &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());
    }
    if let Some(param_value) = p_header_range {
        req_builder = req_builder.header("range", param_value.to_string());
    }
    if let Some(param_value) = p_header_more {
        req_builder = req_builder.header("more", param_value.to_string());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<GetContentsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}