user

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 16 Imported by: 4

Documentation

Overview

Package user defines user statements, store and search.

Index

Constants

This section is empty.

Variables

View Source
var ErrUserAlreadySet = errors.New("user set in sigchain already")

ErrUserAlreadySet is user already set in sigchain.

Functions

func MockStatement added in v0.1.5

func MockStatement(key *keys.EdX25519Key, sc *keys.Sigchain, name string, service string, req *request.MockRequestor, clock tsutil.Clock) (*keys.Statement, error)

MockStatement for testing.

func NewSigchainStatement

func NewSigchainStatement(sc *keys.Sigchain, user *User, sk *keys.EdX25519Key, ts time.Time) (*keys.Statement, error)

NewSigchainStatement for a user to add to a Sigchain. Returns ErrUserAlreadySet is user already exists in the Sigchain.

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

func Validate

func Validate(user *User) error

Validate service and name and URL. If you want to request the URL and verify the remote statement, use RequestVerify.

func ValidateStatement

func ValidateStatement(st *keys.Statement) error

ValidateStatement returns error if statement is not a valid user statement.

func Verify

func Verify(msg string, usr *User) error

Verify armored message for a user.

Types

type ContextLogger

type ContextLogger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

ContextLogger interface used in this package with request context.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

Logger interface used in this package.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

type Result

type Result struct {
	Err    string `json:"err,omitempty"`
	Status Status `json:"status"`
	// Timestamp is the when the status was last updated.
	Timestamp int64 `json:"ts"`
	User      *User `json:"user"`
	// VerifiedAt is when the status was last OK.
	VerifiedAt int64 `json:"vts"`
}

Result describes the status of a User. TODO: Make Err/Status more explicit, it can be confusing.

func RequestVerify

func RequestVerify(ctx context.Context, req request.Requestor, usr *User, now time.Time) *Result

RequestVerify requests a user URL and verifies it. The result.Status is success (StatusOK) or type of failure. If a failure, result.Err has the error message.

func (Result) IsTimestampExpired

func (r Result) IsTimestampExpired(now time.Time, dt time.Duration) bool

IsTimestampExpired returns true if result Timestamp is older than dt.

func (Result) IsVerifyExpired

func (r Result) IsVerifyExpired(now time.Time, dt time.Duration) bool

IsVerifyExpired returns true if result VerifiedAt is older than dt.

func (Result) String

func (r Result) String() string

type SearchRequest

type SearchRequest struct {
	// Query to search for.
	Query string
	// Limit number of results.
	Limit int
}

SearchRequest ...

type SearchResult

type SearchResult struct {
	KID    keys.ID
	Result *Result
	// Field we matched on (if not the user).
	Field string
}

SearchResult ...

type Status

type Status string

Status is the status of the user statement.

const (
	// StatusOK if user was found and verified.
	StatusOK Status = "ok"
	// StatusResourceNotFound if resource (URL) was not found.
	StatusResourceNotFound Status = "resource-not-found"
	// StatusContentNotFound if resource was found, but message was missing.
	StatusContentNotFound Status = "content-not-found"
	// StatusStatementInvalid if statement was found but was invalid.
	StatusStatementInvalid Status = "statement-invalid"
	// StatusContentInvalid if statement was valid, but other data was invalid.
	StatusContentInvalid Status = "content-invalid"

	// StatusConnFailure if there was a (possibly) temporary connection failure.
	// This could be:
	// - A connection error if not connected to the internet or unable to reach the service.
	// - A 5xx error on the server.
	// - A 4xx error except 404 (for example, 429 if rate limited).
	StatusConnFailure Status = "connection-fail"

	// StatusFailure is any other failure.
	StatusFailure Status = "fail"
	// StatusUnknown is unknown.
	StatusUnknown Status = "unknown"
)

func FindVerify added in v0.1.4

func FindVerify(b []byte, user *User) (Status, error)

FindVerify finds and verifies content.

type User

type User struct {
	Name    string
	KID     keys.ID
	Seq     int
	Service string
	URL     string
}

User describes a name on a service with a signed statement at a URL, signed into a sigchain at (KID, seq).

func FindInSigchain

func FindInSigchain(sc *keys.Sigchain) (*User, error)

FindInSigchain returns User from a Sigchain. If user is invalid returns nil.

