Add ADMIN_KEY variable to context

This commit is contained in:
Lucien Cartier-Tilet 2023-01-15 22:51:22 +01:00
parent e522f358e5
commit 8c62727ec9
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 23 additions and 0 deletions

View File

@ -1,3 +1,5 @@
ADMIN_KEY=
ORDABOK_HOSTS=https://example.com # if empty or unset, CORS will allow all origins ORDABOK_HOSTS=https://example.com # if empty or unset, CORS will allow all origins
# Database # Database

View File

@ -3,11 +3,32 @@ use crate::db::Database;
use tracing::info; use tracing::info;
macro_rules! from_env {
($varname:expr) => {
std::env::var($varname)
.expect(format!("{} must be set!", $varname).as_str())
};
}
#[derive(Debug, Clone)]
pub struct OtherEnvVar {
pub admin_key: String,
}
impl Default for OtherEnvVar {
fn default() -> Self {
Self {
admin_key: from_env!("ADMIN_KEY")
}
}
}
#[derive(Default, Debug, Clone)] #[derive(Default, Debug, Clone)]
pub struct Context { pub struct Context {
pub db: Database, pub db: Database,
pub appwrite: APVariables, pub appwrite: APVariables,
pub user_auth: bool, pub user_auth: bool,
pub other_vars: OtherEnvVar
} }
impl Context { impl Context {