registry

package
v0.9.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2020 License: GPL-3.0 Imports: 10 Imported by: 1

README

Registry

Qri GoDoc License Codecov CI

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. Consider this package testiment that nothing is absolute.

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.

Long term, we intended to implement a distributed hash table (DHT) to make it possible to operate fully-decentralized, and provide registry support as a configurable detail.

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

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

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var ErrSearchNotSupported = fmt.Errorf("search not supported")

ErrSearchNotSupported is the canonical error to indicate search isn't implemented

Functions

func DeregisterProfile

func DeregisterProfile(store Profiles, p *Profile) error

DeregisterProfile removes a profile from the registry if it exists confirming the user has the authority to do so

func RegisterProfile

func RegisterProfile(store Profiles, p *Profile) (err error)

RegisterProfile adds a profile to the list if it's valid and the desired handle isn't taken

func UpdateProfile

func UpdateProfile(store Profiles, p *Profile) (err error)

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

type MemProfiles struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (*MemProfiles) Update

func (ps *MemProfiles) Update(key string, value *Profile) error

Update modifies an existing profile

type MockSearch

type MockSearch struct {
	Datasets []*dataset.Dataset
}

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

func (NilSearch) Search

func (ns NilSearch) Search(p SearchParams) ([]*dataset.Dataset, error)

Search returns an error indicating 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

func ProfileFromPrivateKey(p *Profile, privKey crypto.PrivKey) (*Profile, error)

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

func (*Profile) Validate

func (p *Profile) Validate() error

Validate is a sanity check that all required values are present

func (*Profile) Verify

func (p *Profile) Verify() error

Verify checks a profile's proof of key ownership Registree's must prove they have control of the private key by signing the desired handle, which is validated with a provided public key. Public key, handle, and date of

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 {
	Remote   *remote.Remote
	Profiles Profiles
	Search   Searchable
	Indexer  Indexer
}

Registry a collection of interfaces that together form a registry service

type SearchParams

type SearchParams struct {
	Q             string
	Limit, Offset int
}

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

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 provides a mock registry server for testing purposes
Package regserver provides a mock registry server for testing purposes
handlers
Package handlers creates HTTP handler functions for registry interface implementations
Package handlers creates HTTP handler functions for registry interface implementations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL