Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

Constellation: serve a did:web service doc! #14

merged opened by bad-example.com targeting main from constellation/did-web

somehow missed this before

Labels

None yet.

Participants 1
AT URI
at://did:plc:hdhoaan3xa3jiuq4fg4mefid/sh.tangled.repo.pull/3me2qastrj422
+39 -8
Diff #0
+7 -1
constellation/src/bin/main.rs
··· 45 45 #[arg(short, long)] 46 46 #[clap(value_enum, default_value_t = StorageBackend::Memory)] 47 47 backend: StorageBackend, 48 + /// Serve a did:web document for this domain 49 + #[arg(long)] 50 + did_web_domain: Option<String>, 48 51 /// Initiate a database backup into this dir, if supported by the storage 49 52 #[arg(long)] 50 53 backup: Option<PathBuf>, ··· 103 106 MemStorage::new(), 104 107 fixture, 105 108 None, 109 + args.did_web_domain, 106 110 stream, 107 111 bind, 108 112 metrics_bind, ··· 138 142 rocks, 139 143 fixture, 140 144 args.data, 145 + args.did_web_domain, 141 146 stream, 142 147 bind, 143 148 metrics_bind, ··· 159 164 mut storage: impl LinkStorage, 160 165 fixture: Option<PathBuf>, 161 166 data_dir: Option<PathBuf>, 167 + did_web_domain: Option<String>, 162 168 stream: String, 163 169 bind: SocketAddr, 164 170 metrics_bind: SocketAddr, ··· 211 217 if collect_metrics { 212 218 install_metrics_server(metrics_bind)?; 213 219 } 214 - serve(readable, bind, staying_alive).await 220 + serve(readable, bind, did_web_domain, staying_alive).await 215 221 }) 216 222 .unwrap(); 217 223 stay_alive.drop_guard();
+32 -7
constellation/src/server/mod.rs
··· 3 3 extract::{Query, Request}, 4 4 http::{self, header}, 5 5 middleware::{self, Next}, 6 - response::{IntoResponse, Response}, 6 + response::{IntoResponse, Json, Response}, 7 7 routing::get, 8 8 Router, 9 9 }; ··· 37 37 http::StatusCode::INTERNAL_SERVER_ERROR 38 38 } 39 39 40 - pub async fn serve<S, A>(store: S, addr: A, stay_alive: CancellationToken) -> anyhow::Result<()> 41 - where 42 - S: LinkReader, 43 - A: ToSocketAddrs, 44 - { 45 - let app = Router::new() 40 + pub async fn serve<S: LinkReader, A: ToSocketAddrs>( 41 + store: S, 42 + addr: A, 43 + did_web_domain: Option<String>, 44 + stay_alive: CancellationToken, 45 + ) -> anyhow::Result<()> { 46 + let mut app = Router::new(); 47 + 48 + if let Some(d) = did_web_domain { 49 + app = app.route( 50 + "/.well-known/did.json", 51 + get({ 52 + let domain = d.clone(); 53 + move || did_web(domain) 54 + }), 55 + ) 56 + } 57 + 58 + let app = app 46 59 .route("/robots.txt", get(robots)) 47 60 .route( 48 61 "/", ··· 204 217 User-agent: * 205 218 Disallow: /links 206 219 Disallow: /links/ 220 + Disallow: /xrpc/ 207 221 " 208 222 } 209 223 224 + async fn did_web(domain: String) -> impl IntoResponse { 225 + Json(serde_json::json!({ 226 + "id": format!("did:web:{domain}"), 227 + "service": [{ 228 + "id": "#constellation", 229 + "type": "ConstellationGraphService", 230 + "serviceEndpoint": format!("https://{domain}") 231 + }] 232 + })) 233 + } 234 + 210 235 #[derive(Template, Serialize, Deserialize)] 211 236 #[template(path = "hello.html.j2")] 212 237 struct HelloReponse {

History

1 round 0 comments
sign up or login to add to the discussion
bad-example.com submitted #0
1 commit
expand
serve a did web!
expand 0 comments
pull request successfully merged