Documentation ¶
Overview ¶
Package registry defines primitives for keeping centralized repositories of qri types (peers, datasets, etc). It uses classical client/server patterns, arranging types into cannonical stores.
At first glance, this seems to run against the grain of "decentralize or die" principles espoused by those of us interested in reducing points of failure in a network. Registries offer a way to operate as a federated model, with peers opting-in to a set of norms set forth by a registry.
It is a long term goal at qri that it be *possible* to fully decentralize all aspects, of qri this isn't practical short-term, and isn't always a desired property.
As an example, associating human-readable usernames with crypto keypairs is an order of magnitude easier if you just put the damn thing in a list. So that's what this registry does.
This base package provides common primitives that other packages can import to work with a registry, and subpackages for turning these primitives into usable tools like servers & (eventually) command-line clients
Index ¶
- Variables
- func DeregisterProfile(store Profiles, p *Profile) error
- func RegisterProfile(store Profiles, p *Profile) (err error)
- func UpdateProfile(store Profiles, p *Profile) (err error)
- type Indexer
- type MemProfiles
- func (ps *MemProfiles) Create(key string, value *Profile) error
- func (ps *MemProfiles) Delete(key string) error
- func (ps *MemProfiles) Len() (int, error)
- func (ps *MemProfiles) Load(key string) (value *Profile, err error)
- func (ps *MemProfiles) Range(iter func(key string, p *Profile) (kontinue bool, err error)) (err error)
- func (ps *MemProfiles) SortedRange(iter func(key string, p *Profile) (kontinue bool, err error)) (err error)
- func (ps *MemProfiles) Update(key string, value *Profile) error
- type MemReputations
- func (rs *MemReputations) Add(r *Reputation) error
- func (rs *MemReputations) Delete(key string)
- func (rs *MemReputations) Len() int
- func (rs *MemReputations) Load(key string) (value *Reputation, ok bool)
- func (rs *MemReputations) Range(iter func(key string, r *Reputation) (brk bool))
- func (rs *MemReputations) SortedRange(iter func(key string, r *Reputation) (brk bool))
- func (rs *MemReputations) Store(key string, value *Reputation)
- type MockSearch
- type NilSearch
- type Profile
- type Profiles
- type Registry
- type Reputation
- type ReputationResponse
- type Reputations
- type SearchParams
- type Searchable
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUsernameTaken is for when a peername is already taken ErrUsernameTaken = fmt.Errorf("username is taken") // ErrNoRegistry represents the lack of a configured registry ErrNoRegistry = fmt.Errorf("no registry is configured") // ErrNotFound represents a missing record ErrNotFound = fmt.Errorf("not found") )
var ErrSearchNotSupported = fmt.Errorf("search not supported")
ErrSearchNotSupported is the canonical error to indicate search isn't implemented
Functions ¶
func DeregisterProfile ¶
DeregisterProfile removes a profile from the registry if it exists confirming the user has the authority to do so
func RegisterProfile ¶
RegisterProfile adds a profile to the list if it's valid and the desired handle isn't taken
func UpdateProfile ¶
UpdateProfile alters profile data
Types ¶
type Indexer ¶
type Indexer interface { // IndexDatasets adds one or more datasets to a search index IndexDatasets([]*dataset.Dataset) error // UnindexDatasets removes one or more datasets from a search index UnindexDatasets([]*dataset.Dataset) error }
Indexer is an interface for adding registry values to a search index
type MemProfiles ¶
MemProfiles is a map of profile data safe for concurrent use heavily inspired by sync.Map
func NewMemProfiles ¶
func NewMemProfiles() *MemProfiles
NewMemProfiles allocates a new *MemProfiles map
func (*MemProfiles) Create ¶
func (ps *MemProfiles) Create(key string, value *Profile) error
Create adds a profile
func (*MemProfiles) Delete ¶
func (ps *MemProfiles) Delete(key string) error
Delete removes a record from MemProfiles at key
func (*MemProfiles) Len ¶
func (ps *MemProfiles) Len() (int, error)
Len returns the number of records in the map
func (*MemProfiles) Load ¶
func (ps *MemProfiles) Load(key string) (value *Profile, err error)
Load fetches a profile from the list by key
func (*MemProfiles) Range ¶
func (ps *MemProfiles) Range(iter func(key string, p *Profile) (kontinue bool, err error)) (err error)
Range calls an iteration fuction on each element in the map until the end of the list is reached or iter returns true
func (*MemProfiles) SortedRange ¶
func (ps *MemProfiles) SortedRange(iter func(key string, p *Profile) (kontinue bool, err error)) (err error)
SortedRange is like range but with deterministic key ordering
type MemReputations ¶
MemReputations is a map of reputation data safe for concurrent use heavily inspired by sync.Map
func NewMemReputations ¶
func NewMemReputations() *MemReputations
NewMemReputations allocates a new *MemReputations map
func (*MemReputations) Add ¶
func (rs *MemReputations) Add(r *Reputation) error
Add adds the reputation to the map of reputations it Validates the reputation before adding it
func (*MemReputations) Delete ¶
func (rs *MemReputations) Delete(key string)
Delete removes a record from MemReputations at key
func (*MemReputations) Len ¶
func (rs *MemReputations) Len() int
Len returns the number of records in the map
func (*MemReputations) Load ¶
func (rs *MemReputations) Load(key string) (value *Reputation, ok bool)
Load fetches a reputation from the list by key
func (*MemReputations) Range ¶
func (rs *MemReputations) Range(iter func(key string, r *Reputation) (brk bool))
Range calls an iteration fuction on each element in the map until the end of the list is reached or iter returns true
func (*MemReputations) SortedRange ¶
func (rs *MemReputations) SortedRange(iter func(key string, r *Reputation) (brk bool))
SortedRange is like range but with deterministic key ordering
func (*MemReputations) Store ¶
func (rs *MemReputations) Store(key string, value *Reputation)
Store adds an entry
type MockSearch ¶
MockSearch is a very naive implementation of search that wraps registry.Datasets and only checks for exact substring matches of dataset's meta.title property. It's mainly intended for testing purposes.
func (MockSearch) Search ¶
func (ms MockSearch) Search(p SearchParams) (results []*dataset.Dataset, err error)
Search is a trivial search implementation used for testing
type NilSearch ¶
type NilSearch bool
NilSearch is a basic implementation of Searchable which returns an error to indicate that search is not supported
type Profile ¶
type Profile struct { Created time.Time `json:"created"` Username string `json:"username"` // Deprecated use Username instead Peername string `json:"peername,omitempty"` Email string `json:"email"` Password string `json:",omitempty"` Photo string `json:"photo"` Thumb string `json:"thumb"` Name string `json:"name"` Description string `json:"description"` HomeURL string `json:"homeurl"` Twitter string `json:"twitter"` ProfileID string `json:"profileid"` PublicKey string `json:"publickey"` Signature string `json:"signature"` }
Profile is a shorthand version of qri-io/qri/repo/profile.Profile TODO (b5) - this should be refactored to embed a config.Profile, add password & key fields
func ProfileFromPrivateKey ¶
ProfileFromPrivateKey generates a profile struct from a private key & desired profile handle It adds all the necessary components to pass profiles.Register, creating base64-encoded PublicKey & Signature, and base58-encoded ProfileID
type Profiles ¶
type Profiles interface { // Len returns the number of records in the set Len() (int, error) // Load fetches a profile from the list by key Load(key string) (value *Profile, err error) // Range calls an iteration fuction on each element in the map until // the end of the list is reached or iter returns true Range(iter func(key string, p *Profile) (kontinue bool, err error)) error // SortedRange is like range but with deterministic key ordering SortedRange(iter func(key string, p *Profile) (kontinue bool, err error)) error // Create adds an entry, bypassing the register process // store is only exported for administrative use cases. // most of the time callers should use Register instead Create(key string, value *Profile) error // Update modifies an existing profile Update(key string, value *Profile) error // Delete removes a profile from the set at key // Delete is only exported for administrative use cases. // most of the time callers should use Deregister instead Delete(key string) error }
Profiles is the interface for working with a set of *Profile's Register, Deregister, Load, Len, Range, and SortedRange should be considered safe to hook up to public http endpoints, whereas Delete & Store should only be exposed in administrative contexts users should prefer using RegisterProfile & DegristerProfile for dataset manipulation operations
type Registry ¶
type Registry struct { Profiles Profiles Reputations Reputations Search Searchable Indexer Indexer }
Registry a collection of interfaces that together form a registry service
type Reputation ¶
Reputation is record of the peers reputation on the network TODO: this is a stub that can and should be expanded
func NewReputation ¶
func NewReputation(id string) *Reputation
NewReputation creates a new reputation. Reputations start at 1 for now REPUTATIONS MUST BE NON-ZERO NUMBERS
func (*Reputation) Reputation ¶
func (r *Reputation) Reputation() int
Reputation gets the rep of a given Reputation
func (*Reputation) SetReputation ¶
func (r *Reputation) SetReputation(reputation int)
SetReputation sets the reputation of a given Reputation
func (*Reputation) Validate ¶
func (r *Reputation) Validate() error
Validate is a sanity check that all required values are present
type ReputationResponse ¶
type ReputationResponse struct { Reputation *Reputation Expiration time.Duration }
ReputationResponse is the result of a request for a reputation
type Reputations ¶
type Reputations interface { // Len returns the number of records in the set Len() int // Load fetches a profile from the list by key Load(key string) (value *Reputation, ok bool) // Range calls an iteration fuction on each element in the map until // the end of the list is reached or iter returns true Range(iter func(key string, r *Reputation) (brk bool)) // SortedRange is like range but with deterministic key ordering SortedRange(iter func(key string, r *Reputation) (brk bool)) // Add adds the Reputation to the list of reputations Add(r *Reputation) error // Store adds an entry, bypassing the register process // store is only exported for administrative use cases. // most of the time callers should use Register instead Store(key string, value *Reputation) // Delete removes a record from the set at key // Delete is only exported for administrative use cases. // most of the time callers should use Deregister instead Delete(key string) }
Reputations is the interface for working with a set of *Reputation's Add, Load, Len, Range, and SortedRange should be considered safe to hook up to public http endpoints, whereas Delete & Store should only be exposed in administrative contexts
type SearchParams ¶
SearchParams encapsulates parameters provided to Searchable.Search
type Searchable ¶
type Searchable interface {
Search(p SearchParams) ([]*dataset.Dataset, error)
}
Searchable is an opt-in interface for registries that wish to support search
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package regclient defines a client for interacting with a registry server
|
Package regclient defines a client for interacting with a registry server |
Package regserver is a wrapper around the handlers package, turning it into a proper http server
|
Package regserver is a wrapper around the handlers package, turning it into a proper http server |
handlers
Package handlers creates HTTP handler functions for registry interface implementations
|
Package handlers creates HTTP handler functions for registry interface implementations |
mock
Package mock provides a mock registry server for testing purposes it mocks the behaviour of a registry server with in-memory storage
|
Package mock provides a mock registry server for testing purposes it mocks the behaviour of a registry server with in-memory storage |