diff --git a/bobbin/crates/xrpc/src/lib.rs b/bobbin/crates/xrpc/src/lib.rs index bd60f006..bc6cfd77 100644 --- a/bobbin/crates/xrpc/src/lib.rs +++ b/bobbin/crates/xrpc/src/lib.rs @@ -58,7 +58,7 @@ use bobbin_types::sh_tangled::pipeline::status::{ Status as PipelineStatus, StatusRecord as PipelineStatusRecord, }; use bobbin_types::sh_tangled::pipeline::{Pipeline, PipelineRecord}; -use bobbin_types::sh_tangled::public_key::{PublicKey, PublicKeyRecord}; +use bobbin_types::sh_tangled::public_key::{PublicKey, PublicKeyGetRecordOutput, PublicKeyRecord}; use bobbin_types::sh_tangled::repo::artifact::{Artifact, ArtifactRecord}; use bobbin_types::sh_tangled::repo::collaborator::{Collaborator, CollaboratorRecord}; use bobbin_types::sh_tangled::repo::issue::state::{ @@ -243,6 +243,10 @@ pub fn router(state: AppState) -> Router { "/xrpc/sh.tangled.spindle.countSpindles", get(count_spindles), ) + .route( + "/xrpc/sh.tangled.publicKey.getPublicKey", + get(get_public_key), + ) .route("/xrpc/sh.tangled.publicKey.listKeys", get(list_public_keys)) .route( "/xrpc/sh.tangled.publicKey.countKeys", @@ -615,6 +619,12 @@ struct GetPullQuery { pull: AtUri, } +#[derive(Debug, Deserialize)] +struct GetPublicKeyQuery { + #[serde(rename = "publicKey")] + public_key: AtUri, +} + #[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq)] #[serde(rename_all = "lowercase")] enum Order { @@ -1309,6 +1319,19 @@ async fn get_pull( }))) } +async fn get_public_key( + State(state): State, + XrpcQuery(q): XrpcQuery, +) -> Result>>, XrpcError> { + let (body, value) = + fetch::>(&state, &q.public_key).await?; + Ok(Json(Deduped(PublicKeyGetRecordOutput { + cid: Some(body.cid.clone()), + uri: body.uri.clone(), + value, + }))) +} + async fn get_repos( State(state): State, RawQuery(query): RawQuery, diff --git a/flake.nix b/flake.nix index e918d1fd..03ffa6f3 100644 --- a/flake.nix +++ b/flake.nix @@ -411,6 +411,7 @@ fenix.packages.${system}.stable.rust-src fenix.packages.${system}.stable.clippy fenix.packages.${system}.stable.rustfmt + fenix.packages.${system}.stable.rust-analyzer fenix.packages.${system}.targets.wasm32-unknown-unknown.stable.rust-std ]) pkgs.coreutils # for those of us who are on systems that use busybox (alpine) diff --git a/lexicons/publicKey/getPublicKey.json b/lexicons/publicKey/getPublicKey.json new file mode 100644 index 00000000..872e277f --- /dev/null +++ b/lexicons/publicKey/getPublicKey.json @@ -0,0 +1,41 @@ +{ + "lexicon": 1, + "id": "sh.tangled.publicKey.getPublicKey", + "defs": { + "main": { + "type": "query", + "parameters": { + "type": "params", + "required": ["publicKey"], + "properties": { + "publicKey": { + "type": "string", + "format": "at-uri", + "description": "AT-URI of the sh.tangled.publicKey record to fetch." + } + } + }, + "output": { + "encoding": "application/json", + "schema": { + "type": "object", + "required": ["uri", "value"], + "properties": { + "uri": { + "type": "string", + "format": "at-uri" + }, + "cid": { + "type": "string", + "format": "cid" + }, + "value": { + "type": "unknown", + "description": "Embedded sh.tangled.publicKey record." + } + } + } + } + } + } +}