-
Notifications
You must be signed in to change notification settings - Fork 140
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
goat: repo mst command for displaying MST structure #885
Conversation
I like it! And cool how (relatively) little code this is. A couple high-level notes before I dig in to code and play with it myself:
Additional feature brainstorming:
|
@bnewbold good thoughts! I think the output should make sense without color, but allow color to enhance it. How do you feel about this iteration on the output? I think this way of displaying the pointers also helps visually call out proof paths.
|
Here's an example with full CIDs in the output. I display them on a separate line from the key in this case, otherwise the keys are pretty hard to see.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it pretty cool!
If we ever go for colors, a pattern like this would be cool to keep track of the levels.
We could have an option for downloading repos "on-demand" instead of operating on previously downloaded files. I think that's generally more useful for investigations, etc.
Made a small example:
diff --git a/cmd/goat/repo.go b/cmd/goat/repo.go
index 45501445..a2a0466d 100644
--- a/cmd/goat/repo.go
+++ b/cmd/goat/repo.go
@@ -68,7 +68,7 @@ var cmdRepo = &cli.Command{
&cli.Command{
Name: "mst",
Usage: "show repo MST structure",
- ArgsUsage: `<car-file>`,
+ ArgsUsage: `<at-identifier>`,
Flags: []cli.Flag{},
Action: runRepoMST,
},
@@ -210,17 +210,29 @@ func runRepoInspect(cctx *cli.Context) error {
func runRepoMST(cctx *cli.Context) error {
ctx := context.Background()
- carPath := cctx.Args().First()
- if carPath == "" {
- return fmt.Errorf("need to provide path to CAR file as argument")
+ username := cctx.Args().First()
+ if username == "" {
+ return fmt.Errorf("need to provide username as an argument")
}
- fi, err := os.Open(carPath)
+ ident, err := resolveIdent(ctx, username)
+ if err != nil {
+ return err
+ }
+
+ // create a new API client to connect to the account's PDS
+ xrpcc := xrpc.Client{
+ Host: ident.PDSEndpoint(),
+ }
+ if xrpcc.Host == "" {
+ return fmt.Errorf("no PDS endpoint for identity")
+ }
+ repoBytes, err := comatproto.SyncGetRepo(ctx, &xrpcc, ident.DID.String(), "")
if err != nil {
return err
}
// read repository tree in to memory
- r, err := repo.ReadRepoFromCar(ctx, fi)
+ r, err := repo.ReadRepoFromCar(ctx, bytes.NewReader(repoBytes))
if err != nil {
return err
}
and then goat repo mst divy.zone
(or go run . repo mst divy.zone
). If we did this then it could make sense to be outside of the repo
subcommand.
There are other commands (at least list
) that also have this duality of making sense to work out of a downloaded file or directly talking to a PDS. If we like the approach, we could have a more general solution for these cases.
Tidied this up a bit.
|
@rafaelbsky I appreciate the functionality you're going for there! The main things I miss there is that a. it only works on the live version of a repo, not a snapshot, and b. it wouldn't be able to be used to inspect proofs or firehose event contents. You may notice that |
@devinivy That's nice! My intention was that it was an option, I just didn't make it as an option to simplify the example. But using pipes sounds like the ideal approach 👌 |
This adds a flag
--mst
to goat'srepo inspect
command. When passed, the command will output a representation of the repository's MST structure. It may also be used to display the partial MST of a repository, i.e. in the case of a record proof.As part of this work I exposed the
NodeData
andTreeEntry
types from the mst module, which are sufficient for working with raw MST data.The output is intended to be a faithful representation of the MST:
....
) represent the length of the key prefix.✗
appears in the output when the block behind a CID pointer is not present, which should not occur when inspecting a full repository but is generally expected when inspecting a proof.Example: