From c1231245a4df41cc3d6131be462d22a1b841b52a Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 11 Sep 2022 10:51:08 +0200 Subject: [PATCH] Complete self-destruct support --- Makefile | 4 ++++ app/boxes.py | 26 ++++++++++++++++++++++++++ docs/user_guide.md | 12 +++++++++--- tasks.py | 22 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9671a4c..ee214f5 100644 --- a/Makefile +++ b/Makefile @@ -25,3 +25,7 @@ webfinger: .PHONY: move-to move-to: -docker run --volume `pwd`/data:/app/data --volume `pwd`/app/static:/app/app/static microblogpub/microblogpub inv move-to $(account) + +.PHONY: self-destruct +move-to: + -docker run --volume `pwd`/data:/app/data --volume `pwd`/app/static:/app/app/static microblogpub/microblogpub inv self-destruct diff --git a/app/boxes.py b/app/boxes.py index f38c296..a6fd090 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -94,6 +94,7 @@ async def send_delete(db_session: AsyncSession, ap_object_id: str) -> None: raise ValueError(f"{ap_object_id} not found in the outbox") delete_id = allocate_outbox_id() + # FIXME addressing delete = { "@context": ap.AS_EXTENDED_CTX, "id": outbox_object_id(delete_id), @@ -405,6 +406,31 @@ async def send_move( await db_session.commit() +async def send_self_destruct(db_session: AsyncSession) -> None: + delete_id = allocate_outbox_id() + delete = { + "@context": ap.AS_EXTENDED_CTX, + "id": outbox_object_id(delete_id), + "type": "Delete", + "actor": ID, + "object": ID, + "to": [ap.AS_PUBLIC], + } + outbox_object = await save_outbox_object( + db_session, + delete_id, + delete, + ) + if not outbox_object.id: + raise ValueError("Should never happen") + + recipients = await compute_all_known_recipients(db_session) + for rcp in recipients: + await new_outgoing_activity(db_session, rcp, outbox_object.id) + + await db_session.commit() + + async def send_create( db_session: AsyncSession, ap_type: str, diff --git a/docs/user_guide.md b/docs/user_guide.md index da1c472..30f76c1 100644 --- a/docs/user_guide.md +++ b/docs/user_guide.md @@ -341,10 +341,16 @@ make account=username@domain.tld move-to ### Deleting the instance -**This section is just a draft.** - You want to delete your instance, you can request other instances to delete your remote profile. -Once deleted, you won't be able to use your instance anymore. + +Note that this is a best-effort delete as some instances may not delete your data. + +The command won't remove any local data, it just broadcast account deletion messages to all known servers. + +After executing the command, you should let the server run until all the outgoing delete tasks are sent. + +Once deleted, you won't be able to use your instance anymore, but you will be able to perform a fresh re-install of any ActivityPub software. + #### Python edition diff --git a/tasks.py b/tasks.py index 512240e..17e1754 100644 --- a/tasks.py +++ b/tasks.py @@ -271,6 +271,28 @@ def move_to(ctx, moved_to): asyncio.run(_send_move()) +@task +def self_destruct(ctx): + # type: (Context) -> None + from loguru import logger + + from app.boxes import send_self_destruct + from app.database import async_session + + logger.disable("app") + + async def _send_self_destruct(): + if input("Initiating self destruct, type yes to confirm: ") != "yes": + print("Aborting") + + async with async_session() as db_session: + await send_self_destruct(db_session) + + print("Done") + + asyncio.run(_send_self_destruct()) + + @task def yunohost_config( ctx,