Skip to content

Commit

Permalink
updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold committed Feb 26, 2025
1 parent 377d159 commit 7acf5a5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Run with, eg, `go run ./cmd/bigsky`):
- `cmd/sonar`: event stream monitoring tool
- `cmd/hepa`: auto-moderation rule engine service
- `cmd/rainbow`: firehose fanout service
- `cmd/domesbook`: identity directory service
- `cmd/domesday`: identity directory service
- `gen`: dev tool to run CBOR type codegen

Packages:
Expand Down
20 changes: 18 additions & 2 deletions cmd/domesday/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/labstack/echo/v4"
)

// GET /xrpc/com.atproto.identity.resolveHandle
func (srv *Server) ResolveHandle(c echo.Context) error {
ctx := c.Request().Context()

Expand Down Expand Up @@ -40,6 +41,7 @@ func (srv *Server) ResolveHandle(c echo.Context) error {
})
}

// GET /xrpc/com.atproto.identity.resolveDid
func (srv *Server) ResolveDid(c echo.Context) error {
ctx := c.Request().Context()

Expand Down Expand Up @@ -68,6 +70,7 @@ func (srv *Server) ResolveDid(c echo.Context) error {
})
}

// helper for resolveIdentity
func (srv *Server) resolveIdentityFromHandle(c echo.Context, handle syntax.Handle) error {
ctx := c.Request().Context()

Expand Down Expand Up @@ -123,6 +126,7 @@ func (srv *Server) resolveIdentityFromHandle(c echo.Context, handle syntax.Handl
})
}

// helper for resolveIdentity
func (srv *Server) resolveIdentityFromDID(c echo.Context, did syntax.DID) error {
ctx := c.Request().Context()

Expand Down Expand Up @@ -167,6 +171,7 @@ func (srv *Server) resolveIdentityFromDID(c echo.Context, did syntax.DID) error
})
}

// GET /xrpc/com.atproto.identity.resolveIdentity
func (srv *Server) ResolveIdentity(c echo.Context) error {
// we partially re-implement the "Lookup()" logic here, but returning the full DID document, not `identity.Identity`
atid, err := syntax.ParseAtIdentifier(c.QueryParam("identifier"))
Expand All @@ -188,10 +193,19 @@ func (srv *Server) ResolveIdentity(c echo.Context) error {
return fmt.Errorf("unreachable code path")
}

// POST /xrpc/com.atproto.identity.refreshIdentity
func (srv *Server) RefreshIdentity(c echo.Context) error {
ctx := c.Request().Context()

atid, err := syntax.ParseAtIdentifier(c.QueryParam("identifier"))
var body comatproto.IdentityRefreshIdentity_Input
if err := c.Bind(&body); err != nil {
return c.JSON(400, GenericError{
Error: "InvalidRequestBody",
Message: err.Error(),
})
}

atid, err := syntax.ParseAtIdentifier(body.Identifier)
if err != nil {
return c.JSON(400, GenericError{
Error: "InvalidIdentifierSyntax",
Expand All @@ -204,15 +218,17 @@ func (srv *Server) RefreshIdentity(c echo.Context) error {
if err := srv.dir.PurgeDID(ctx, did); err != nil {
return err
}
return srv.resolveIdentityFromDID(c, did)
}
handle, err := atid.AsHandle()
if nil == err {
if err := srv.dir.PurgeHandle(ctx, handle); err != nil {
return err
}
return srv.resolveIdentityFromHandle(c, handle)
}

return srv.ResolveIdentity(c)
return fmt.Errorf("unreachable code path")
}

type GenericStatus struct {
Expand Down
45 changes: 45 additions & 0 deletions cmd/domesday/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ func run(args []string) error {
},
},
},
&cli.Command{
Name: "refresh",
ArgsUsage: `<at-identifier>`,
Usage: "ask service to refresh identity",
Action: runRefreshCmd,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "host",
Usage: "domesday server to send request to",
Value: "http://localhost:6600",
EnvVars: []string{"DOMESDAY_HOST"},
},
},
},
},
}

Expand Down Expand Up @@ -259,3 +273,34 @@ func runLookupCmd(cctx *cli.Context) error {
fmt.Println(string(b))
return nil
}

func runRefreshCmd(cctx *cli.Context) error {
ctx := context.Background()
dir := configClient(cctx)

s := cctx.Args().First()
if s == "" {
return fmt.Errorf("need to provide identifier for resolution")
}
atid, err := syntax.ParseAtIdentifier(s)
if err != nil {
return err
}

err = dir.Purge(ctx, *atid)
if err != nil {
return err
}

ident, err := dir.Lookup(ctx, *atid)
if err != nil {
return err
}

b, err := json.MarshalIndent(ident, "", " ")
if err != nil {
return err
}
fmt.Println(string(b))
return nil
}

0 comments on commit 7acf5a5

Please sign in to comment.