Skip to content
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

feat(cmd/goat): XRPC subcommand #879

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bleonard252
Copy link

This PR introduces a generic XRPC subcommand, which allows executing XRPC queries and procedures on your PDS, or via the atproto-proxy header (which is set with the --proxy flag). This should aid in the development of XRPC endpoints, and it may be helpful for power users.

A screenshot of the command being run in a terminal, with the proxy DID redacted.

NAME:
   goat xrpc - use an XRPC endpoint

USAGE:
   goat xrpc [command options] <nsid> [paramKey=paramValue...]

DESCRIPTION:
   Execute an XRPC query or procedure via your PDS. Procedure inputs should be provided via standard input (i.e. a pipe, or redirection with <).

OPTIONS:
   --proxy value            the service to proxy to, referred to by its DID and service ID
   --type value             the MIME type of the request body for a procedure (default: "application/json")
   --procedure, --post, -p  execute an XRPC procedure (POST request) (default: false)
   --query, -q, --get, -g   execute an XRPC query (GET request) (default: false)
   --help, -h               show help

I set procedure and query to be options instead of subcommands so that lexicon resolution can be added later. If a lexicon resolves for a given NSID, the lexicon will tell it which one (procedure or query) it needs to be.

@bleonard252
Copy link
Author

bleonard252 commented Dec 17, 2024

I'm noticing that XrpcClient.Do seems to have poor error reporting. I think it should attempt to output the body in the error, if it's JSON or plaintext, and at least the status code. Right now it's just "retrying," and the error message is that it "gave up" after trying 4 times:

error: request failed: Post "https://puffball.us-east.host.bsky.network/xrpc/xyz.northwoodforum.hierarchy.createCategory": POST https://puffball.us-east.host.bsky.network/xrpc/xyz.northwoodforum.hierarchy.createCategory giving up after 4 attempt(s)

edit: it also sometimes just gives generic error messages for HTTP status codes like 400, 404, 403, 401:

error: XRPC ERROR 400: InvalidRequest: InvalidRequest

@bnewbold
Copy link
Collaborator

I've had something like this on my TODO list for a while! I haven't dug in super deep to your implementation here, but I really like the HTTPie "interface" and copied that in an earlier atproto CLI tool: https://gitlab.com/bnewbold/adenosine/-/blob/main/extra/adenosine.1.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants