Fix loading keys from environment var

This commit is contained in:
Shadowfacts 2023-01-03 14:25:26 -05:00
parent bd43ad69d8
commit 151e3860a4
3 changed files with 10 additions and 2 deletions

View File

@ -1,10 +1,13 @@
use log::debug;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::{fs, io::Read}; use std::{fs, io::Read};
macro_rules! read { macro_rules! read {
($env:ident, $default:literal) => { ($env:ident, $default:literal) => {
pub static $env: Lazy<String> = Lazy::new(|| { pub static $env: Lazy<String> = Lazy::new(|| {
let path = option_env!("$env").unwrap_or($default); let env_path = std::env::var(stringify!($env));
let path = env_path.as_deref().unwrap_or($default);
debug!("Reading key from {}", path);
let mut f = fs::File::open(path).unwrap(); let mut f = fs::File::open(path).unwrap();
let mut s = String::new(); let mut s = String::new();
f.read_to_string(&mut s).unwrap(); f.read_to_string(&mut s).unwrap();

View File

@ -5,7 +5,7 @@ mod db;
pub mod digester; pub mod digester;
pub mod federate; pub mod federate;
mod inbox; mod inbox;
mod keys; pub mod keys;
mod types; mod types;
mod util; mod util;
mod webfinger; mod webfinger;

View File

@ -16,6 +16,7 @@ use generator::output_path;
use log::error; use log::error;
use log::info; use log::info;
use notify_debouncer_mini::new_debouncer; use notify_debouncer_mini::new_debouncer;
use once_cell::sync::Lazy;
use sqlx::{ use sqlx::{
sqlite::{SqliteConnectOptions, SqlitePoolOptions}, sqlite::{SqliteConnectOptions, SqlitePoolOptions},
ConnectOptions, SqlitePool, ConnectOptions, SqlitePool,
@ -46,6 +47,10 @@ async fn main() {
let _ = generate().await; let _ = generate().await;
} }
Some(("serve", matches)) => { Some(("serve", matches)) => {
// ensure that the keys are loadable
_ = Lazy::force(&activitypub::keys::PUB_KEY_PEM);
_ = Lazy::force(&activitypub::keys::PRIV_KEY_PEM);
let posts = generate().await.expect("initial generation"); let posts = generate().await.expect("initial generation");
info!("Generated"); info!("Generated");