Documentation
¶
Overview ¶
Package firestore stores single-use authentication ceremony state in Firestore in Datastore mode.
It exists so a deployment on Google Cloud with no relational database can run the passkey, OAuth, and OIDC ceremonies. Importing it publishes the ceremony kind; the client itself belongs to database/firestore, which this package reads from the request context:
import _ "github.com/shibukawa/popcornweb/database/firestore" import _ "github.com/shibukawa/popcornweb/authstate/firestore"
Nothing here sweeps expired records. Take decides expiry from the stored deadline, so correctness never waits for a deletion; removing the bytes is a TTL policy on the expires_at property, which a deployment applies to the kind it owns:
gcloud firestore fields ttls update expires_at --collection-group=popcornweb_authstate --enable-ttl
The sqlite adapter publishes Prune because a bounded DELETE is cheap there. Here the equivalent is a query over every ceremony record ever written, which costs more than the records it would remove.
Index ¶
Constants ¶
const DeclaredKind = "popcornweb_authstate"
DeclaredKind is the entity kind. A kind is intrinsic to the type rather than a deployment fact, so nothing maps it onto another name.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Kind is the entity kind. Empty means DeclaredKind.
Kind string
// Namespace separates the ceremonies of one protocol from another's within
// the one kind. It is required.
//
// It is part of the key rather than a Datastore namespace: a Datastore
// namespace is a tenancy dimension the deployment owns, and borrowing it
// for a protocol name would collide with the isolation the test runner and
// a multi-tenant deployment use it for.
Namespace string
// Now is injectable for tests.
Now func() time.Time
MaxKeyBytes int
MaxValueBytes int
}
Options configures a store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists expiring, single-use authentication state in Firestore.
It is a raw store: it works on already encoded payloads, so plugin/auth can open one for a ceremony type this package cannot name. NewStore puts the codec back on for a caller that has one.
func NewRawStore ¶
NewRawStore builds the store. It opens nothing: the client comes from the request context, installed by the database/firestore middleware. That is why it takes no client argument, unlike the sqlite adapter which takes a pool.
func (*Store) Put ¶
Put stores a value that has never been stored under this key, or whose previous record has already expired.
The uncontended case is one commit: Insert fails if the key is taken. Only an actual collision pays for the transaction, which is the one place a predicate over a stored value can run — there is no condition expression on this wire, so an expired record is replaced by reading it inside a transaction and deciding in Go.
func (*Store) Take ¶
Take removes a record and returns what it removed.
No commit returns a prior entity, so this is a transaction: read, queue the delete, commit. Two concurrent takes cannot both commit, and the loser re-runs, finds nothing, and reports the miss — which is the single-use guarantee the contract asks for.
A malformed, expired, or undecodable record stays consumed: it was single-use, and handing it back would be worse than losing it.