Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ sudo pdsadmin account create
If needed, use `pdsadmin` to create an invite code:

```bash
sudo pdsadmin create-invite-code
sudo pdsadmin invite create
```

When creating an account using the app, enter this invite code.
Expand Down
17 changes: 0 additions & 17 deletions pdsadmin/create-invite-code.sh

This file was deleted.

13 changes: 11 additions & 2 deletions pdsadmin/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ request-crawl [<RELAY HOST>]
Request a crawl from a relay host.
e.g. pdsadmin request-crawl bsky.network

invite
list [FILTER]
List invite codes. Filter: used, disabled, free
e.g. pdsadmin invite list
e.g. pdsadmin invite list free
create [COUNT]
Create a new invite code with optional use count (default: 1)
e.g. pdsadmin invite create
e.g. pdsadmin invite create 5

create-invite-code
Create a new invite code.
e.g. pdsadmin create-invite-code
Removed. Use 'pdsadmin invite create' instead.

help
Display this help information.
Expand Down
72 changes: 72 additions & 0 deletions pdsadmin/invite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail

PDS_ENV_FILE=${PDS_ENV_FILE:-"/pds/pds.env"}
source "${PDS_ENV_FILE}"

# curl a URL and fail if the request fails.
function curl_cmd_get {
curl --fail --silent --show-error "$@"
}

# curl a URL and fail if the request fails.
function curl_cmd_post {
curl --fail --silent --show-error --request POST --header "Content-Type: application/json" "$@"
}

# The subcommand to run.
SUBCOMMAND="${1:-}"

#
# invite list [filter]
#
if [[ "${SUBCOMMAND}" == "list" ]]; then
FILTER="${2:-}"

CODES_JSON="$(curl_cmd_get \
--user "admin:${PDS_ADMIN_PASSWORD}" \
Comment thread
jaspermayone marked this conversation as resolved.
"https://${PDS_HOSTNAME}/xrpc/com.atproto.admin.getInviteCodes"
)"

if [[ "${FILTER}" == "used" ]]; then
# Show codes that have been used
JQ_FILTER='.codes[] | select(.uses != []) | [.code, (.uses | length | tostring), (if .disabled then "disabled" else "active" end)] | @tsv'
elif [[ "${FILTER}" == "disabled" ]]; then
# Show disabled codes
JQ_FILTER='.codes[] | select(.disabled == true) | [.code, (.uses | length | tostring), "disabled"] | @tsv'
elif [[ "${FILTER}" == "free" ]]; then
# Show codes that are not used and not disabled
JQ_FILTER='.codes[] | select(.uses == [] and .disabled == false) | [.code, "0", "active"] | @tsv'
else
# Show all codes
JQ_FILTER='.codes[] | [.code, (.uses | length | tostring), (if .disabled then "disabled" else "active" end)] | @tsv'
Comment thread
jaspermayone marked this conversation as resolved.
Outdated
fi

echo -e "Code\tUses\tStatus"
echo "${CODES_JSON}" | jq --raw-output "${JQ_FILTER}" | column --table

Comment thread
jaspermayone marked this conversation as resolved.
Outdated
#
# invite create [use_count]
#
elif [[ "${SUBCOMMAND}" == "create" ]]; then
USE_COUNT="${2:-1}"

Comment thread
jaspermayone marked this conversation as resolved.
CODE="$(curl_cmd_post \
--user "admin:${PDS_ADMIN_PASSWORD}" \
Comment thread
jaspermayone marked this conversation as resolved.
--data "{\"useCount\": ${USE_COUNT}}" \
"https://${PDS_HOSTNAME}/xrpc/com.atproto.server.createInviteCode" | jq --raw-output '.code'
)"

echo "${CODE}"

else
echo "Unknown subcommand: ${SUBCOMMAND}" >/dev/stderr
echo "Usage: pdsadmin invite <command>" >/dev/stderr
echo "" >/dev/stderr
echo "Commands:" >/dev/stderr
echo " list [filter] List invite codes (filter: used, disabled, free)" >/dev/stderr
echo " create [count] Create a new invite code (default: 1 use)" >/dev/stderr
exit 1
fi