fastly_api/apis/
configuration.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10use std::env;
11
12// https://www.fastly.com/documentation/reference/api/#rate-limiting
13pub const DEFAULT_RATELIMIT: u64 = 1000;
14
15#[derive(Debug, Clone)]
16pub struct Configuration {
17    pub base_path: String,
18    pub user_agent: Option<String>,
19    pub client: reqwest::Client,
20    pub basic_auth: Option<BasicAuth>,
21    pub oauth_access_token: Option<String>,
22    pub bearer_access_token: Option<String>,
23    pub api_key: Option<ApiKey>,
24    pub rate_limit_remaining: u64,
25    pub rate_limit_reset: u64,
26    // TODO: take an oauth2 token source, similar to the go one
27}
28
29pub type BasicAuth = (String, Option<String>);
30
31#[derive(Debug, Clone)]
32pub struct ApiKey {
33    pub prefix: Option<String>,
34    pub key: String,
35}
36
37impl Configuration {
38    pub fn new() -> Configuration {
39        Configuration::default()
40    }
41}
42
43impl Default for Configuration {
44    fn default() -> Self {
45        let api_key = match env::var("FASTLY_API_TOKEN") {
46          Ok(key) => key,
47          Err(_) => "".to_string(),
48        };
49
50        Configuration {
51            base_path: "https://api.fastly.com".to_owned(),
52            user_agent: Some("fastly-rust/9.0.0/rust".to_owned()),
53            client: reqwest::Client::new(),
54            basic_auth: None,
55            oauth_access_token: None,
56            bearer_access_token: None,
57            api_key: Some(ApiKey {
58              prefix: None,
59              key: api_key,
60            }),
61            rate_limit_remaining: DEFAULT_RATELIMIT,
62            rate_limit_reset: 0,
63        }
64    }
65}