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 std::{fs, io::Read};
macro_rules! read {
($env:ident, $default:literal) => {
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 s = String::new();
f.read_to_string(&mut s).unwrap();

View File

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

View File

@ -16,6 +16,7 @@ use generator::output_path;
use log::error;
use log::info;
use notify_debouncer_mini::new_debouncer;
use once_cell::sync::Lazy;
use sqlx::{
sqlite::{SqliteConnectOptions, SqlitePoolOptions},
ConnectOptions, SqlitePool,
@ -46,6 +47,10 @@ async fn main() {
let _ = generate().await;
}
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");
info!("Generated");