Documentation
¶
Overview ¶
Package storage defines the persistence interface the Inkless service uses and a registry of drivers selected by URL scheme. Drivers register themselves from init, as database/sql drivers do; import them for their side effect (for example storage/sqlite).
Drivers must implement optimistic concurrency: updates of requests, sessions, challenges and webhook deliveries succeed only when the stored version (or the stated previous value) is unchanged, and fail with ErrConflict otherwise. Uniqueness of ids, event sequence numbers and idempotency keys comes from unique constraints.
Index ¶
Constants ¶
const DefaultURL = "sqlite:inkless.db"
DefaultURL is used when no database URL is configured.
Variables ¶
var ( // ErrNotFound is returned when a looked-up record does not exist. ErrNotFound = errors.New("storage: not found") // ErrConflict means a concurrent change won; the caller retries the // whole transaction. ErrConflict = errors.New("storage: conflict") )
Functions ¶
Types ¶
type Application ¶
type Idempotency ¶
type Opener ¶
Opener opens a store from a URL whose scheme selected the driver. It creates or migrates the schema as needed.
type Request ¶
type Request struct {
ID string
ApplicationID string
DocumentID string
State string
Routing string
Assurance string
ConsentVersion string
Locale string
ExpiresAt time.Time
ExternalRef string
Metadata []byte
Sequence int64
LastHash string
RevokeReason string
CreatedAt time.Time
UpdatedAt time.Time
IssuedAt *time.Time
EndedAt *time.Time
// Signers are ordered by (Order, Ref).
Signers []Signer
Version int64
}
type Session ¶
type Session struct {
ID string
TokenHash []byte
RequestID string
SignerRef string
Assertion []byte
ReturnURL string
Nonce string
CreatedAt time.Time
LinkExpiresAt time.Time
OpenedAt *time.Time
BrowserHash []byte
CeremonyExpiresAt *time.Time
IP string
UserAgent string
CodeSends int
Outcome string
OutcomeAt *time.Time
Version int64
}
type Store ¶
type Store interface {
// Tx runs fn in one transaction and commits when fn returns nil.
// Every read and write happens through a Tx. Calls must not nest.
Tx(ctx context.Context, fn func(Tx) error) error
Close() error
}
Store is a database holding Inkless state.
type Tx ¶
type Tx interface {
InsertApplication(ctx context.Context, a Application) error
Application(ctx context.Context, id string) (*Application, error)
Applications(ctx context.Context) ([]Application, error)
UpdateApplication(ctx context.Context, a Application) error
InsertAPIKey(ctx context.Context, k APIKey) error
// APIKeyApplication returns the application of an unrevoked key hash.
APIKeyApplication(ctx context.Context, hash []byte) (string, error)
RevokeAPIKeys(ctx context.Context, appID string, at time.Time) error
InsertWebhookSecret(ctx context.Context, s WebhookSecret) error
// WebhookSecrets returns the application's secrets that have not expired
// at now, oldest first.
WebhookSecrets(ctx context.Context, appID string, now time.Time) ([]WebhookSecret, error)
ExpireWebhookSecrets(ctx context.Context, appID string, at time.Time) error
InsertDocument(ctx context.Context, d Document, content []byte) error
Document(ctx context.Context, id string) (*Document, error)
DocumentContent(ctx context.Context, id string) ([]byte, error)
// InsertRequest stores a request and its signers with Version 1.
InsertRequest(ctx context.Context, r *Request) error
Request(ctx context.Context, id string) (*Request, error)
// UpdateRequest writes r and its signers' mutable fields if the stored
// version equals r.Version, then increments r.Version.
UpdateRequest(ctx context.Context, r *Request) error
// ListRequests returns ids of the application's requests ordered by
// (UpdatedAt, ID) strictly after (after, afterID).
ListRequests(ctx context.Context, appID string, after time.Time, afterID string, limit int) ([]string, error)
// OverdueRequests returns ids of issued or partially signed requests
// whose ExpiresAt is not after now.
OverdueRequests(ctx context.Context, now time.Time, limit int) ([]string, error)
// UnsealedRequests returns ids of completed requests without artifacts.
UnsealedRequests(ctx context.Context, limit int) ([]string, error)
InsertEvents(ctx context.Context, events []Event) error
// Events returns a request's events in sequence order.
Events(ctx context.Context, requestID string) ([]Event, error)
InsertDeliveries(ctx context.Context, ds []Delivery) error
// DueDeliveries returns pending deliveries with NextAttemptAt not after
// now that are first in sequence among their request's pending
// deliveries; request.completed only once the request has artifacts.
DueDeliveries(ctx context.Context, now time.Time, limit int) ([]Delivery, error)
// UpdateDelivery writes d if it is still pending and its stored
// NextAttemptAt equals prevNextAttempt.
UpdateDelivery(ctx context.Context, d *Delivery, prevNextAttempt time.Time) error
FailedDeliveries(ctx context.Context, appID string, limit int) ([]Delivery, error)
InsertSession(ctx context.Context, s *Session) error
SessionByToken(ctx context.Context, tokenHash []byte) (*Session, error)
SessionByBrowser(ctx context.Context, browserHash []byte) (*Session, error)
// UpdateSession writes s if the stored version equals s.Version, then
// increments s.Version.
UpdateSession(ctx context.Context, s *Session) error
InsertChallenge(ctx context.Context, c *Challenge) error
// LatestChallenge returns the session's most recent challenge.
LatestChallenge(ctx context.Context, sessionID string) (*Challenge, error)
// UpdateChallenge writes c if the stored version equals c.Version, then
// increments c.Version.
UpdateChallenge(ctx context.Context, c *Challenge) error
// InsertIdempotency stores k unless the (AppID, Key) pair exists, and
// reports whether it was inserted.
InsertIdempotency(ctx context.Context, k Idempotency) (bool, error)
Idempotency(ctx context.Context, appID, key string) (*Idempotency, error)
CompleteIdempotency(ctx context.Context, appID, key string, status int, response []byte) error
DeleteIdempotency(ctx context.Context, appID, key string) error
PruneIdempotency(ctx context.Context, before time.Time) error
// InsertArtifacts stores a's files unless the request already has
// artifacts, which are kept.
InsertArtifacts(ctx context.Context, a Artifacts) error
Artifacts(ctx context.Context, requestID string) (*Artifacts, error)
HasArtifacts(ctx context.Context, requestID string) (bool, error)
// Setting returns a named service setting, such as the server secret
// or published key material.
Setting(ctx context.Context, name string) ([]byte, error)
// InsertSetting stores value unless name exists, and reports whether
// it was inserted.
InsertSetting(ctx context.Context, name string, value []byte) (bool, error)
// PutSetting stores value, replacing any existing one.
PutSetting(ctx context.Context, name string, value []byte) error
}
Tx is the set of operations available inside a transaction. Methods returning a single record return ErrNotFound when it does not exist.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mysql registers the storage driver for mysql://user:password@host:port/database URLs, using go-sql-driver/mysql.
|
Package mysql registers the storage driver for mysql://user:password@host:port/database URLs, using go-sql-driver/mysql. |
|
Package postgres registers the storage driver for postgres:// and postgresql:// URLs, using pgx.
|
Package postgres registers the storage driver for postgres:// and postgresql:// URLs, using pgx. |
|
Package sqlite registers the default storage driver for URLs of the form sqlite:PATH (sqlite:inkless.db, sqlite:///var/lib/inkless.db).
|
Package sqlite registers the default storage driver for URLs of the form sqlite:PATH (sqlite:inkless.db, sqlite:///var/lib/inkless.db). |
|
Package sqlstore implements storage.Store on database/sql.
|
Package sqlstore implements storage.Store on database/sql. |
|
Package storagetest is the conformance suite for storage drivers.
|
Package storagetest is the conformance suite for storage drivers. |