diff --git a/crates/knotty-knot/src/main.rs b/crates/knotty-knot/src/main.rs index 257161f..225d951 100644 --- a/crates/knotty-knot/src/main.rs +++ b/crates/knotty-knot/src/main.rs @@ -4,7 +4,7 @@ mod router; mod state; mod xrpc; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use clap::{Args, Parser, Subcommand}; use jacquard::types::string::Did; @@ -31,10 +31,6 @@ pub struct ServeArgs { #[arg(long, env = "KNOT_LISTEN_ADDR", default_value = "0.0.0.0:5555")] pub listen_addr: String, - /// Public hostname of this knot (used as did:web:) - #[arg(long, env = "KNOT_HOSTNAME")] - pub hostname: String, - /// DID of the server owner #[arg(long, env = "KNOT_OWNER")] pub owner: String, @@ -59,6 +55,8 @@ pub struct GenerateArgs { pub overwrite: bool, } +static KNOT_HOSTNAME: &'static str = env!("KNOT_HOSTNAME"); + #[tokio::main] async fn main() -> miette::Result<()> { tracing_subscriber::fmt::init(); @@ -76,7 +74,7 @@ async fn main() -> miette::Result<()> { Commands::Serve(args) => { let keypair = keypair::Keypair::load(&args.key_path)?; - let did_str = format!("did:web:{}", args.hostname); + let did_str = format!("did:web:{}", KNOT_HOSTNAME); let did = Did::new(&did_str) .into_diagnostic() .wrap_err("building did:web with hostname")?; @@ -85,10 +83,9 @@ async fn main() -> miette::Result<()> { .into_diagnostic() .wrap_err("building owner did")?; - let hostname = args.hostname; + let storage_path = Path::new(&args.repo_path); - let listen_addr = args.listen_addr.clone(); - let state = KnotState::new(&did, &keypair, &owner, &hostname); + let state = KnotState::new(&did, &keypair, &owner, KNOT_HOSTNAME, storage_path); tracing::info!( hostname = %state.hostname, @@ -97,6 +94,7 @@ async fn main() -> miette::Result<()> { "starting knotty-knot", ); + let listen_addr = args.listen_addr; let listener = tokio::net::TcpListener::bind(&listen_addr) .await .into_diagnostic()?; diff --git a/crates/knotty-knot/src/state.rs b/crates/knotty-knot/src/state.rs index bd9bdc4..e150bb5 100644 --- a/crates/knotty-knot/src/state.rs +++ b/crates/knotty-knot/src/state.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use jacquard::identity::JacquardResolver; use jacquard::types::did_doc::{DidDocument, Service, VerificationMethod, default_context}; use jacquard::types::string::Did; @@ -13,10 +15,17 @@ pub struct KnotState { pub did_doc: DidDocument<'static>, pub owner: Did<'static>, pub hostname: &'static str, + pub storage_path: &'static Path, } impl KnotState { - pub fn new(did: &Did<'_>, keypair: &keypair::Keypair, owner: &Did<'_>, hostname: &str) -> Self { + pub fn new( + did: &Did<'_>, + keypair: &keypair::Keypair, + owner: &Did<'_>, + hostname: &str, + storage_path: &Path, + ) -> Self { let service_url = format!("https://{}", did); let did_doc = build_did_doc(&did, &service_url, &keypair.public_key_multibase()); @@ -25,6 +34,7 @@ impl KnotState { owner: owner.clone().into_static(), did_doc, hostname: hostname.to_owned().leak(), + storage_path: Box::leak(Box::new(storage_path.to_path_buf())), } } }