1 use diesel::{result::Error, *};
2 use lemmy_db_schema::source::secret::Secret;
3 use lemmy_utils::settings::structs::Settings;
6 use crate::get_database_url_from_env;
9 static ref SECRET: RwLock<Secret> = RwLock::new(init().expect("Failed to load secrets from DB."));
12 pub trait SecretSingleton {
16 impl SecretSingleton for Secret {
17 /// Returns the Secret as a struct
19 SECRET.read().expect("read secrets").to_owned()
23 /// Reads the secrets from the DB
24 fn init() -> Result<Secret, Error> {
25 let db_url = match get_database_url_from_env() {
27 Err(_) => Settings::get().get_database_url(),
30 let conn = PgConnection::establish(&db_url).expect("Couldn't get DB connection for Secrets.");
34 fn read_secrets(conn: &PgConnection) -> Result<Secret, Error> {
35 use lemmy_db_schema::schema::secret::dsl::*;
36 secret.first::<Secret>(conn)