chadtmiller.com/group-host
atmosphere group host
0
0
opensocial import moves an account and its spaces here
crates/group-host/src/import.rs+11−1
| @@ -364,7 +364,7 @@ pub async fn check_import( | ||
Query(p): Query<Params>, | ||
headers: HeaderMap, | ||
) -> Answer { | ||
signed_in(&host, &headers, &format!("{NS}.checkImport")).await?; | ||
let me = signed_in(&host, &headers, &format!("{NS}.checkImport")).await?; | ||
let did = param(&p, "did")?; | ||
let plan = host | ||
.plan_import(did, p.get("address").map(String::as_str)) | ||
| @@ -375,7 +375,17 @@ pub async fn check_import( | ||
"address": plan.address, | ||
"label": plan.label, | ||
"keeps": plan.keeps, | ||
"pds": plan.pds, | ||
}); | ||
// What its operation should name, again, for whoever is moving it. | ||
let pending = host | ||
.store | ||
.pending_import(did) | ||
.map_err(XrpcError::internal)?; | ||
if pending.is_some_and(|p| p.founder == me) { | ||
let account = host.store.account(did).map_err(XrpcError::internal)?; | ||
out["recommendedCreds"] = creds(&host, &account.expect("a move's account")); | ||
} | ||
if let Some(from) = &plan.from { | ||
out["from"] = json!(from); | ||
} | ||
crates/group-host/tests/common/net.rs+2−0
| @@ -14,6 +14,8 @@ pub struct Net { | ||
pub plc: String, | ||
/// Whether the PDS is on the space alpha. | ||
pub spaces: bool, | ||
/// Where the codes the PDS mails are read: `GET <mail>?to=<address>`. | ||
pub mail: String, | ||
pub accounts: Vec<Member>, | ||
} | ||
| ||
crates/group-host/tests/import.rs+16−1
| @@ -831,6 +831,8 @@ async fn checks_what_a_move_would_make_of_it_before_anything_moves() { | ||
assert_eq!(said["keeps"], false); | ||
assert_eq!(said["from"], "harbor.old.test"); | ||
assert!(said.get("refused").is_none()); | ||
assert_eq!(said["pds"], w.url.as_str()); | ||
assert!(said.get("recommendedCreds").is_none()); | ||
assert!(w.h.host.store.account(&w.did).unwrap().is_none()); | ||
let (_, said) = w.check(&format!("did={}&address=Riders", w.did)).await; | ||
assert_eq!(said["address"], "riders.groups.test"); | ||
| @@ -840,9 +842,22 @@ async fn checks_what_a_move_would_make_of_it_before_anything_moves() { | ||
let said = w.start(&w.people[0], json!({"address": "-"})).await; | ||
assert_eq!(error(&said), (400, "InvalidHandle")); | ||
// An earlier move of the same account holds nothing that counts. | ||
assert_eq!(w.start(&w.people[0], json!({})).await.0, 200); | ||
let (status, started) = w.start(&w.people[0], json!({})).await; | ||
assert_eq!(status, 200, "{started}"); | ||
let (_, said) = w.check(&format!("did={}", w.did)).await; | ||
assert!(said.get("refused").is_none(), "{said}"); | ||
// Whoever is moving it is told again what its operation should name; | ||
// nobody else is. | ||
assert_eq!(said["recommendedCreds"], started["recommendedCreds"]); | ||
let other = &w.people[1]; | ||
let (_, said) = get( | ||
&w.h, | ||
CHECK, | ||
&format!("did={}", w.did), | ||
&[auth(&w.h, other, CHECK)], | ||
) | ||
.await; | ||
assert!(said.get("recommendedCreds").is_none(), "{said}"); | ||
// One known by no handle takes the address asked for, and only that. | ||
let rotation = Keypair::generate(Curve::K256); | ||
let mut op = Op::atproto( | ||
crates/opensocial/src/lib.rs+230−1
| @@ -24,12 +24,19 @@ pub const USAGE: &str = "usage: opensocial <command> | ||
invite someone in | ||
migrate <group> --to <address> [--to-did <did>] | ||
move a group, whole, from this host to the one at <address> | ||
import <account> [--address <label>] | ||
move an account from its server here, its spaces with it, to | ||
become a group run by you; its server emails a code | ||
import <account> --code <code> | ||
with that code, finish moving it | ||
seed <handle> a group to try things on: two rules, a moderator role, and an | ||
invite for each handle in OPENSOCIAL_SEED_INVITE | ||
| ||
A group or person is a handle or a DID. You sign in as OPENSOCIAL_AS (a | ||
handle) with OPENSOCIAL_PASSWORD, at PDS_URL; the host is OPENSOCIAL_HOST, | ||
its DID OPENSOCIAL_HOST_DID (by default the did:web of its address). | ||
its DID OPENSOCIAL_HOST_DID (by default the did:web of its address). An | ||
account you import signs in at its own server with OPENSOCIAL_IMPORT_PASSWORD, | ||
its own password: its server hands its identity over for no app password. | ||
"; | ||
| ||
/// Where the command acts, and as whom: from the environment. | ||
| @@ -47,6 +54,9 @@ pub struct Env { | ||
pub password: Option<String>, | ||
/// Who `seed` invites, `OPENSOCIAL_SEED_INVITE`, comma-separated. | ||
pub seed_invite: Vec<String>, | ||
/// The password of an account `import` moves, at its own server, | ||
/// `OPENSOCIAL_IMPORT_PASSWORD`. | ||
pub import_password: Option<String>, | ||
} | ||
| ||
/// The did:web a host at `url` is by default, as the host names itself. | ||
| @@ -72,6 +82,7 @@ impl Env { | ||
pds: pds.trim_end_matches('/').to_string(), | ||
handle: var("OPENSOCIAL_AS"), | ||
password: var("OPENSOCIAL_PASSWORD"), | ||
import_password: var("OPENSOCIAL_IMPORT_PASSWORD"), | ||
seed_invite: invite | ||
.split(',') | ||
.map(str::trim) | ||
| @@ -161,6 +172,66 @@ impl Client { | ||
answer(res, lxm).await | ||
} | ||
| ||
/// `nsid` of the person's own PDS, as them: a query with `params`, or | ||
/// with `body`, a procedure (one that takes none with a null body). | ||
async fn own( | ||
&self, | ||
nsid: &str, | ||
params: &[(&str, &str)], | ||
body: Option<&Value>, | ||
) -> Result<Value> { | ||
let url = format!("{}/xrpc/{nsid}", self.pds); | ||
let asked = match body { | ||
Some(Value::Null) => self.http.post(url), | ||
Some(body) => self.http.post(url).json(body), | ||
None => self.http.get(url), | ||
}; | ||
let sent = asked.query(params).bearer_auth(&self.access).send().await; | ||
let res = sent.context(format!("reaching {}", self.pds))?; | ||
answer(res, nsid).await | ||
} | ||
| ||
/// The bytes `nsid` of the person's own PDS answers with `params`, and | ||
/// their type; none where it holds no repo of theirs. | ||
async fn own_bytes( | ||
&self, | ||
nsid: &str, | ||
params: &[(&str, &str)], | ||
) -> Result<Option<(Vec<u8>, String)>> { | ||
let url = format!("{}/xrpc/{nsid}", self.pds); | ||
let asked = self.http.get(url).query(params).bearer_auth(&self.access); | ||
let res = asked.send().await; | ||
let res = res.context(format!("reaching {}", self.pds))?; | ||
let kind = res | ||
.headers() | ||
.get("content-type") | ||
.and_then(|v| v.to_str().ok()); | ||
let kind = kind.unwrap_or("application/octet-stream").to_string(); | ||
if !res.status().is_success() { | ||
let said = answer(res, nsid).await.expect_err("a refusal"); | ||
let none = format!("{said}").contains("RepoNotFound"); | ||
return none.then_some(None).ok_or(said); | ||
} | ||
Ok(Some((res.bytes().await?.to_vec(), kind))) | ||
} | ||
| ||
/// `host`'s procedure `lxm` with `params`, taking `bytes` of `kind`. | ||
async fn send( | ||
&self, | ||
host: &Host, | ||
lxm: &str, | ||
params: &[(&str, &str)], | ||
bytes: Vec<u8>, | ||
kind: &str, | ||
) -> Result<Value> { | ||
let token = self.token(&host.did, lxm).await?; | ||
let url = format!("{}/xrpc/{lxm}", host.url); | ||
let asked = self.http.post(url).bearer_auth(token).query(params); | ||
let sent = asked.header("content-type", kind).body(bytes).send().await; | ||
let res = sent.context(format!("reaching {}", host.url))?; | ||
answer(res, lxm).await | ||
} | ||
| ||
/// The DID `who` names, a handle or a DID, as `host` resolves it. | ||
pub async fn resolve(&self, host: &Host, who: &str) -> Result<String> { | ||
if who.starts_with("did:") { | ||
| @@ -256,6 +327,11 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> { | ||
}; | ||
migrate(&signed_in(env).await?, &host, &dest, group).await | ||
} | ||
"import" => { | ||
let a = parse(rest, &["address", "code"])?; | ||
let [account] = a.take()?; | ||
import(&signed_in(env).await?, &host, env, account, &a).await | ||
} | ||
"seed" => { | ||
let [handle] = parse(rest, &[])?.take()?; | ||
seed(&signed_in(env).await?, &host, handle, &env.seed_invite).await | ||
| @@ -414,6 +490,159 @@ async fn migrate(me: &Client, from: &Host, to: &Host, group: &str) -> Result<Str | ||
Ok(out) | ||
} | ||
| ||
/// The cursor a listing's next page starts after, if it has one. | ||
fn next(listed: &Value) -> Option<String> { | ||
let cursor = text(&listed["cursor"]); | ||
(!cursor.is_empty()).then_some(cursor.to_string()) | ||
} | ||
| ||
/// Moves `account` here to become a group run by `me`, in two runs: one | ||
/// copies it and its spaces and has its server email a code, and one, with | ||
/// that code, has its server sign its identity over and finishes. | ||
async fn import( | ||
me: &Client, | ||
host: &Host, | ||
env: &Env, | ||
account: &str, | ||
a: &Args<'_>, | ||
) -> Result<String> { | ||
let did = me.resolve(host, account).await?; | ||
let mut asked = vec![("did", did.as_str())]; | ||
asked.extend(a.flags.get("address").map(|l| ("address", *l))); | ||
let plan = me.query(host, &m("checkImport"), &asked).await?; | ||
if let Some(no) = plan.get("refused") { | ||
bail!("{} can't move here: {}", account, text(&no["message"])); | ||
} | ||
let Some(password) = &env.import_password else { | ||
bail!("set OPENSOCIAL_IMPORT_PASSWORD to {account}'s own password at its server"); | ||
}; | ||
let theirs = Client::sign_in(text(&plan["pds"]), account, password).await?; | ||
match a.flags.get("code") { | ||
None => start_import(me, &theirs, host, &plan, account, a.flags.get("address")).await, | ||
Some(code) => finish_import(me, &theirs, host, &plan, code).await, | ||
} | ||
} | ||
| ||
async fn start_import( | ||
me: &Client, | ||
theirs: &Client, | ||
host: &Host, | ||
plan: &Value, | ||
account: &str, | ||
address: Option<&&str>, | ||
) -> Result<String> { | ||
let did = theirs.did.as_str(); | ||
let proof = theirs | ||
.token(&host.did, "com.atproto.server.createAccount") | ||
.await?; | ||
let mut body = json!({ "serviceJwt": proof }); | ||
if let Some(label) = address { | ||
body["address"] = json!(label); | ||
} | ||
let copied = me.call(host, &m("importAccount"), &body).await?; | ||
let mut out = format!( | ||
"moving {did} | ||
from {} | ||
as {} | ||
", | ||
text(&plan["pds"]), | ||
text(&copied["handle"]) | ||
); | ||
out += &format!( | ||
"copied {} records, {} files | ||
", | ||
copied["records"], copied["blobs"] | ||
); | ||
// Each space it governs or wrote in: a space it governs first, then its | ||
// files there, then its repo, which holds them. | ||
let mut spaces = Vec::new(); | ||
let mut cursor = Some(String::new()); | ||
while let Some(after) = cursor.take() { | ||
let mut page = vec![("limit", "100")]; | ||
page.extend((!after.is_empty()).then_some(("cursor", after.as_str()))); | ||
let listed = theirs | ||
.own("com.atproto.space.listSpaces", &page, None) | ||
.await?; | ||
let uris = listed["spaces"].as_array().into_iter().flatten(); | ||
spaces.extend(uris.map(|s| text(&s["uri"]).to_string())); | ||
cursor = next(&listed); | ||
} | ||
let (mut files, mut records) = (0, 0); | ||
let bring = &m("importAccountSpace"); | ||
for space in &spaces { | ||
let at = [("space", space.as_str()), ("repo", did)]; | ||
let governs = space.starts_with(&format!("at://{did}/")); | ||
if governs { | ||
let meta = theirs | ||
.own_bytes("com.atproto.space.exportSpaceMeta", &at[..1]) | ||
.await?; | ||
let (meta, kind) = meta.context(format!("{space} exported nothing"))?; | ||
me.send(host, bring, &[("did", did), ("part", "meta")], meta, &kind) | ||
.await?; | ||
} | ||
let mut cursor = Some(String::new()); | ||
while let Some(after) = cursor.take() { | ||
let mut page = at.to_vec(); | ||
page.extend((!after.is_empty()).then_some(("cursor", after.as_str()))); | ||
let listed = theirs | ||
.own("com.atproto.space.listBlobs", &page, None) | ||
.await?; | ||
for cid in listed["cids"].as_array().into_iter().flatten() { | ||
let at = [at[0], at[1], ("cid", text(cid))]; | ||
let blob = theirs.own_bytes("com.atproto.space.getBlob", &at).await?; | ||
let (bytes, kind) = blob.context(format!("{space} has no file {}", text(cid)))?; | ||
me.send(host, bring, &[("did", did), ("part", "blob")], bytes, &kind) | ||
.await?; | ||
files += 1; | ||
} | ||
cursor = next(&listed); | ||
} | ||
if let Some((repo, kind)) = theirs.own_bytes("com.atproto.space.getRepo", &at).await? { | ||
let kept = me | ||
.send(host, bring, &[("did", did), ("part", "repo")], repo, &kind) | ||
.await?; | ||
records += kept["records"].as_u64().unwrap_or_default(); | ||
} | ||
} | ||
out += &format!( | ||
"brought {} spaces: {records} records, {files} files | ||
", | ||
spaces.len() | ||
); | ||
let ask = "com.atproto.identity.requestPlcOperationSignature"; | ||
theirs.own(ask, &[], Some(&Value::Null)).await?; | ||
out += &format!( | ||
"its server has emailed a code to move its identity; finish with | ||
opensocial import {account} --code <code> | ||
" | ||
); | ||
Ok(out) | ||
} | ||
| ||
async fn finish_import( | ||
me: &Client, | ||
theirs: &Client, | ||
host: &Host, | ||
plan: &Value, | ||
code: &str, | ||
) -> Result<String> { | ||
let did = theirs.did.as_str(); | ||
let Some(Value::Object(creds)) = plan.get("recommendedCreds") else { | ||
bail!("no move of {did} of yours is under way here: start it without --code"); | ||
}; | ||
let mut asked = creds.clone(); | ||
asked.insert("token".into(), json!(code.trim())); | ||
let sign = "com.atproto.identity.signPlcOperation"; | ||
let signed = theirs.own(sign, &[], Some(&Value::Object(asked))).await?; | ||
let body = json!({ "did": did, "operation": signed["operation"] }); | ||
let done = me.call(host, &m("completeImport"), &body).await?; | ||
Ok(format!( | ||
"moved: {} is a group here, run by you | ||
", | ||
text(&done["handle"]) | ||
)) | ||
} | ||
| ||
/// The rules a seeded group starts with. | ||
const RULES: [(&str, &str); 2] = [ | ||
("Be kind", "Disagree with ideas, not people."), | ||
crates/opensocial/tests/commands.rs+149−0
| @@ -9,6 +9,7 @@ use group_host::Host; | ||
use group_host::config::Config; | ||
use net::net; | ||
use opensocial::{Env, did_web, run}; | ||
use serde_json::{Value, json}; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
use tempfile::TempDir; | ||
| @@ -209,6 +210,154 @@ async fn moves_a_group_to_another_host() { | ||
assert!(said.contains("fyi.opensocial.migratePrepare"), "{said}"); | ||
} | ||
| ||
/// `nsid` of the reference PDS, as `bearer`: a query with `query`, or a | ||
/// procedure with `body`; `bytes` of `kind` for one that takes them. | ||
async fn pds(nsid: &str, bearer: &str, body: Option<Value>, bytes: Option<(&[u8], &str)>) -> Value { | ||
let url = format!("{}/xrpc/{nsid}", net().pds); | ||
let http = reqwest::Client::new(); | ||
let req = match (body, bytes) { | ||
(_, Some((b, kind))) => http.post(url).header("content-type", kind).body(b.to_vec()), | ||
(Some(body), None) => http.post(url).json(&body), | ||
(None, None) => http.get(url), | ||
}; | ||
let req = if bearer.is_empty() { | ||
req | ||
} else { | ||
req.bearer_auth(bearer) | ||
}; | ||
let res = req.send().await.unwrap(); | ||
let status = res.status(); | ||
let said: Value = res.json().await.unwrap_or(Value::Null); | ||
assert!(status.is_success(), "{nsid}: {status} {said}"); | ||
said | ||
} | ||
| ||
#[tokio::test] | ||
async fn moves_an_account_and_its_spaces_here_to_become_a_group() { | ||
let n = net(); | ||
if !n.spaces { | ||
eprintln!("the reference PDS has no spaces: GROUP_HOST_DEV_ENV names the alpha's build"); | ||
return; | ||
} | ||
let h = host().await; | ||
// An account of its own on the reference PDS, which moves away. | ||
let name = format!("harbor{}", std::process::id()); | ||
let (handle, email, password) = ( | ||
format!("{name}.test"), | ||
format!("{name}@test.com"), | ||
"harbor-password", | ||
); | ||
let made = pds( | ||
"com.atproto.server.createAccount", | ||
"", | ||
Some(json!({"handle": handle, "email": email, "password": password})), | ||
None, | ||
) | ||
.await; | ||
let (did, jwt) = ( | ||
made["did"].as_str().unwrap(), | ||
made["accessJwt"].as_str().unwrap(), | ||
); | ||
// A forum it governs, which Alice reads, holding a photo; and a space | ||
// of its own it has written nothing in. | ||
let forum = pds( | ||
"com.atproto.space.createSpace", | ||
jwt, | ||
Some(json!({"spaceType": "com.example.forum", "skey": "general", "policy": {"$type": "com.atproto.memberspace.policy", "publicRead": true}})), | ||
None, | ||
) | ||
.await["uri"] | ||
.as_str() | ||
.unwrap() | ||
.to_string(); | ||
let alice = &n.accounts[0]; | ||
let member = json!({"space": forum, "did": alice.did, "read": true, "write": false}); | ||
pds("com.atproto.memberspace.putMember", jwt, Some(member), None).await; | ||
let photo = pds( | ||
"com.atproto.repo.uploadBlob", | ||
jwt, | ||
None, | ||
Some((&[1, 2, 3], "image/png")), | ||
) | ||
.await; | ||
let note = json!({"$type": "com.example.note", "text": "Saturday's ride", "photo": photo["blob"], "createdAt": "2026-11-04T00:00:00Z"}); | ||
let record = json!({"space": forum, "repo": did, "collection": "com.example.note", "rkey": "ride", "record": note}); | ||
pds("com.atproto.space.createRecord", jwt, Some(record), None).await; | ||
let diary = json!({"spaceType": "com.example.diary", "skey": "self", "policy": {"$type": "com.atproto.personalspace.policy"}}); | ||
pds("com.atproto.space.createSpace", jwt, Some(diary), None).await; | ||
// And a calendar of Alice's it writes in. | ||
let session = json!({"identifier": alice.handle, "password": alice.password}); | ||
let session = pds("com.atproto.server.createSession", "", Some(session), None).await; | ||
let hers = session["accessJwt"].as_str().unwrap(); | ||
let calendar = json!({"spaceType": "com.example.calendar", "skey": name, "policy": {"$type": "com.atproto.memberspace.policy"}}); | ||
let calendar = pds("com.atproto.space.createSpace", hers, Some(calendar), None).await; | ||
let calendar = calendar["uri"].as_str().unwrap().to_string(); | ||
let member = json!({"space": calendar, "did": did, "read": true, "write": true}); | ||
pds( | ||
"com.atproto.memberspace.putMember", | ||
hers, | ||
Some(member), | ||
None, | ||
) | ||
.await; | ||
let event = json!({"$type": "com.example.note", "text": "Ride on Saturday", "createdAt": "2026-11-04T00:00:00Z"}); | ||
let record = json!({"space": calendar, "repo": did, "collection": "com.example.note", "rkey": "saturday", "record": event}); | ||
pds("com.atproto.space.createRecord", jwt, Some(record), None).await; | ||
| ||
// Alice moves it, with its own password. | ||
let plain = env(&h, 0); | ||
let mut mover = plain.clone(); | ||
mover.import_password = Some(password.into()); | ||
let said = fails(&plain, &["import", &handle]).await; | ||
assert!(said.contains("set OPENSOCIAL_IMPORT_PASSWORD"), "{said}"); | ||
let said = fails(&mover, &["import", &handle, "--address", "-"]).await; | ||
assert!(said.contains("can't move here"), "{said}"); | ||
let said = fails(&mover, &["import", &handle, "--code", "nothing-sent"]).await; | ||
assert!(said.contains("no move of"), "{said}"); | ||
let club = format!("{name}-club"); | ||
let said = ok(&mover, &["import", &handle, "--address", &club]).await; | ||
assert!(said.contains(&format!("as {club}.groups.test")), "{said}"); | ||
assert!( | ||
said.contains("brought 3 spaces: 2 records, 1 files"), | ||
"{said}" | ||
); | ||
assert!( | ||
said.ends_with(&format!("opensocial import {handle} --code <code>\n")), | ||
"{said}" | ||
); | ||
| ||
// With the code its server emailed, it is finished. | ||
let mail = reqwest::get(format!("{}?to={email}", n.mail)) | ||
.await | ||
.unwrap(); | ||
let code: Value = mail.json().await.unwrap(); | ||
let code = code["code"].as_str().unwrap(); | ||
let said = ok(&mover, &["import", &handle, "--code", code]).await; | ||
assert_eq!( | ||
said, | ||
format!("moved: {club}.groups.test is a group here, run by you\n") | ||
); | ||
let store = &h.host.store; | ||
assert!(h.host.deactivation(did).unwrap().is_none()); | ||
assert!(store.space(&forum).unwrap().unwrap().public_read); | ||
assert_eq!( | ||
store.granted(&forum, &alice.did).unwrap(), | ||
Some((true, false)) | ||
); | ||
let paths = store.space_paths(did, &forum).unwrap(); | ||
assert_eq!(paths.keys().collect::<Vec<_>>(), ["com.example.note/ride"]); | ||
let held = store.space_paths(did, &calendar).unwrap(); | ||
assert_eq!( | ||
held.keys().collect::<Vec<_>>(), | ||
["com.example.note/saturday"] | ||
); | ||
let writers = store.writers(&forum, None, 10).unwrap(); | ||
assert_eq!( | ||
writers.iter().map(|w| w.did.as_str()).collect::<Vec<_>>(), | ||
[did] | ||
); | ||
} | ||
| ||
#[tokio::test] | ||
async fn says_what_is_wrong_with_what_it_is_asked() { | ||
let h = host().await; | ||
docs/design/moving.md+11−1
| @@ -75,7 +75,10 @@ confirms it (an emailed code, on the reference PDS). | ||
out its own), that still names it; otherwise its handle is its | ||
address here, its handle's first label (or one asked for) under this | ||
host's domain. It says when that address, or that handle, is | ||
another's here. | ||
another's here, and which server the account lives on. While the | ||
caller's own move of it is pending, it says again what the PLC | ||
operation should name, so a client that has stopped in between can | ||
have the account's server sign it. | ||
2. **`importAccount`**, for someone this host starts groups for, never | ||
the account itself, and only a did:plc account: the token checked | ||
against the account's key in the directory, for this host or one of | ||
| @@ -100,6 +103,13 @@ confirms it (an emailed code, on the reference PDS). | ||
The old server keeps its copy until its owner deletes it there; once the | ||
DID names this host, the network reads the account here. | ||
| ||
`opensocial import <account>` walks through it, signed in as the person | ||
moving it and, with its own password, as the account at its server (its | ||
server signs its identity over for no app password). It copies the | ||
account and its spaces and has its server email a code; `opensocial | ||
import <account> --code <code>` then has its server sign the operation | ||
and finishes. | ||
| ||
## Its spaces | ||
| ||
Between steps 2 and 3, the one moving it brings its spaces, with | ||
docs/design/README.md+1−1
| @@ -131,7 +131,7 @@ says otherwise. | ||
`methods/{moderation,recovery,importAccount,migration}.ts`, | ||
`hostLabels.ts`, `scripts/move-host.ts`. | ||
9. **MCP and the command.** The `opensocial` command's `create-group`, | ||
`inspect`, `membership`, `migrate` and `seed`, signed in as a person on | ||
`inspect`, `membership`, `migrate`, `import` and `seed`, signed in as a person on | ||
their own PDS (done, see [the commands](../reference/cli.md); moving | ||
the host is `group-host move-host`, as it needs the host's own | ||
database and keys); and the MCP tools over what steps 4 to 8 brought, | ||
docs/reference/cli.md+3−0
| @@ -24,6 +24,8 @@ any PDS may run it against any host. | ||
| `membership eject <group> <member> [--reason]` | puts a member out | | ||
| `membership invite <group> <person> [--message]` | invites someone in | | ||
| `migrate <group> --to <address> [--to-did <did>]` | moves a group, whole, from this host to another ([moving](../design/moving.md)) | | ||
| `import <account> [--address <label>]` | moves an account from its server here, its spaces with it, to become a group run by you; its server emails a code ([moving](../design/moving.md#an-account-becoming-a-group)) | | ||
| `import <account> --code <code>` | with that code, has its server sign its identity over, and finishes | | ||
| `seed <handle>` | a group to try things on: two rules, a moderator role, and an invite for each of `OPENSOCIAL_SEED_INVITE` | | ||
| ||
A group or person is a handle or a DID. Anything else fails with its | ||
| @@ -36,6 +38,7 @@ usage. | ||
| `OPENSOCIAL_HOST` | the host; `http://localhost:2600` | | ||
| `OPENSOCIAL_HOST_DID` | its DID; the did:web of its address | | ||
| `OPENSOCIAL_SEED_INVITE` | who `seed` invites, comma-separated | | ||
| `OPENSOCIAL_IMPORT_PASSWORD` | the password of the account `import` moves, at its own server: its own, as its server signs its identity over for no app password | | ||
| ||
## `just` | ||
| ||
harness/pds.mjs+22−2
| @@ -1,7 +1,7 @@ | ||
// Runs the reference PDS (@atproto/pds, through @atproto/dev-env) and a PLC | ||
// directory on free ports, makes test accounts, prints one JSON line naming | ||
// them, and stops when stdin closes. As knotless's harness/pds.mjs, less what | ||
// only knotless needs. | ||
// them (and where the codes the PDS mails are read), and stops when stdin | ||
// closes. As knotless's harness/pds.mjs, less what only knotless needs. | ||
// | ||
// node harness/pds.mjs [--accounts alice,bob] | ||
// | ||
| @@ -24,6 +24,7 @@ import { execFileSync } from 'node:child_process' | ||
import { tmpdir } from 'node:os' | ||
import dns from 'node:dns' | ||
import tls from 'node:tls' | ||
import http from 'node:http' | ||
| ||
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..') | ||
// The PDS's better-sqlite3 is built for the Node .node-version names. | ||
| @@ -98,16 +99,35 @@ for (const name of names) { | ||
accounts.push({ handle, did, password }) | ||
} | ||
| ||
// The codes the PDS mails to let an account's identity move (an account | ||
// moving to a group host asks for one), kept by address and served at | ||
// `mail`, as the account's inbox would have them. | ||
const codes = new Map() | ||
const mailer = net.pds.ctx.mailer | ||
const sendPlcOperation = mailer.sendPlcOperation.bind(mailer) | ||
mailer.sendPlcOperation = async (params, opts) => { | ||
codes.set(opts.to, params.token) | ||
return sendPlcOperation(params, opts) | ||
} | ||
const inbox = http.createServer((req, res) => { | ||
const code = codes.get(new URL(req.url, 'http://inbox').searchParams.get('to')) | ||
res.writeHead(code ? 200 : 404, { 'content-type': 'application/json' }) | ||
res.end(JSON.stringify(code ? { code } : { error: 'NoMail' })) | ||
}) | ||
await new Promise((resolve) => inbox.listen(0, '127.0.0.1', resolve)) | ||
| ||
const described = await fetch(`${net.pds.url}/xrpc/com.atproto.server.describeServer`).then((r) => r.json()) | ||
console.log(JSON.stringify({ | ||
pds: net.pds.url, | ||
plc: net.plc.url, | ||
spaces: described.spacesAlpha === true, | ||
mail: `http://127.0.0.1:${inbox.address().port}`, | ||
console: { host: CONSOLE_HOST, cert, key }, | ||
accounts, | ||
})) | ||
| ||
const shutdown = async () => { | ||
inbox.close() | ||
await net.close() | ||
process.exit(0) | ||
} | ||
lexicons/fyi/opensocial/checkImport.json+10−1
| @@ -4,7 +4,7 @@ | ||
"defs": { | ||
"main": { | ||
"type": "query", | ||
"description": "What moving an account here would make of it, before anything moves (importAccount moves it so): its handle here, whether that's the one it has, and its address, this host's own name for it, where its site lives. A handle on a domain of the account's own that still names it comes along; one its old server gives out becomes the address. `refused` says why it can't have that address, as importAccount would.", | ||
"description": "What moving an account here would make of it, before anything moves (importAccount moves it so): its handle here, whether that's the one it has, and its address, this host's own name for it, where its site lives. A handle on a domain of the account's own that still names it comes along; one its old server gives out becomes the address. `refused` says why it can't have that address, as importAccount would. While the caller's own move of it is pending, `recommendedCreds` says again what the operation should name, as importAccount did.", | ||
"parameters": { | ||
"type": "params", | ||
"required": [ | ||
| @@ -60,6 +60,15 @@ | ||
"refused": { | ||
"type": "unknown", | ||
"description": "{error, message}: InvalidHandle or HandleNotAvailable." | ||
}, | ||
"pds": { | ||
"type": "string", | ||
"format": "uri", | ||
"description": "The server it lives on now, as its DID document names it." | ||
}, | ||
"recommendedCreds": { | ||
"type": "unknown", | ||
"description": "While the caller's own move of it is pending: rotationKeys, alsoKnownAs, verificationMethods and services, as importAccount answered, for the account's server to sign (com.atproto.identity.signPlcOperation)." | ||
} | ||
} | ||
} | ||