-
Notifications
You must be signed in to change notification settings - Fork 293
improve pdsadmin invite based commands #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaspermayone
wants to merge
4
commits into
bluesky-social:main
Choose a base branch
from
jaspermayone-forks:feat/improvements-to-invite-create
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b535f3e
Improve invite command
jaspermayone 1e9980e
Add backwards compatibility for create-invite-code
jaspermayone d6ed09f
Add goat notice to help and all commands
jaspermayone 2f8f2c6
Improve invite command UX: validate inputs and handle empty results
jaspermayone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" \ | ||
| "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' | ||
|
jaspermayone marked this conversation as resolved.
Outdated
|
||
| fi | ||
|
|
||
| echo -e "Code\tUses\tStatus" | ||
| echo "${CODES_JSON}" | jq --raw-output "${JQ_FILTER}" | column --table | ||
|
|
||
|
jaspermayone marked this conversation as resolved.
Outdated
|
||
| # | ||
| # invite create [use_count] | ||
| # | ||
| elif [[ "${SUBCOMMAND}" == "create" ]]; then | ||
| USE_COUNT="${2:-1}" | ||
|
|
||
|
jaspermayone marked this conversation as resolved.
|
||
| CODE="$(curl_cmd_post \ | ||
| --user "admin:${PDS_ADMIN_PASSWORD}" \ | ||
|
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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.