aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-04 19:22:03 -0700
committerBryan Newbold <bnewbold@robocracy.org>2022-11-04 19:22:03 -0700
commit0aa684b2bd048adbc02cc82cc2f61ff556efda2d (patch)
tree18e8309f28d2e50b3386c5aa9a2e53f24d56b3e4
parent05495ede3e4defac165a1f536dfe6d62fc181557 (diff)
downloadadenosine-0aa684b2bd048adbc02cc82cc2f61ff556efda2d.tar.gz
adenosine-0aa684b2bd048adbc02cc82cc2f61ff556efda2d.zip
pds: fix 'put' (not 'Update')
-rw-r--r--Cargo.lock3
-rw-r--r--adenosine-cli/src/bin/adenosine.rs1
-rw-r--r--adenosine-pds/Cargo.toml1
-rw-r--r--adenosine-pds/src/lib.rs28
4 files changed, 33 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f48b469..4f66206 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -20,10 +20,12 @@ dependencies = [
"atty",
"base64",
"colored_json",
+ "data-encoding",
"dotenv",
"env_logger 0.9.1",
"lazy_static",
"log",
+ "rand 0.7.3",
"regex",
"reqwest",
"serde_json",
@@ -35,6 +37,7 @@ dependencies = [
name = "adenosine-pds"
version = "0.1.0-dev.0"
dependencies = [
+ "adenosine-cli",
"anyhow",
"async-trait",
"bcrypt",
diff --git a/adenosine-cli/src/bin/adenosine.rs b/adenosine-cli/src/bin/adenosine.rs
index f2200ae..827101d 100644
--- a/adenosine-cli/src/bin/adenosine.rs
+++ b/adenosine-cli/src/bin/adenosine.rs
@@ -364,6 +364,7 @@ fn run(opt: Opt) -> Result<()> {
}
Command::Update { uri, fields } => {
params.insert("did".to_string(), uri.repository.to_string());
+ params.insert("user".to_string(), uri.repository.to_string());
params.insert(
"collection".to_string(),
uri.collection.ok_or(anyhow!("collection required"))?,
diff --git a/adenosine-pds/Cargo.toml b/adenosine-pds/Cargo.toml
index 190ba00..e7f92ea 100644
--- a/adenosine-pds/Cargo.toml
+++ b/adenosine-pds/Cargo.toml
@@ -27,6 +27,7 @@ jsonschema = "*"
schemafy = "*"
rouille = "*"
iroh-car = { version = "0.1.0-vendored.0", path = "../iroh-car" }
+adenosine-cli = { version = "0.1.0-dev.0", path = "../adenosine-cli" }
tokio = { version = "1", features = ["full"] }
futures = "0.3"
sha256 = "*"
diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs
index 913b089..a4b6114 100644
--- a/adenosine-pds/src/lib.rs
+++ b/adenosine-pds/src/lib.rs
@@ -438,6 +438,34 @@ fn xrpc_post_handler(
// TODO: next handle updates to database
Ok(json!({}))
}
+ "com.atproto.repoPutRecord" => {
+ // TODO: validate edits against schemas
+ let did = Did::from_str(&xrpc_required_param(request, "did")?)?;
+ let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?;
+ let tid = Tid::from_str(&xrpc_required_param(request, "rkey")?)?;
+ let record: Value = rouille::input::json_input(request)?;
+ let mut srv = srv.lock().unwrap();
+ let _auth_did = &xrpc_check_auth_header(&mut srv, request, Some(&did))?;
+ let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap();
+ let last_commit = srv.repo.get_commit(&commit_cid)?;
+ let mutations: Vec<Mutation> = vec![Mutation::Update(
+ collection,
+ tid,
+ json_value_into_ipld(record),
+ )];
+ let new_mst_cid = srv
+ .repo
+ .update_mst(&last_commit.mst_cid, &mutations)
+ .context("updating MST in repo")?;
+ let new_root_cid = srv.repo.write_root(
+ &last_commit.meta_cid,
+ Some(&last_commit.commit_cid),
+ &new_mst_cid,
+ )?;
+ srv.repo.write_commit(&did, &new_root_cid, "dummy-sig")?;
+ // TODO: next handle updates to database
+ Ok(json!({}))
+ }
"com.atproto.repoDeleteRecord" => {
let did = Did::from_str(&xrpc_required_param(request, "did")?)?;
let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?;