myc_http_tools/
settings.rs

1use lazy_static::lazy_static;
2use reqwest::Client;
3use std::env::var_os;
4
5// ? ---------------------------------------------------------------------------
6// ? Configure default system constants
7// ? ---------------------------------------------------------------------------
8
9/// Default profile key
10///
11/// This is the default key used to store the profile in the request headers and
12/// send it to the gateway downstream services.
13///
14pub const DEFAULT_PROFILE_KEY: &str = "x-mycelium-profile";
15
16/// Default email key
17///
18/// This is the default key used to store the email in the request headers and
19/// send it to the gateway downstream services.
20///
21pub const DEFAULT_EMAIL_KEY: &str = "x-mycelium-email";
22
23/// Default scope key
24///
25/// The scope key should be used to inject the scope present on the connection
26/// string into the request headers and send it to the gateway downstream
27/// services.
28///
29pub const DEFAULT_SCOPE_KEY: &str = "x-mycelium-scope";
30
31/// Default mycelium role key
32///
33/// This is the default key used to store the mycelium role in the request
34/// headers and send it to the gateway downstream services.
35///
36pub const DEFAULT_MYCELIUM_ROLE_KEY: &str = "x-mycelium-role";
37
38/// Default request id key
39///
40/// This is the default key used to store the request id in the request headers
41/// and send it to the gateway downstream services.
42///
43pub const DEFAULT_REQUEST_ID_KEY: &str = "x-mycelium-request-id";
44
45/// Default connection string key
46///
47/// This is the default key used to store the connection string in the request
48/// headers and send it to the gateway downstream services.
49///
50pub const DEFAULT_CONNECTION_STRING_KEY: &str = "x-mycelium-connection-string";
51
52/// Default tenant id key
53///
54/// This is the default key used to store the tenant id in the request headers
55/// and send it to the gateway downstream services.
56///
57pub const DEFAULT_TENANT_ID_KEY: &str = "x-mycelium-tenant-id";
58
59/// Default forward header key
60///
61/// This is the default key used to store the forward header in the request
62/// headers and send it to the gateway downstream services.
63///
64pub const FORWARD_FOR_KEY: &str = "x-forwarded-for";
65
66/// Default forwarding keys
67///
68/// Such keys are used to map the headers that should be removed from the
69/// downstream response before stream it back to the client.
70///
71pub const FORWARDING_KEYS: [&str; 9] = [
72    "Host",
73    "Connection",
74    "Keep-Alive",
75    "Proxy-Authenticate",
76    "Proxy-Authorization",
77    "Te",
78    "Trailers",
79    "Transfer-Encoding",
80    "Upgrade",
81];
82
83/// Mycelium provider key
84///
85/// This is the key used to indicate that the request is coming from the
86/// internal provider. This key should be used to validate the issuer of the
87/// request.
88///
89pub const MYCELIUM_PROVIDER_KEY: &str = "mycelium";
90
91// ? ---------------------------------------------------------------------------
92// ? Authentication and authorization
93// ? ---------------------------------------------------------------------------
94
95lazy_static! {
96    #[derive(Debug)]
97    pub(super) static ref REQWEST_CLIENT: Client = Client::new();
98}
99
100pub(super) async fn get_client() -> Client {
101    REQWEST_CLIENT.to_owned()
102}
103
104lazy_static! {
105
106    #[derive(Debug)]
107    pub(crate) static ref PROFILE_FETCHING_URL: String =
108        match var_os("PROFILE_FETCHING_URL") {
109            Some(path) => path.into_string().unwrap(),
110            None => panic!("PROFILE_FETCHING_URL not configured."),
111        };
112}