aboutsummaryrefslogtreecommitdiff
path: root/base/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/lib.rs')
-rw-r--r--base/src/lib.rs56
1 files changed, 15 insertions, 41 deletions
diff --git a/base/src/lib.rs b/base/src/lib.rs
index 010e908..55a9927 100644
--- a/base/src/lib.rs
+++ b/base/src/lib.rs
@@ -9,47 +9,21 @@ pub mod federation;
pub mod permission;
pub use jellycommon as common;
+use serde::{Deserialize, Serialize};
+use std::sync::LazyLock;
+use std::sync::Mutex;
-use jellycommon::config::{GlobalConfig, SecretsConfig};
-use std::sync::{
- atomic::{AtomicBool, Ordering},
- LazyLock,
-};
-
-pub static CONF: LazyLock<GlobalConfig> = LazyLock::new(load_config);
-pub static SECRETS: LazyLock<SecretsConfig> = LazyLock::new(load_secrets);
-pub static USE_TEST: AtomicBool = AtomicBool::new(false);
-
-pub fn use_test_config() {
- USE_TEST.store(true, Ordering::Relaxed)
+#[rustfmt::skip]
+#[derive(Debug, Deserialize, Serialize, Default)]
+pub struct Config {
+ asset_key: Option<String>,
}
-pub fn load_config() -> GlobalConfig {
- if USE_TEST.load(Ordering::Relaxed) {
- return GlobalConfig::default();
- }
- serde_yaml::from_reader(
- std::fs::File::open(std::env::var("JELLYTHING_CONFIG").unwrap_or_else(|_| {
- if std::env::args()
- .next()
- .unwrap_or_default()
- .ends_with("jellything")
- {
- std::env::args().nth(1).expect(
- "First argument or JELLYTHING_CONFIG must specify the configuration to use.",
- )
- } else {
- panic!("JELLYTHING_CONFIG variable is required.")
- }
- }))
- .expect("config cannot be read"),
- )
- .expect("config invalid")
-}
-fn load_secrets() -> SecretsConfig {
- if USE_TEST.load(Ordering::Relaxed) {
- return SecretsConfig::default();
- }
- serde_yaml::from_reader(std::fs::File::open(&CONF.secrets_path).expect("secrets file missing"))
- .expect("secrets config invalid")
-}
+pub static CONF_PRELOAD: Mutex<Option<Config>> = Mutex::new(None);
+static CONF: LazyLock<Config> = LazyLock::new(|| {
+ CONF_PRELOAD
+ .lock()
+ .unwrap()
+ .take()
+ .expect("cache config not preloaded. logic error")
+});