this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

identity: move resolution to BaseDirectory

+28 -37
+9 -20
atproto/identity/base_directory.go
··· 7 7 "github.com/bluesky-social/indigo/atproto/syntax" 8 8 ) 9 9 10 - type BasicDirectory struct { 10 + type BaseDirectory struct { 11 11 PLCURL string 12 12 } 13 13 14 - var _ Directory = (*BasicDirectory)(nil) 14 + var _ Directory = (*BaseDirectory)(nil) 15 15 16 - func NewBasicDirectory(plcURL string) BasicDirectory { 16 + func NewBaseDirectory(plcURL string) BaseDirectory { 17 17 if plcURL == "" { 18 18 plcURL = DefaultPLCURL 19 19 } 20 - return BasicDirectory{ 20 + return BaseDirectory{ 21 21 PLCURL: plcURL, 22 22 } 23 23 } 24 24 25 - func (d *BasicDirectory) ResolveDID(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 26 - switch did.Method() { 27 - case "web": 28 - return ResolveDIDWeb(ctx, did) 29 - case "plc": 30 - return ResolveDIDPLC(ctx, d.PLCURL, did) 31 - default: 32 - return nil, fmt.Errorf("DID method not supported: %s", did.Method()) 33 - } 34 - } 35 - 36 - func (d *BasicDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) { 37 - did, err := ResolveHandle(ctx, h) 25 + func (d *BaseDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Identity, error) { 26 + did, err := d.ResolveHandle(ctx, h) 38 27 if err != nil { 39 28 return nil, err 40 29 } ··· 60 49 return &ident, nil 61 50 } 62 51 63 - func (d *BasicDirectory) LookupDID(ctx context.Context, did syntax.DID) (*Identity, error) { 52 + func (d *BaseDirectory) LookupDID(ctx context.Context, did syntax.DID) (*Identity, error) { 64 53 doc, err := d.ResolveDID(ctx, did) 65 54 if err != nil { 66 55 return nil, err ··· 70 59 if err != nil { 71 60 return nil, err 72 61 } 73 - resolvedDID, err := ResolveHandle(ctx, declared) 62 + resolvedDID, err := d.ResolveHandle(ctx, declared) 74 63 if err != nil { 75 64 return nil, err 76 65 } ··· 86 75 return &ident, nil 87 76 } 88 77 89 - func (d *BasicDirectory) Lookup(ctx context.Context, a syntax.AtIdentifier) (*Identity, error) { 78 + func (d *BaseDirectory) Lookup(ctx context.Context, a syntax.AtIdentifier) (*Identity, error) { 90 79 handle, err := a.AsHandle() 91 80 if nil == err { // if *not* an error 92 81 return d.LookupHandle(ctx, handle)
+5 -3
atproto/identity/cmd/atp-id/main.go
··· 50 50 } 51 51 fmt.Printf("valid at-identifier syntax: %s\n", id) 52 52 53 - ndir := identity.NewBasicDirectory("https://plc.directory") 53 + ndir := identity.NewBaseDirectory("https://plc.directory") 54 54 55 55 acc, err := ndir.Lookup(ctx, *id) 56 56 if err != nil { ··· 73 73 } 74 74 fmt.Printf("valid handle syntax: %s\n", handle) 75 75 76 - did, err := identity.ResolveHandle(ctx, handle) 76 + d := identity.NewBaseDirectory(identity.DefaultPLCURL) 77 + did, err := d.ResolveHandle(ctx, handle) 77 78 if err != nil { 78 79 return err 79 80 } ··· 96 97 } 97 98 fmt.Printf("valid DID syntax: %s\n", did) 98 99 99 - doc, err := identity.DefaultResolveDID(ctx, did) 100 + d := identity.NewBaseDirectory(identity.DefaultPLCURL) 101 + doc, err := d.ResolveDID(ctx, did) 100 102 if err != nil { 101 103 return err 102 104 }
+5 -5
atproto/identity/did.go
··· 32 32 } 33 33 34 34 // WARNING: this does *not* bi-directionally verify account metadata; it only implements direct DID-to-DID-document lookup for the supported DID methods, and parses the resulting DID Doc into an Identity struct 35 - func DefaultResolveDID(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 35 + func (d *BaseDirectory) ResolveDID(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 36 36 switch did.Method() { 37 37 case "web": 38 - return ResolveDIDWeb(ctx, did) 38 + return d.ResolveDIDWeb(ctx, did) 39 39 case "plc": 40 - return ResolveDIDPLC(ctx, DefaultPLCURL, did) 40 + return d.ResolveDIDPLC(ctx, DefaultPLCURL, did) 41 41 default: 42 42 return nil, fmt.Errorf("DID method not supported: %s", did.Method()) 43 43 } 44 44 } 45 45 46 - func ResolveDIDWeb(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 46 + func (d *BaseDirectory) ResolveDIDWeb(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 47 47 if did.Method() != "web" { 48 48 return nil, fmt.Errorf("expected a did:web, got: %s", did) 49 49 } ··· 84 84 } 85 85 86 86 // plcURL should have URL method, hostname, and optional port; it should not have a path or trailing slash 87 - func ResolveDIDPLC(ctx context.Context, plcURL string, did syntax.DID) (*DIDDocument, error) { 87 + func (d *BaseDirectory) ResolveDIDPLC(ctx context.Context, plcURL string, did syntax.DID) (*DIDDocument, error) { 88 88 if did.Method() != "plc" { 89 89 return nil, fmt.Errorf("expected a did:plc, got: %s", did) 90 90 }
+5 -5
atproto/identity/handle.go
··· 13 13 ) 14 14 15 15 // Does not cross-verify, just does the handle resolution step. 16 - func ResolveHandleDNS(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 16 + func (d *BaseDirectory) ResolveHandleDNS(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 17 17 // TODO: timeout 18 18 // TODO: mechanism to control NDS better; context? separate method? 19 19 ··· 42 42 return "", ErrHandleNotFound 43 43 } 44 44 45 - func ResolveHandleWellKnown(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 45 + func (d *BaseDirectory) ResolveHandleWellKnown(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 46 46 // TODO: timeout 47 47 // TODO: could pull a client or transport from context? 48 48 c := http.DefaultClient ··· 79 79 return syntax.ParseDID(line) 80 80 } 81 81 82 - func ResolveHandle(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 83 - did, dnsErr := ResolveHandleDNS(ctx, handle) 82 + func (d *BaseDirectory) ResolveHandle(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 83 + did, dnsErr := d.ResolveHandleDNS(ctx, handle) 84 84 if dnsErr == nil { 85 85 return did, nil 86 86 } 87 - did, httpErr := ResolveHandleWellKnown(ctx, handle) 87 + did, httpErr := d.ResolveHandleWellKnown(ctx, handle) 88 88 if httpErr == nil { 89 89 return did, nil 90 90 }
+1 -1
atproto/identity/identity.go
··· 41 41 42 42 // Returns a reasonable default Directory implementation for most use cases 43 43 func DefaultDirectory() Directory { 44 - naive := NewBasicDirectory(DefaultPLCURL) 44 + naive := NewBaseDirectory(DefaultPLCURL) 45 45 cached := NewCacheDirectory(&naive) 46 46 return &cached 47 47 }
+3 -3
atproto/identity/live_test.go
··· 49 49 assert.Error(err) 50 50 } 51 51 52 - func TestBasicDirectory(t *testing.T) { 52 + func TestBaseDirectory(t *testing.T) { 53 53 // XXX: t.Skip("skipping live network test") 54 - d := NewBasicDirectory(DefaultPLCURL) 54 + d := NewBaseDirectory(DefaultPLCURL) 55 55 testDirectoryLive(t, &d) 56 56 } 57 57 58 58 func TestCacheDirectory(t *testing.T) { 59 59 // XXX: t.Skip("skipping live network test") 60 - inner := NewBasicDirectory(DefaultPLCURL) 60 + inner := NewBaseDirectory(DefaultPLCURL) 61 61 d := NewCacheDirectory(&inner) 62 62 for i := 0; i < 3; i = i + 1 { 63 63 testDirectoryLive(t, &d)