user

package
v0.1.3-0...-3c80581 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 15 Imported by: 0

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 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.

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 gives the type of failure (unless user.StatusOK), and the result.Err has more specific details about the failure.

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 VerifyContent

func VerifyContent(b []byte, result *Result, kid keys.ID) (Status, error)

VerifyContent checks 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 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 Verify

func Verify(msg string, kid keys.ID, user *User) (*User, error)

Verify armored message for a user. If user is specified, we will verify it matches the User in the verified message.

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

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

Users keeps track of sigchain user links.

func NewUsers

func NewUsers(ds docs.Documents, scs *keys.Sigchains, req request.Requestor, clock tsutil.Clock) *Users

NewUsers creates Users.

func (*Users) CheckForExisting

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

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

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

func (*Users) Expired

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

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

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

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

KIDs returns all key ids in the user store.

func (*Users) RequestVerify

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

RequestVerify a user. Doesn't index result.

func (*Users) Requestor

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

Requestor ...

func (*Users) Search

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

Search for users.

func (*Users) Status

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

Status returns KIDs that match a status.

func (*Users) Update

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

Update index for sigchain KID.

func (*Users) User

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.

Jump to

Keyboard shortcuts

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