profile

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package profile defines a qri peer profile

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is the not found err for the profile package
	ErrNotFound = fmt.Errorf("profile: not found")
	// ErrAmbiguousUsername occurs when more than one username is the same in a
	// context that requires exactly one user. More information is needed to
	// disambiguate which username is correct
	ErrAmbiguousUsername = fmt.Errorf("ambiguous username")
)

Functions

This section is empty.

Types

type Author

type Author interface {
	AuthorID() string
	AuthorPubKey() crypto.PubKey
	Username() string
}

Author uses keypair cryptography to distinguish between different log sources (authors)

Deprecated - don't rely on this interface, refactor to use profile.Profiles and public keys instead

func NewAuthor

func NewAuthor(id string, pubKey crypto.PubKey, username string) Author

NewAuthor creates an Author interface implementation, allowing outside packages needing to satisfy the Author interface

Deprecated - use profile.Profile instead

type ID

type ID peer.ID

ID is a distinct thing form a peer.ID. They are *NOT* meant to be interchangable but the mechanics of peer.ID & profile.ID are exactly the same

func IDB58Decode

func IDB58Decode(proid string) (ID, error)

IDB58Decode proxies a lower level API b/c I'm lazy & don't like

func IDB58DecodeOrEmpty

func IDB58DecodeOrEmpty(proid string) ID

IDB58DecodeOrEmpty decodes an ID, or returns an empty ID if decoding fails

func IDB58MustDecode

func IDB58MustDecode(proid string) ID

IDB58MustDecode panics if an ID doesn't decode. useful for testing

func IDFromPeerID

func IDFromPeerID(pid peer.ID) ID

IDFromPeerID type casts a peer.ID from ipfs into an ID

func IDRawByteString

func IDRawByteString(data string) ID

IDRawByteString constructs an ID from a raw byte string. No decoding happens. Should only be used in tests

func NewB58ID

func NewB58ID(pid string) (ID, error)

NewB58ID creates a peer.ID from a base58-encoded string

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ID

func (*ID) MarshalYAML

func (id *ID) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for ID

func (ID) String

func (id ID) String() string

String implements the stringer interface for ID

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface for ID

func (*ID) UnmarshalYAML

func (id *ID) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

UnmarshalYAML implements the yaml.Unmarshaler interface for ID

func (ID) Validate

func (id ID) Validate() error

Validate exposes the validation interface for ID

type LocalStore

type LocalStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LocalStore is an on-disk json file implementation of the repo.Peers interface

func (*LocalStore) Active

func (r *LocalStore) Active(ctx context.Context) *Profile

Active is the curernt active profile

func (*LocalStore) DeleteProfile

func (r *LocalStore) DeleteProfile(id ID) error

DeleteProfile removes a profile from the store

func (*LocalStore) GetProfile

func (r *LocalStore) GetProfile(id ID) (*Profile, error)

GetProfile fetches a profile from the store

func (*LocalStore) List

func (r *LocalStore) List() (map[ID]*Profile, error)

List hands back the list of peers

func (*LocalStore) Owner

func (r *LocalStore) Owner() *Profile

Owner accesses the current owner user profile

func (*LocalStore) PeerIDs

func (r *LocalStore) PeerIDs(id ID) ([]peer.ID, error)

PeerIDs gives the peer.IDs list for a given peername

func (*LocalStore) PeerProfile

func (r *LocalStore) PeerProfile(id peer.ID) (*Profile, error)

PeerProfile gives the profile that corresponds with a given peer.ID

func (*LocalStore) PeernameID

func (r *LocalStore) PeernameID(peername string) (ID, error)

PeernameID gives the ID for a given peername

func (*LocalStore) ProfilesForUsername

func (r *LocalStore) ProfilesForUsername(username string) ([]*Profile, error)

ProfilesForUsername fetches all profile that match a username (Peername)

func (*LocalStore) PutProfile

func (r *LocalStore) PutProfile(p *Profile) error

PutProfile adds a peer to the store

func (*LocalStore) SetOwner

func (r *LocalStore) SetOwner(own *Profile) error

SetOwner updates the owner profile

type MemStore

type MemStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MemStore is an in-memory implementation of the profile Store interface

func (*MemStore) Active

func (m *MemStore) Active(ctx context.Context) *Profile

Active is the curernt active profile

func (*MemStore) DeleteProfile

func (m *MemStore) DeleteProfile(id ID) error

DeleteProfile removes a peer from this store

func (*MemStore) GetProfile

func (m *MemStore) GetProfile(id ID) (*Profile, error)

GetProfile give's peer info from the store for a given peer.ID

func (*MemStore) List

func (m *MemStore) List() (map[ID]*Profile, error)

List hands the full list of peers back

func (*MemStore) Owner

func (m *MemStore) Owner() *Profile

Owner accesses the current owner user profile

func (*MemStore) PeerIDs

func (m *MemStore) PeerIDs(id ID) ([]peer.ID, error)

PeerIDs gives the peer.IDs list for a given peername

func (*MemStore) PeerProfile

func (m *MemStore) PeerProfile(id peer.ID) (*Profile, error)

PeerProfile returns profile data for a given peer.ID TODO - this func implies that peer.ID's are only ever connected to the same profile. That could cause trouble.

func (*MemStore) PeernameID

func (m *MemStore) PeernameID(peername string) (ID, error)

PeernameID gives the ID for a given peername

