From 8c62727ec92ca55106014cddd040665bbc7f4905 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 15 Jan 2023 22:51:22 +0100 Subject: [PATCH] Add ADMIN_KEY variable to context --- .env.example | 2 ++ src/graphql/context.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/.env.example b/.env.example index 7f3d3fb..c77c829 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ +ADMIN_KEY= + ORDABOK_HOSTS=https://example.com # if empty or unset, CORS will allow all origins # Database diff --git a/src/graphql/context.rs b/src/graphql/context.rs index 4e96fb7..8882a0e 100644 --- a/src/graphql/context.rs +++ b/src/graphql/context.rs @@ -3,11 +3,32 @@ use crate::db::Database; 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)] pub struct Context { pub db: Database, pub appwrite: APVariables, pub user_auth: bool, + pub other_vars: OtherEnvVar } impl Context {