cloud_hypervisor_client/apis/configuration.rs
1/*
2 * Cloud Hypervisor API
3 *
4 * Local HTTP based API for managing and inspecting a cloud-hypervisor virtual machine.
5 *
6 * The version of the OpenAPI document: 0.3.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use hyper;
12use hyper_util::client::legacy::connect::Connect;
13use hyper_util::client::legacy::connect::HttpConnector;
14use hyper_util::client::legacy::Client;
15use hyper_util::rt::TokioExecutor;
16
17pub struct Configuration<C: Connect = HttpConnector>
18where
19 C: Clone + std::marker::Send + Sync + 'static,
20{
21 pub base_path: String,
22 pub user_agent: Option<String>,
23 pub client: Client<C, String>,
24 pub basic_auth: Option<BasicAuth>,
25 pub oauth_access_token: Option<String>,
26 pub api_key: Option<ApiKey>,
27 // TODO: take an oauth2 token source, similar to the go one
28}
29
30pub type BasicAuth = (String, Option<String>);
31
32pub struct ApiKey {
33 pub prefix: Option<String>,
34 pub key: String,
35}
36
37impl Configuration<HttpConnector> {
38 /// Construct a default [`Configuration`](Self) with a hyper client using a default
39 /// [`HttpConnector`](hyper_util::client::legacy::connect::HttpConnector).
40 ///
41 /// Use [`with_client`](Configuration<T>::with_client) to construct a Configuration with a
42 /// custom hyper client.
43 ///
44 /// # Example
45 ///
46 /// ```
47 /// # use cloud_hypervisor_client::apis::configuration::Configuration;
48 /// let api_config = Configuration {
49 /// basic_auth: Some(("user".into(), None)),
50 /// ..Configuration::new()
51 /// };
52 /// ```
53 pub fn new() -> Configuration<HttpConnector> {
54 Configuration::default()
55 }
56}
57
58impl<C: Connect> Configuration<C>
59where
60 C: Clone + std::marker::Send + Sync,
61{
62 /// Construct a new Configuration with a custom hyper client.
63 ///
64 /// # Example
65 ///
66 /// ```
67 /// # use core::time::Duration;
68 /// # use cloud_hypervisor_client::apis::configuration::Configuration;
69 /// use hyper_util::client::legacy::Client;
70 /// use hyper_util::rt::TokioExecutor;
71 ///
72 /// let client = Client::builder(TokioExecutor::new())
73 /// .pool_idle_timeout(Duration::from_secs(30))
74 /// .build_http();
75 ///
76 /// let api_config = Configuration::with_client(client);
77 /// ```
78 pub fn with_client(client: Client<C, String>) -> Configuration<C> {
79 Configuration {
80 base_path: "http://localhost/api/v1".to_owned(),
81 user_agent: Some("cloud-hypervisor-client/0.3.0".to_owned()),
82 client,
83 basic_auth: None,
84 oauth_access_token: None,
85 api_key: None,
86 }
87 }
88}
89
90impl Default for Configuration<HttpConnector> {
91 fn default() -> Self {
92 let client = Client::builder(TokioExecutor::new()).build_http();
93 Configuration::with_client(client)
94 }
95}