Documentation ¶
Overview ¶
Package user defines user statements, store and search.
Index ¶
- Variables
- func NewSigchainStatement(sc *keys.Sigchain, user *User, sk *keys.EdX25519Key, ts time.Time) (*keys.Statement, error)
- func SetLogger(l Logger)
- func Validate(user *User) error
- func ValidateStatement(st *keys.Statement) error
- type ContextLogger
- type LogLevel
- type Logger
- type Result
- type SearchRequest
- type SearchResult
- type Status
- type User
- type Users
- func (u *Users) CheckForExisting(ctx context.Context, sc *keys.Sigchain) (keys.ID, error)
- func (u *Users) CheckSigchain(ctx context.Context, sc *keys.Sigchain) (*Result, error)
- func (u *Users) Expired(ctx context.Context, dt time.Duration, maxAge time.Duration) ([]keys.ID, error)
- func (u *Users) Find(ctx context.Context, kid keys.ID) (*Result, error)
- func (u *Users) Get(ctx context.Context, kid keys.ID) (*Result, error)
- func (u *Users) KIDs(ctx context.Context) ([]keys.ID, error)
- func (u *Users) RequestVerify(ctx context.Context, usr *User) *Result
- func (u *Users) Requestor() request.Requestor
- func (u *Users) Search(ctx context.Context, req *SearchRequest) ([]*SearchResult, error)
- func (u *Users) Status(ctx context.Context, st Status) ([]keys.ID, error)
- func (u *Users) Update(ctx context.Context, kid keys.ID) (*Result, error)
- func (u *Users) User(ctx context.Context, user string) (*Result, error)
Constants ¶
This section is empty.
Variables ¶
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 Validate ¶
Validate service and name and URL. If you want to request the URL and verify the remote statement, use RequestVerify.
func ValidateStatement ¶
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.
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.
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 ¶
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 ¶
IsTimestampExpired returns true if result Timestamp is older than dt.
func (Result) IsVerifyExpired ¶
IsVerifyExpired returns true if result VerifiedAt is older than dt.
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" )
type User ¶
User describes a name on a service with a signed statement at a URL, signed into a sigchain at (KID, seq).
func FindInSigchain ¶
FindInSigchain returns User from a Sigchain. If user is invalid returns nil.
func NewForSigning ¶
NewForSigning returns User for signing (doesn't have remote URL yet). The name is normalized, for example for twitter "@Username" => "username".
func Verify ¶
Verify armored message for a user. If user is specified, we will verify it matches the User in the verified message.
func (User) MarshalJSON ¶
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) UnmarshalJSON ¶
UnmarshalJSON unmarshals a user from JSON.
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 ¶
CheckForExisting returns key ID of exsiting user in sigchain different from this sigchain key.
func (*Users) CheckSigchain ¶
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) Get ¶
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) RequestVerify ¶
RequestVerify a user. Doesn't index result.
func (*Users) Search ¶
func (u *Users) Search(ctx context.Context, req *SearchRequest) ([]*SearchResult, error)
Search for users.