aboutsummaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/src/assetfed.rs4
-rw-r--r--base/src/federation.rs108
-rw-r--r--base/src/lib.rs56
-rw-r--r--base/src/permission.rs3
4 files changed, 72 insertions, 99 deletions
diff --git a/base/src/assetfed.rs b/base/src/assetfed.rs
index 621169f..ea62e0d 100644
--- a/base/src/assetfed.rs
+++ b/base/src/assetfed.rs
@@ -3,7 +3,7 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
-use crate::SECRETS;
+use crate::CONF;
use aes_gcm_siv::{
aead::{generic_array::GenericArray, Aead},
Aes256GcmSiv, KeyInit,
@@ -20,7 +20,7 @@ use std::{path::PathBuf, sync::LazyLock};
const VERSION: u32 = 3;
static ASSET_KEY: LazyLock<Aes256GcmSiv> = LazyLock::new(|| {
- if let Some(sk) = &SECRETS.session_key {
+ if let Some(sk) = &CONF.asset_key {
let r = base64::engine::general_purpose::STANDARD
.decode(sk)
.expect("key invalid; should be valid base64");
diff --git a/base/src/federation.rs b/base/src/federation.rs
index 879ce96..b24d113 100644
--- a/base/src/federation.rs
+++ b/base/src/federation.rs
@@ -3,62 +3,62 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
-use crate::SECRETS;
-use anyhow::anyhow;
-use jellyclient::{Instance, Session};
-use jellycommon::{config::FederationAccount, user::CreateSessionParams};
-use std::{collections::HashMap, sync::Arc};
-use tokio::sync::RwLock;
-pub struct Federation {
- instances: HashMap<String, Instance>,
- sessions: RwLock<HashMap<String, Arc<Session>>>,
-}
+// use anyhow::anyhow;
+// use jellyclient::{Instance, Session};
+// use jellycommon::{config::FederationAccount, user::CreateSessionParams};
+// use std::{collections::HashMap, sync::Arc};
+// use tokio::sync::RwLock;
-impl Federation {
- pub fn initialize() -> Self {
- let instances = SECRETS
- .federation
- .iter()
- .map(|(k, FederationAccount { tls, .. })| {
- (k.to_owned(), Instance::new(k.to_owned(), *tls))
- })
- .collect::<HashMap<_, _>>();
+// pub struct Federation {
+// instances: HashMap<String, Instance>,
+// sessions: RwLock<HashMap<String, Arc<Session>>>,
+// }
- Self {
- instances,
- sessions: Default::default(),
- }
- }
+// impl Federation {
+// pub fn initialize() -> Self {
+// let instances = SECRETS
+// .federation
+// .iter()
+// .map(|(k, FederationAccount { tls, .. })| {
+// (k.to_owned(), Instance::new(k.to_owned(), *tls))
+// })
+// .collect::<HashMap<_, _>>();
- pub fn get_instance(&self, host: &String) -> anyhow::Result<&Instance> {
- self.instances.get(host).ok_or(anyhow!("unknown instance"))
- }
+// Self {
+// instances,
+// sessions: Default::default(),
+// }
+// }
- pub async fn get_session(&self, host: &String) -> anyhow::Result<Arc<Session>> {
- let mut w = self.sessions.write().await;
- if let Some(s) = w.get(host) {
- Ok(s.to_owned())
- } else {
- let FederationAccount {
- username, password, ..
- } = SECRETS
- .federation
- .get(host)
- .ok_or(anyhow!("no credentials of the remote server"))?;
- let s = Arc::new(
- self.get_instance(host)?
- .to_owned()
- .login(CreateSessionParams {
- username: username.to_owned(),
- password: password.to_owned(),
- expire: None,
- drop_permissions: None,
- })
- .await?,
- );
- w.insert(host.to_owned(), s.clone());
- Ok(s)
- }
- }
-}
+// pub fn get_instance(&self, host: &String) -> anyhow::Result<&Instance> {
+// self.instances.get(host).ok_or(anyhow!("unknown instance"))
+// }
+
+// pub async fn get_session(&self, host: &String) -> anyhow::Result<Arc<Session>> {
+// let mut w = self.sessions.write().await;
+// if let Some(s) = w.get(host) {
+// Ok(s.to_owned())
+// } else {
+// let FederationAccount {
+// username, password, ..
+// } = SECRETS
+// .federation
+// .get(host)
+// .ok_or(anyhow!("no credentials of the remote server"))?;
+// let s = Arc::new(
+// self.get_instance(host)?
+// .to_owned()
+// .login(CreateSessionParams {
+// username: username.to_owned(),
+// password: password.to_owned(),
+// expire: None,
+// drop_permissions: None,
+// })
+// .await?,
+// );
+// w.insert(host.to_owned(), s.clone());
+// Ok(s)
+// }
+// }
+// }
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")
+});
diff --git a/base/src/permission.rs b/base/src/permission.rs
index 55d0870..7914f0b 100644
--- a/base/src/permission.rs
+++ b/base/src/permission.rs
@@ -3,7 +3,6 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
-use crate::CONF;
use anyhow::anyhow;
use jellycommon::{
user::{PermissionSet, UserPermission},
@@ -22,7 +21,7 @@ impl PermissionSetExt for PermissionSet {
fn check_explicit(&self, perm: &UserPermission) -> Option<bool> {
self.0
.get(perm)
- .or(CONF.default_permission_set.0.get(perm))
+ // .or(CONF.default_permission_set.0.get(perm))
.copied()
}
fn assert(&self, perm: &UserPermission) -> Result<(), anyhow::Error> {