Documentation
¶
Overview ¶
Package uploadsessions is a records plugin that keeps upload sessions (upload.Session, UP-15) in the database: the SessionStore to use when sessions must survive a restart or be shared by several instances behind a load balancer. upload.Sessions does every check (the secret, the expiry by its own clock, the limits against the endpoint's policy); this store only keeps the rows, never a token's secret, only its SHA-256.
p := uploadsessions.New()
store, _ := records.New(db, dialect, disks, records.WithPlugins(p))
sessions, _ := upload.NewSessions(p.Store(store), upload.SessionsOptions{})
Schedule sessions.Sweep (the library starts no background work); an expired session is refused whether or not it was swept.
Index ¶
- Constants
- Variables
- type Plugin
- type Store
- func (st Store) DeleteSession(ctx context.Context, id string) error
- func (st Store) LoadSession(ctx context.Context, id string) (upload.Session, error)
- func (st Store) SaveSession(ctx context.Context, sess upload.Session) error
- func (st Store) SweepSessions(ctx context.Context, now time.Time) (int, error)
Constants ¶
const ( ColID = "id" ColSecretHash = "secret_hash" ColKey = "storage_key" ColPrefix = "prefix" ColMaxSize = "max_size" ColAllowed = "allowed" ColCreatedAt = "created_at" ColExpiresAt = "expires_at" )
Column names of fs_upload_sessions.
const PluginName = "uploadsessions"
PluginName is the plugin's name in the migration ledger.
const TableNameSessions = "fs_upload_sessions"
TableNameSessions is the table the plugin owns: one row per session.
Variables ¶
var ( Table = sqlb.Table{Name: TableNameSessions, Alias: "us"} ID = sqlb.Col[string](Table, ColID) SecretHash = sqlb.Col[string](Table, ColSecretHash) // Key and Prefix: exactly one is set ("" for the other), as in // upload.Session. Key = sqlb.Col[string](Table, ColKey) Prefix = sqlb.Col[string](Table, ColPrefix) MaxSize = sqlb.Col[int64](Table, ColMaxSize) // Allowed is the session's type patterns as a JSON array, "[]" or // "null" for none (the policy's types). Allowed = sqlb.Col[string](Table, ColAllowed) CreatedAt = sqlb.Col[time.Time](Table, ColCreatedAt) ExpiresAt = sqlb.Col[time.Time](Table, ColExpiresAt) )
Table and typed columns.
Functions ¶
This section is empty.
Types ¶
type Plugin ¶
type Plugin struct{}
Plugin owns the sessions table. Construct it with New, install it with records.WithPlugins, and get the SessionStore with Store.
func (*Plugin) Migrations ¶
Migrations implements records.Migrator.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an upload.SessionStore in the records database. Statements join the transaction in ctx, if any (records.Store.Tx).
func (Store) DeleteSession ¶
DeleteSession implements upload.SessionStore.
func (Store) LoadSession ¶
LoadSession implements upload.SessionStore: CodeNotFound when there is no session with id.
func (Store) SaveSession ¶
SaveSession implements upload.SessionStore. An ID already present is CodeExists.