Properly load env vars
This commit is contained in:
parent
4fc8c7ce98
commit
c05c2ffabf
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
data::FilePath,
|
||||
statics::{GITHUB_AUTH_QUERY, OPT},
|
||||
statics::{load_env_var, GITHUB_AUTH_QUERY, OPT},
|
||||
};
|
||||
use actix_web::{
|
||||
http::{header::LOCATION, StatusCode},
|
||||
@ -109,14 +109,13 @@ pub(crate) struct Github;
|
||||
|
||||
impl Github {
|
||||
pub(crate) fn auth_query() -> Option<String> {
|
||||
use std::env::var;
|
||||
OPT.github_id
|
||||
.clone()
|
||||
.or_else(|| var("GITHUB_CLIENT_ID").ok())
|
||||
.or_else(|| load_env_var("GITHUB_CLIENT_ID"))
|
||||
.and_then(|id| {
|
||||
OPT.github_secret
|
||||
.clone()
|
||||
.or_else(|| var("GITHUB_CLIENT_SECRET").ok())
|
||||
.or_else(|| load_env_var("GITHUB_CLIENT_SECRET"))
|
||||
.map(|secret| format!("?client_id={}&client_secret={}", id, secret))
|
||||
})
|
||||
}
|
||||
|
@ -11,21 +11,27 @@ lazy_static! {
|
||||
pub(crate) static ref CF_ZONE_IDENT: String = OPT
|
||||
.cf_zone
|
||||
.clone()
|
||||
.or_else(|| env::var("CF_ZONE_IDENT").ok())
|
||||
.or_else(|| load_env_var("CF_ZONE_IDENT"))
|
||||
.expect("Cloudflare zone identifier not set");
|
||||
pub(crate) static ref CF_AUTH_KEY: String = OPT
|
||||
.cf_auth_key
|
||||
.clone()
|
||||
.or_else(|| env::var("CF_AUTH_KEY").ok())
|
||||
.or_else(|| load_env_var("CF_AUTH_KEY"))
|
||||
.expect("Cloudflare auth key not set");
|
||||
pub(crate) static ref CF_AUTH_USER: String = OPT
|
||||
.cf_auth_user
|
||||
.clone()
|
||||
.or_else(|| env::var("CF_AUTH_USER").ok())
|
||||
.or_else(|| load_env_var("CF_AUTH_USER"))
|
||||
.expect("Cloudflare auth user not set");
|
||||
pub(crate) static ref HOSTNAME: String = OPT
|
||||
.hostname
|
||||
.clone()
|
||||
.or_else(|| env::var("GITACHE_HOSTNAME").ok())
|
||||
.or_else(|| load_env_var("GITACHE_HOSTNAME"))
|
||||
.unwrap_or_else(|| "gitcdn.tk".to_string());
|
||||
}
|
||||
|
||||
pub(crate) fn load_env_var(key: &str) -> Option<String> {
|
||||
env::var(key)
|
||||
.ok()
|
||||
.and_then(|val| if val.is_empty() { None } else { Some(val) })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user