func New

func New(kid keys.ID, service string, name string, urs string, seq int) (*User, error)

New creates a User. Name and URL string are NOT normalized.

func NewEcho added in v0.1.5

func NewEcho(sk *keys.EdX25519Key, name string, seq int) (*User, error)

NewEcho creates a signed user@echo (for testing).

func NewForSigning

func NewForSigning(kid keys.ID, service string, name string) (*User, error)

NewForSigning returns User for signing (doesn't have remote URL yet). The name is normalized, for example for twitter "@Username" => "username".

func (User) Bytes

func (u User) Bytes() ([]byte, error)

Bytes is a serialized User.

func (User) ID

func (u User) ID() string

ID is an identifier for a user, e.g. gabriel@github.

func (User) MarshalJSON

func (u User) MarshalJSON() ([]byte, error)

MarshalJSON marshals user to JSON.

func (*User) Sign

func (u *User) Sign(key *keys.EdX25519Key) (string, error)

Sign user into an armored message.

func (User) String

func (u User) String() string

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a user from JSON.

func (*User) Validate

func (u *User) Validate() error

Validate service and name and URL. If you want to request the URL and verify the remote statement, use RequestVerify.

type Users added in v0.1.2

type Users struct {
	// contains filtered or unexported fields
}

Users keeps track of sigchain user links.

func NewUsers added in v0.1.2

func NewUsers(ds docs.Documents, scs *keys.Sigchains, opt ...UsersOption) *Users

NewUsers creates Users.

func (*Users) CheckForExisting added in v0.1.2

func (u *Users) CheckForExisting(ctx context.Context, sc *keys.Sigchain) (keys.ID, error)

CheckForExisting returns key ID of exsiting user in sigchain different from this sigchain key.

func (*Users) CheckSigchain added in v0.1.2

func (u *Users) CheckSigchain(ctx context.Context, sc *keys.Sigchain) (*Result, error)

CheckSigchain looks for user in a Sigchain and creates a result or updates the current result.

func (*Users) Expired added in v0.1.2

func (u *Users) Expired(ctx context.Context, dt time.Duration, maxAge time.Duration) ([]keys.ID, error)

Expired returns KIDs that haven't been checked in a duration.

func (*Users) Find added in v0.1.2

func (u *Users) Find(ctx context.Context, kid keys.ID) (*Result, error)

Find user result for KID. Will also search for related keys.

func (*Users) Get added in v0.1.2

func (u *Users) Get(ctx context.Context, kid keys.ID) (*Result, error)

Get user result for KID. Retrieves cached result. If Update(kid) has not been called or there is no user statement, this will return nil.

func (*Users) KIDs added in v0.1.2

func (u *Users) KIDs(ctx context.Context) ([]keys.ID, error)

KIDs returns all key ids in the user store.

func (*Users) RequestVerify added in v0.1.2

func (u *Users) RequestVerify(ctx context.Context, usr *User) *Result

RequestVerify a user. Doesn't index result.

func (*Users) Requestor added in v0.1.2

func (u *Users) Requestor() request.Requestor

Requestor ...

func (*Users) Search added in v0.1.2

func (u *Users) Search(ctx context.Context, req *SearchRequest) ([]*SearchResult, error)

Search for users.

func (*Users) Status added in v0.1.2

func (u *Users) Status(ctx context.Context, st Status) ([]keys.ID, error)

Status returns KIDs that match a status.

func (*Users) Update added in v0.1.2

func (u *Users) Update(ctx context.Context, kid keys.ID) (*Result, error)

Update index for sigchain KID.

func (*Users) User added in v0.1.2

func (u *Users) User(ctx context.Context, user string) (*Result, error)

User result for user name@service. Retrieves cached result. If Update(kid) has not been called or there is no user statement, this will return nil.

type UsersOption added in v0.1.4

type UsersOption func(*UsersOptions)

UsersOption ...

func Clock added in v0.1.4

func Clock(clock tsutil.Clock) UsersOption

Clock to use.

func Requestor added in v0.1.4

func Requestor(req request.Requestor) UsersOption

Requestor to use.

type UsersOptions added in v0.1.4

type UsersOptions struct {
	Req   request.Requestor
	Clock tsutil.Clock
}

UsersOptions are options for Users.

Jump to

Keyboard shortcuts

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