From bde8973666c58a8fa51702b728df1717aa7af211 Mon Sep 17 00:00:00 2001 From: eris Date: Mon, 28 Oct 2024 11:37:35 -0400 Subject: [PATCH 1/5] add change-handle subcommand to account.sh --- pdsadmin/account.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pdsadmin/account.sh b/pdsadmin/account.sh index 86a5f1e..beafc1c 100644 --- a/pdsadmin/account.sh +++ b/pdsadmin/account.sh @@ -228,6 +228,32 @@ elif [[ "${SUBCOMMAND}" == "reset-password" ]]; then echo "New password: ${PASSWORD}" echo +# +# account change-handle +# +elif [[ "${SUBCOMMAND}" == "change-handle" ]]; then + DID="${2:-}" + HANDLE="${3:-}" + + if [[ "${DID}" == "" ]]; then + echo "ERROR: missing DID parameter." >/dev/stderr + echo "Usage: $0 ${SUBCOMMAND} " >/dev/stderr + exit 1 + i + + if [[ "${DID}" != did:* ]]; then + echo "ERROR: DID parameter must start with \"did:\"." >/dev/stderr + echo "Usage: $0 ${SUBCOMMAND} " >/dev/stderr + exit 1 + fi + + curl_cmd_post \ + --user "admin:${PDS_ADMIN_PASSWORD}" + --data "{\"did\": \"${DID}\", \"handle\": \"${HANDLE}\"}" \ + "https://${PDS_HOSTNAME}/xrpc/com.atproto.admin.updateAccountHandle" > /dev/null + + echo "Changed handle of ${DID} to ${HANDLE}" + else echo "Unknown subcommand: ${SUBCOMMAND}" >/dev/stderr exit 1 From 2de7bb0a0a6d46b90fdc02aab8d7d122227f0cce Mon Sep 17 00:00:00 2001 From: eris Date: Mon, 28 Oct 2024 11:40:07 -0400 Subject: [PATCH 2/5] describe account change-handle in help command --- pdsadmin/help.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pdsadmin/help.sh b/pdsadmin/help.sh index 1a0b16e..3a0eb69 100644 --- a/pdsadmin/help.sh +++ b/pdsadmin/help.sh @@ -30,6 +30,9 @@ account reset-password Reset a password for an account specified by DID. e.g. pdsadmin account reset-password did:plc:xyz123abc456 + change-handle + Change the handle for an account specified by DID + e.g. pdsadmin account change-handle did:plc:xyz123abc456 alice.example.com request-crawl [] Request a crawl from a relay host. From 5ef0941d618a6eceec6ead4c72e15f7eb99ea8af Mon Sep 17 00:00:00 2001 From: eris Date: Mon, 28 Oct 2024 11:57:22 -0400 Subject: [PATCH 3/5] Update account.sh --- pdsadmin/account.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pdsadmin/account.sh b/pdsadmin/account.sh index beafc1c..3bc306b 100644 --- a/pdsadmin/account.sh +++ b/pdsadmin/account.sh @@ -234,25 +234,30 @@ elif [[ "${SUBCOMMAND}" == "reset-password" ]]; then elif [[ "${SUBCOMMAND}" == "change-handle" ]]; then DID="${2:-}" HANDLE="${3:-}" - + if [[ "${DID}" == "" ]]; then echo "ERROR: missing DID parameter." >/dev/stderr - echo "Usage: $0 ${SUBCOMMAND} " >/dev/stderr + echo "Usage: $0 ${SUBCOMMAND} " >/dev/stderr exit 1 - i - + fi + + if [[ "${HANDLE}" == "" ]]; then + echo "ERROR: missing handle parameter" >/dev/stderr + echo "Usave: $0 ${SUBCOMMAND} " + fi + if [[ "${DID}" != did:* ]]; then echo "ERROR: DID parameter must start with \"did:\"." >/dev/stderr - echo "Usage: $0 ${SUBCOMMAND} " >/dev/stderr + echo "Usage: $0 ${SUBCOMMAND} " >/dev/stderr exit 1 fi - + curl_cmd_post \ - --user "admin:${PDS_ADMIN_PASSWORD}" - --data "{\"did\": \"${DID}\", \"handle\": \"${HANDLE}\"}" \ + --user "admin:${PDS_ADMIN_PASSWORD}" \ + --data "{\"did\":\"${DID}\",\"handle\":\"${HANDLE}\"}" \ "https://${PDS_HOSTNAME}/xrpc/com.atproto.admin.updateAccountHandle" > /dev/null - echo "Changed handle of ${DID} to ${HANDLE}" + echo "Updated handle to ${HANDLE} for account ${DID}" else echo "Unknown subcommand: ${SUBCOMMAND}" >/dev/stderr From 171a3d8d86e970d5e28b7b7ff2047e2125b6aa07 Mon Sep 17 00:00:00 2001 From: eris Date: Mon, 28 Oct 2024 12:09:43 -0400 Subject: [PATCH 4/5] better error handling for change-handle --- pdsadmin/account.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pdsadmin/account.sh b/pdsadmin/account.sh index 3bc306b..62c78eb 100644 --- a/pdsadmin/account.sh +++ b/pdsadmin/account.sh @@ -252,12 +252,15 @@ elif [[ "${SUBCOMMAND}" == "change-handle" ]]; then exit 1 fi - curl_cmd_post \ + RESULT="$(curl_cmd_post_nofail \ --user "admin:${PDS_ADMIN_PASSWORD}" \ --data "{\"did\":\"${DID}\",\"handle\":\"${HANDLE}\"}" \ - "https://${PDS_HOSTNAME}/xrpc/com.atproto.admin.updateAccountHandle" > /dev/null + "https://${PDS_HOSTNAME}/xrpc/com.atproto.admin.updateAccountHandle")" - echo "Updated handle to ${HANDLE} for account ${DID}" + if [[ -n "$(echo "$RESULT" | jq --raw-output '.error')" ]]; then + echo "ERROR: $(echo "$RESULT" | jq --raw-output '.message')" >/dev/stderr + exit 1 + fi else echo "Unknown subcommand: ${SUBCOMMAND}" >/dev/stderr From aca56f73b7f4a5ac5f53c3b6b304876ecd1a8370 Mon Sep 17 00:00:00 2001 From: eris Date: Mon, 28 Oct 2024 12:20:04 -0400 Subject: [PATCH 5/5] correct another minor oversight oops --- pdsadmin/account.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdsadmin/account.sh b/pdsadmin/account.sh index 62c78eb..5ed5e69 100644 --- a/pdsadmin/account.sh +++ b/pdsadmin/account.sh @@ -243,7 +243,8 @@ elif [[ "${SUBCOMMAND}" == "change-handle" ]]; then if [[ "${HANDLE}" == "" ]]; then echo "ERROR: missing handle parameter" >/dev/stderr - echo "Usave: $0 ${SUBCOMMAND} " + echo "Usage: $0 ${SUBCOMMAND} " + exit 1 fi if [[ "${DID}" != did:* ]]; then