user

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 14 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.

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

func (*Result) Update added in v0.1.6

func (r *Result) Update(ctx context.Context, req request.Requestor, now time.Time)

Update result using Requestor.

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

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) RequestVerify added in v0.1.6

func (u *User) RequestVerify(ctx context.Context, opt ...VerifyOption) *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 (*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.

func (*User) Verify added in v0.1.6

func (u *User) Verify(msg string) error

Verify verifies a saltpack armored message for a user. The message should have come from the User URL and part of a verified sigchain statement with matching sequence number.

type VerifyOption added in v0.1.6

type VerifyOption func(*VerifyOptions)

VerifyOption ...

func Clock added in v0.1.4

func Clock(clock tsutil.Clock) VerifyOption

Clock ...

func Requestor added in v0.1.4

func Requestor(req request.Requestor) VerifyOption

Requestor ...

type VerifyOptions added in v0.1.6

type VerifyOptions struct {
	Requestor request.Requestor
	Clock     tsutil.Clock
}

VerifyOptions ...

Jump to

Keyboard shortcuts

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