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