All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rust.hyper.configuration.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>partial_header}}
use hyper;
use hyper_util::client::legacy::Client;
use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::rt::TokioExecutor;

pub struct Configuration
    where C: Clone + std::marker::Send + Sync + 'static {
    pub base_path: String,
    pub user_agent: Option,
    pub client: Client,
    pub basic_auth: Option,
    pub oauth_access_token: Option,
    pub api_key: Option,
    // TODO: take an oauth2 token source, similar to the go one
}

pub type BasicAuth = (String, Option);

pub struct ApiKey {
    pub prefix: Option,
    pub key: String,
}

impl Configuration {
    /// Construct a default [`Configuration`](Self) with a hyper client using a default
    /// [`HttpConnector`](hyper_util::client::legacy::connect::HttpConnector).
    ///
    /// Use [`with_client`](Configuration::with_client) to construct a Configuration with a
    /// custom hyper client.
    ///
    /// # Example
    ///
    /// ```
    /// # use {{externCrateName}}::apis::configuration::Configuration;
    /// let api_config = Configuration {
    ///   basic_auth: Some(("user".into(), None)),
    ///   ..Configuration::new()
    /// };
    /// ```
    pub fn new() -> Configuration {
        Configuration::default()
    }
}

impl Configuration
    where C: Clone + std::marker::Send + Sync {

    /// Construct a new Configuration with a custom hyper client.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::time::Duration;
    /// # use {{externCrateName}}::apis::configuration::Configuration;
    /// use hyper_util::client::legacy::Client;
    /// use hyper_util::rt::TokioExecutor;
    ///
    /// let client = Client::builder(TokioExecutor::new())
    ///   .pool_idle_timeout(Duration::from_secs(30))
    ///   .build_http();
    ///
    /// let api_config = Configuration::with_client(client);
    /// ```
    pub fn with_client(client: Client) -> Configuration {
        Configuration {
            base_path: "{{{basePath}}}".to_owned(),
            user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}Some("OpenAPI-Generator/{{{version}}}/rust".to_owned()){{/httpUserAgent}},
            client,
            basic_auth: None,
            oauth_access_token: None,
            api_key: None,
        }
    }
}

impl Default for Configuration {
    fn default() -> Self {
        let client = Client::builder(TokioExecutor::new()).build_http();
    	Configuration::with_client(client)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy