don't
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(knot): specify knot name as a URL

Signed-off-by: tjh <x@tjh.dev>

tjh 977eab83 27769446

+26 -12
+16 -7
crates/gordian-knot/src/cli/serve.rs
··· 31 31 /// Serve the tangled knot. 32 32 #[derive(Clone, Debug, Args)] 33 33 pub struct Serve { 34 - /// FQDN of the knot. 34 + /// Base URL of the knot. 35 35 #[arg(long, short, value_hint = ValueHint::Hostname, env = "KNOT_NAME")] 36 - #[cfg_attr(debug_assertions, arg(default_value = "localhost:5555"))] 37 - pub name: String, 36 + #[cfg_attr(debug_assertions, arg(default_value = "http://localhost:5555"))] 37 + pub base: Url, 38 38 39 39 /// Handle or DID of the knot owner. 40 40 #[arg(long, short, env = "KNOT_OWNER")] ··· 112 112 impl Serve { 113 113 pub fn to_knot_config(&self) -> Result<KnotConfiguration, Error> { 114 114 let Self { 115 - name, 115 + base, 116 116 owner, 117 117 repos: repo_path, 118 118 hooks: _, ··· 130 130 archive_xz_command: _, 131 131 } = self.clone(); 132 132 133 - // @TODO Validate? 133 + assert!( 134 + ["http", "https"].contains(&base.scheme()), 135 + "knot base url must be \"https\" or \"http\"" 136 + ); 137 + assert!( 138 + base.username().is_empty() && base.password().is_none(), 139 + "knot base url should be contain a username or password" 140 + ); 134 141 135 - let instance = format!("did:web:{name}").parse()?; 142 + let instance = format!("did:web:{}", base.authority()).parse()?; 136 143 137 144 Ok(KnotConfiguration { 138 145 git_config, ··· 152 145 idle: Duration::from_secs(repo_cache_idle), 153 146 live: Duration::from_secs(repo_cache_live), 154 147 }, 155 - ..KnotConfiguration::new(owner, instance, repo_path) 148 + ..KnotConfiguration::new(base, owner, instance, repo_path) 156 149 }) 157 150 } 158 151 ··· 290 283 tracing::info!(?private_addrs, "bound internal API"); 291 284 292 285 let config: KnotConfiguration = arguments.to_knot_config()?; 286 + tracing::info!(?config); 287 + 293 288 let knot_state = KnotState::new(config, resolver, public_http, database, &private_addrs)?; 294 289 let knot = Knot::from(knot_state); 295 290
+2 -1
crates/gordian-knot/src/mock.rs
··· 27 27 28 28 let database = DataStore::new(pool); 29 29 let resolver = Resolver::new(pds.clone()); 30 - let config = KnotConfiguration::new(owner_did.clone(), instance, base.path()); 30 + let base_url = format!("http://{instance_name}").parse().unwrap(); 31 + let config = KnotConfiguration::new(base_url, owner_did.clone(), instance, base.path()); 31 32 let knot = Knot::new(config, resolver, reqwest::Client::new(), database, []).unwrap(); 32 33 33 34 (base, pds, knot)
+8 -4
crates/gordian-knot/src/model/config.rs
··· 6 6 path::{Path, PathBuf}, 7 7 time::Duration, 8 8 }; 9 + use url::Url; 9 10 10 11 pub const DEFAULT_READMES: &[&[u8]] = &[ 11 12 b"README.md", ··· 28 27 29 28 #[derive(Debug)] 30 29 pub struct KnotConfiguration { 30 + pub base: Url, 31 31 pub owner: DidBuf, 32 32 pub instance: DidBuf, 33 33 pub repo_path: PathBuf, ··· 46 44 } 47 45 48 46 impl KnotConfiguration { 49 - pub fn new<P>(owner: DidBuf, instance: DidBuf, base: P) -> Self 47 + pub fn new<P>(base: Url, owner: DidBuf, instance: DidBuf, repos: P) -> Self 50 48 where 51 49 P: AsRef<Path>, 52 50 { 53 51 assert_eq!(instance.method(), "web", "knot instance should be did:web"); 54 52 55 - let base = base.as_ref(); 53 + let repo_path = repos.as_ref().to_path_buf(); 54 + let git_config = repo_path.join("git_config").to_path_buf(); 56 55 Self { 56 + base, 57 57 owner, 58 58 instance, 59 - repo_path: base.to_path_buf(), 60 - git_config: base.join("git_config").to_path_buf(), 59 + repo_path, 60 + git_config, 61 61 readmes: DEFAULT_READMES 62 62 .iter() 63 63 .map(|readme| BString::new(readme.to_vec()))