func (*MemStore) ProfilesForUsername

func (m *MemStore) ProfilesForUsername(username string) ([]*Profile, error)

ProfilesForUsername fetches all profile that match a username (Peername)

func (*MemStore) PutProfile

func (m *MemStore) PutProfile(p *Profile) error

PutProfile adds a peer to this store

func (*MemStore) SetOwner

func (m *MemStore) SetOwner(own *Profile) error

SetOwner updates the owner profile

type Profile

type Profile struct {
	// All Profiles are built on public key infrastructure
	// PrivKey is the peer's private key, should only be present for the current peer
	PrivKey crypto.PrivKey `json:"_,omitempty"`
	// PubKey is the peer's public key
	PubKey crypto.PubKey `json:"key,omitempty"`
	// KeyID is the key identifier used for the keystore
	KeyID key.ID `json:"key_id,omitempty"`

	ID ID `json:"id"`
	// Created timestamp
	Created time.Time `json:"created,omitempty"`
	// Updated timestamp
	Updated time.Time `json:"updated,omitempty"`
	// Peername a handle for the user. min 1 character, max 80. composed of [_,-,a-z,A-Z,1-9]
	Peername string `json:"peername"`
	// specifies weather this is a user or an organization
	Type Type `json:"type"`
	// user's email address
	Email string `json:"email"`
	// user name field. could be first[space]last, but not strictly enforced
	Name string `json:"name"`
	// user-filled description of self
	Description string `json:"description"`
	// url this user wants the world to click
	HomeURL string `json:"homeUrl"`
	// color this user likes to use as their theme color
	Color string `json:"color"`
	// Thumb path for user's thumbnail
	Thumb string `json:"thumb"`
	// Profile photo
	Photo string `json:"photo"`
	// Poster photo for users's profile page
	Poster string `json:"poster"`
	// Twitter is a  peer's twitter handle
	Twitter string `json:"twitter"`
	// Online indicates if this peer is currently connected to the network
	Online bool `json:"online,omitempty"`

	// PeerIDs lists any network PeerIDs associated with this profile
	// in the form /network/peerID
	PeerIDs []peer.ID `json:"peerIDs"`
	// NetworkAddrs keeps a list of locations for this profile on the network as multiaddr strings
	NetworkAddrs []ma.Multiaddr `json:"networkAddrs,omitempty"`
}

Profile defines peer profile details

func NewProfile

func NewProfile(p *config.ProfilePod) (pro *Profile, err error)

NewProfile allocates a profile from a CodingProfile

func ResolveUsername

func ResolveUsername(s Store, username string) (*Profile, error)

ResolveUsername finds a single profile for a given username from a store of usernames. Errors if the store contains more than one user with the given username

func (*Profile) Decode

func (p *Profile) Decode(sp *config.ProfilePod) error

Decode turns a ProfilePod into a profile.Profile

func (Profile) Encode

func (p Profile) Encode() (*config.ProfilePod, error)

Encode returns a ProfilePod for a given profile

func (*Profile) GetKeyID

func (p *Profile) GetKeyID() key.ID

GetKeyID returns a KeyID assigned to the profile or falls back to the profile ID if none is present

func (*Profile) ValidOwnerProfile

func (p *Profile) ValidOwnerProfile() error

ValidOwnerProfile checks if a profile can be used as an owner profile

type Store

type Store interface {
	// Owner is a single profile that represents the current user
	Owner() *Profile
	// SetOwner handles updates to the current user profile at runtime
	SetOwner(own *Profile) error
	// Active is the active profile that represents the current user
	Active(ctx context.Context) *Profile

	// put a profile in the store
	PutProfile(profile *Profile) error
	// get a profile by ID
	GetProfile(id ID) (*Profile, error)
	// remove a profile from the store
	DeleteProfile(id ID) error

	// get all profiles who's .Peername field matches a given username. It's
	// possible to have multiple profiles with the same username
	ProfilesForUsername(username string) ([]*Profile, error)
	// list all profiles in the store, keyed by ID
	// Deprecated - don't add new callers to this. We should replace this with
	// a better batch accessor
	List() (map[ID]*Profile, error)
	// get a set of peer ids for a given profile ID
	PeerIDs(id ID) ([]peer.ID, error)
	// get a profile for a given peer Identifier
	PeerProfile(id peer.ID) (*Profile, error)
	// get the profile ID for a given peername
	// Depcreated - use GetProfile instead
	PeernameID(peername string) (ID, error)
}

Store is a store of profile information. Stores are owned by a single profile that must have an associated private key

func NewLocalStore

func NewLocalStore(filename string, owner *Profile, ks key.Store) (Store, error)

NewLocalStore allocates a LocalStore

func NewMemStore

func NewMemStore(owner *Profile, ks key.Store) (Store, error)

NewMemStore allocates a MemStore

func NewStore

func NewStore(cfg *config.Config, keyStore key.Store) (Store, error)

NewStore creates a profile store from configuration

type Type

type Type int

Type enumerates different types of peers

const (
	// TypePeer is a single person
	TypePeer Type = iota
	// TypeOrganization represents a group of people
	TypeOrganization
)

func ParseType

func ParseType(t string) (Type, error)

ParseType decodes a peer type from a string

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Type

func (Type) String

func (t Type) String() string

String implements the Stringer interface for Type

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface for Type

Jump to

Keyboard shortcuts

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