delivery

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package delivery holds the use cases of the delivery context: for now, moving an environment's ruleset version on when a write changes what its SDKs receive, and evaluating its ruleset for a context to explain what the context is served.

Index

Constants

View Source
const RulesetWait = 2 * time.Second

RulesetWait is how long a request waits for a ruleset its replica is loading before it is answered ErrRulesetUnavailable: an SDK holding a ruleset keeps it and retries, rather than wait on a load that may take up to its own bound. The load goes on for the requests after it.

View Source
const SDKRetryAfter = 2 * time.Second

SDKRetryAfter is how long an SDK is told to wait before retrying a request the server could not serve for now: long enough for a load or a lookup to finish, short enough that an SDK starting up is served within seconds.

Variables

View Source
var ErrNotFound = errors.New("delivery: not found")

ErrNotFound is what a store answers for an entity it does not hold.

View Source
var ErrRulesetUnavailable = apperrors.Unavailable("ruleset_unavailable",
	"this replica cannot load the environment's ruleset yet; try again").WithRetryAfter(SDKRetryAfter)

ErrRulesetUnavailable answers a ruleset this replica cannot load for now. An SDK keeps the ruleset it holds rather than receive an empty one.

View Source
var (
	// ErrSDKKeyNotFound answers a key the environment does not hold, or an
	// identifier that names none.
	ErrSDKKeyNotFound = apperrors.NotFound("not_found", "the environment has no SDK key with this identifier")
)

Functions

This section is empty.

Types

type AttributeDeclaration

type AttributeDeclaration struct {
	Project                workspace.ProjectID
	Key, Name, Description string
	Type                   workspace.AttributeType
	Request                governance.Request
}

AttributeDeclaration is an attribute to declare.

type AuditLog

type AuditLog interface {
	Record(ctx context.Context, e governance.Entry) error
}

AuditLog records the audit entry of a change, in the unit of work of the change.

type AuthenticateSDKKey

type AuthenticateSDKKey struct {
	// contains filtered or unexported fields
}

AuthenticateSDKKey authenticates the SDK key a request to the SDK API presents.

func NewAuthenticateSDKKey

func NewAuthenticateSDKKey(keys SDKKeyLookup, uses *SDKKeyUses, c clock.Clock) *AuthenticateSDKKey

NewAuthenticateSDKKey returns the handler, noting each accepted key's use in uses.

func (*AuthenticateSDKKey) Handle

func (h *AuthenticateSDKKey) Handle(ctx context.Context, value string) (delivery.SDKKey, error)

Handle returns the key whose value is presented: sdk_key_missing for no value; sdk_key_invalid for a malformed or unknown one, refused alike so a caller learns nothing about which keys exist; sdk_key_revoked or sdk_key_expired for a key that no longer works at the clock's time; and unavailable when the key cannot be looked up.

func (*AuthenticateSDKKey) HandleHeld added in v0.2.0

func (h *AuthenticateSDKKey) HandleHeld(value string) (key delivery.SDKKey, held bool, err error)

HandleHeld is Handle for a key the lookup holds in memory already: it judges the key whose value is presented as Handle does when the key is held, and reports held false, without looking anything up, for any other value, malformed or missing ones included. A caller refusing a client for now, such as one presenting too many malformed or unknown keys, still admits a key in use without making a lookup it means to spare.

type BumpRulesets

type BumpRulesets struct {
	// contains filtered or unexported fields
}

BumpRulesets is the one way a write marks the rulesets it changed: every handler whose write changes what an environment's SDKs receive calls it after the write, in the same unit of work, so the version moves exactly when the change commits.

A version is never reused, even after a failover or a restore that lost commits, because the next version is at least the application clock in milliseconds.

func NewBumpRulesets

func NewBumpRulesets(store RulesetVersions, c clock.Clock) *BumpRulesets

NewBumpRulesets returns the handler, numbering versions from c.

func (*BumpRulesets) Environment

func (h *BumpRulesets) Environment(ctx context.Context, environment workspace.EnvironmentID) error

Environment marks the ruleset of environment changed, for a write to what one environment carries, such as a flag's configuration there.

func (*BumpRulesets) Project

func (h *BumpRulesets) Project(ctx context.Context, project workspace.ProjectID) error

Project marks the ruleset of every environment of project changed, for a write to what every environment carries alike, such as a flag's variations or a segment's conditions.

type ConfiguredFlags

type ConfiguredFlags interface {
	// ProjectFlags returns every flag of project, archived ones included.
	ProjectFlags(ctx context.Context, project workspace.ProjectID) ([]flags.Flag, error)
	Segments(ctx context.Context, project workspace.ProjectID) ([]flags.Segment, error)
	// EnvironmentConfigurations returns every flag's configuration in
	// environment.
	EnvironmentConfigurations(ctx context.Context, environment workspace.EnvironmentID) ([]flags.Configuration, error)
	// ProjectExperiments returns every experiment of project, whatever its
	// status.
	ProjectExperiments(ctx context.Context, project workspace.ProjectID) ([]flags.ExperimentRef, error)
}

ConfiguredFlags reads a project's flags and segments and the flags' configurations in one environment.

type CreateSDKKey

type CreateSDKKey struct {
	// contains filtered or unexported fields
}

CreateSDKKey creates an SDK key for an environment.

func NewCreateSDKKey

func NewCreateSDKKey(d SDKKeyDeps) *CreateSDKKey

NewCreateSDKKey returns the handler.

func (*CreateSDKKey) Handle

Handle creates the key, unless its environment already holds the most active keys of its kind, and records sdk_key.created without its value.

type CreateSDKKeyCommand

type CreateSDKKeyCommand struct {
	Ref            SDKKeyRef
	Kind           delivery.SDKKeyKind
	Name           string
	AllowedOrigins []string
	Request        governance.Request
}

CreateSDKKeyCommand asks for a key of Kind in Ref's environment.

type CreatedSDKKey

type CreatedSDKKey struct {
	Key   SDKKeyState
	Value secret.String
}

CreatedSDKKey is a key just made, with its value, shown this once.

type Declarations

type Declarations interface {
	UnitTypes(ctx context.Context, project workspace.ProjectID) ([]workspace.UnitType, error)
	Attributes(ctx context.Context, project workspace.ProjectID) ([]workspace.Attribute, error)
}

Declarations reads a project's unit types and attributes.

type DeclareAttribute

type DeclareAttribute func(ctx context.Context, d AttributeDeclaration) (workspace.Attribute, error)

DeclareAttribute declares an attribute through the workspace context, as a member creating it would, audited as such.

type DeclareDiscoveredAttribute

type DeclareDiscoveredAttribute struct {
	// contains filtered or unexported fields
}

DeclareDiscoveredAttribute declares a discovered attribute.

func NewDeclareDiscoveredAttribute

func NewDeclareDiscoveredAttribute(tx Transactor, store DiscoveredAttributeEditor, declare DeclareAttribute) *DeclareDiscoveredAttribute

NewDeclareDiscoveredAttribute returns the handler.

func (*DeclareDiscoveredAttribute) Handle

Handle declares the discovered attribute of d's project keyed d.Key with d's type, named after its key unless d names it, and removes it from the discovered ones, in one unit of work; an attribute not listed is not_found.

type DiscoveredAttributeEditor

type DiscoveredAttributeEditor interface {
	// DiscoveredAttributeForUpdate returns the attribute of project keyed
	// key, locked until the unit of work ends, or ErrNotFound when there is
	// none it has not declared since.
	DiscoveredAttributeForUpdate(ctx context.Context, project workspace.ProjectID, key string) (delivery.DiscoveredAttribute, error)
	SaveDiscoveredAttribute(ctx context.Context, d delivery.DiscoveredAttribute) error
	DeleteDiscoveredAttribute(ctx context.Context, project workspace.ProjectID, key string) error
}

DiscoveredAttributeEditor changes one discovered attribute.

type DiscoveredAttributeLister

type DiscoveredAttributeLister interface {
	// ListedDiscoveredAttributes returns the attributes of project neither
	// dismissed nor declared since, by key.
	ListedDiscoveredAttributes(ctx context.Context, project workspace.ProjectID) ([]delivery.DiscoveredAttribute, error)
}

DiscoveredAttributeLister lists the discovered attributes a member sees.

type DiscoveredAttributeStore

type DiscoveredAttributeStore interface {
	// LockDiscoveredAttributes holds, until the unit of work ends, the
	// right to add discovered attributes to project.
	LockDiscoveredAttributes(ctx context.Context, project workspace.ProjectID) error
	// DeclaredKeys returns which of keys project declares, as an attribute
	// or a unit type.
	DeclaredKeys(ctx context.Context, project workspace.ProjectID, keys []string) (map[string]bool, error)
	// DiscoveredAttributes returns the stored attributes of project keyed
	// keys that it has not declared since, dismissed ones included.
	DiscoveredAttributes(ctx context.Context, project workspace.ProjectID, keys []string) ([]delivery.DiscoveredAttribute, error)
	// CountDiscoveredAttributes counts the stored attributes of project
	// that it has not declared since, dismissed ones included.
	CountDiscoveredAttributes(ctx context.Context, project workspace.ProjectID) (int, error)
	SaveDiscoveredAttribute(ctx context.Context, d delivery.DiscoveredAttribute) error
}

DiscoveredAttributeStore stores the attributes contexts carried that their project does not declare.

type Discoveries

type Discoveries struct {
	// contains filtered or unexported fields
}

Discoveries gathers the undeclared attributes evaluated contexts carry and writes them in rounds, so an evaluation never waits on a write and a key seen a thousand times a second costs one.

func NewDiscoveries

func NewDiscoveries(tx Transactor, store DiscoveredAttributeStore) *Discoveries

NewDiscoveries returns the replica's gatherer of discovered attributes.

func (*Discoveries) Dropped

func (d *Discoveries) Dropped() DiscoveryDrops

Dropped returns the sightings dropped since it was last asked, for the round's warning.

func (*Discoveries) Flush

func (d *Discoveries) Flush(ctx context.Context) error

Flush writes what was gathered since the last round, one unit of work per project. A project's sightings that cannot be written are dropped rather than retried, and counted as dropped: the next contexts carrying them are seen again. It returns the first failure.

func (*Discoveries) Note

func (d *Discoveries) Note(project workspace.ProjectID, at time.Time, observed []delivery.ObservedAttribute)

Note keeps the attributes a context of project carried at at for the next round, as far as the bounds allow. A key already held is merged whatever the bounds, since it takes no new place.

type DiscoveryDrops

type DiscoveryDrops struct {
	// QueueFull counts sightings that found every place of the queue taken.
	QueueFull int
	// ProjectFull counts sightings whose project held its share already.
	ProjectFull int
	// WriteFailed counts sightings held but lost because writing their
	// project's failed.
	WriteFailed int
}

DiscoveryDrops counts the sightings a replica dropped since the last round, by why.

func (DiscoveryDrops) Total

func (d DiscoveryDrops) Total() int

Total is how many sightings were dropped, whatever why.

type DismissDiscoveredAttribute

type DismissDiscoveredAttribute struct {
	// contains filtered or unexported fields
}

DismissDiscoveredAttribute hides a discovered attribute until it is seen with a new type.

func NewDismissDiscoveredAttribute

func NewDismissDiscoveredAttribute(tx Transactor, store DiscoveredAttributeEditor) *DismissDiscoveredAttribute

NewDismissDiscoveredAttribute returns the handler.

func (*DismissDiscoveredAttribute) Handle

Handle dismisses the discovered attribute of project keyed key, or answers not_found for one not listed.

type Draft

type Draft struct {
	Flag          string
	Configuration flags.ConfigurationInput
}

Draft is an unsaved configuration of the flag keyed Flag.

type Drafts

type Drafts interface {
	// Draft returns in as the configuration of project's flag keyed flag in
	// the environment keyed environment, or the refusal a replace would get.
	Draft(ctx context.Context, project workspace.ProjectID, flag, environment string, in flags.ConfigurationInput) (flags.Configuration, error)
}

Drafts checks an unsaved configuration of one flag, as the flags context would check replacing the saved one with it.

type Evaluate

type Evaluate struct {
	// contains filtered or unexported fields
}

Evaluate evaluates an environment's ruleset for a context, as its SDKs would, with the full reason of every result: the tester of the console.

func NewEvaluate

func NewEvaluate(d EvaluateDeps) *Evaluate

NewEvaluate returns the handler.

func (*Evaluate) Handle

func (h *Evaluate) Handle(ctx context.Context, q EvaluateQuery) (Evaluation, error)

Handle refuses an invalid context with invalid_context, then materializes the environment's ruleset from one snapshot, with the draft in place of its flag's configuration once checked, and evaluates it. It stores nothing, neither the draft nor an exposure; the context's undeclared attributes, key and type only, are noted as discovered.

type EvaluateDeps

type EvaluateDeps struct {
	Snapshots    Snapshotter
	Environments RulesetEnvironments
	Declarations Declarations
	Flags        ConfiguredFlags
	Drafts       Drafts
	// Discoveries gathers the undeclared attributes of the contexts
	// evaluated; nil records none.
	Discoveries *Discoveries
	Clock       clock.Clock
}

EvaluateDeps are what Evaluate runs on.

type EvaluateQuery

type EvaluateQuery struct {
	Project     workspace.ProjectID
	Environment string
	Context     eval.Context
	Flags       []string
	Draft       *Draft
}

EvaluateQuery is a context to evaluate in the environment keyed Environment of Project: every flag that is not archived, or those keyed by Flags when it is not nil, with Draft in place of its flag's saved configuration when it is not nil.

type EvaluateRemotely

type EvaluateRemotely struct {
	// contains filtered or unexported fields
}

EvaluateRemotely evaluates an environment's ruleset for a context an SDK posts, for an SDK that holds no ruleset: a client SDK, or a server SDK that prefers to ask.

func NewEvaluateRemotely

func NewEvaluateRemotely(rulesets Rulesets, discoveries *Discoveries, counts *RemoteEvaluationCounts, c clock.Clock) *EvaluateRemotely

NewEvaluateRemotely returns the handler, evaluating the rulesets this replica holds, noting the undeclared attributes of each context in discoveries and counting each evaluation in counts.

func (*EvaluateRemotely) Handle

Handle refuses a context over the limits with invalid_context, then evaluates the server ruleset of key's environment, private segments included, which never leaves the server: attributes typed against the declared ones, a flag asked for that the ruleset does not hold left out. A client key's results are masked so that it learns the values served and not how they were reached; a server key's carry the true reason. It records no exposure, an exposure being the SDK's explicit call; the context's undeclared attributes, key and type only, are noted as discovered, and the evaluations counted by their true reason, before the mask.

type Evaluation

type Evaluation struct {
	// RulesetVersion is the version of the saved ruleset, which a draft
	// does not move.
	RulesetVersion int64
	// Results are by flag key.
	Results map[string]delivery.Result
}

Evaluation is what the environment's ruleset served a context.

type InventoryDrops

type InventoryDrops struct {
	// QueueFull counts sightings of a new row that found every place of the
	// replica's queue taken.
	QueueFull int
	// KeyFull counts sightings of a new row whose key held
	// delivery.MaxInventoryRowsPerKey rows already.
	KeyFull int
	// WriteFailed counts sightings held but lost because writing their
	// key's failed.
	WriteFailed int
}

InventoryDrops counts the sightings a replica dropped since the last round, by why.

func (InventoryDrops) Total

func (d InventoryDrops) Total() int

Total is how many sightings were dropped, whatever why.

type InventoryStore

type InventoryStore interface {
	// LockSDKInventory holds, until the unit of work ends, the right to add
	// rows of key to the inventory.
	LockSDKInventory(ctx context.Context, key delivery.SDKKeyID) error
	// InventoryOfKey returns the identities of the rows key holds.
	InventoryOfKey(ctx context.Context, key delivery.SDKKeyID) ([]delivery.InventoryIdentity, error)
	// RecordInventory records a sighting of an SDK: a new row, or the row's
	// last time and ruleset version moved on, unless the row was seen less
	// than delivery.InventoryInterval before with the same ruleset version,
	// so replicas writing the same row coalesce.
	RecordInventory(ctx context.Context, s delivery.InventorySighting) error
	// Inventory returns the rows of environment, most recently seen first.
	Inventory(ctx context.Context, environment workspace.EnvironmentID) ([]delivery.InventoryRow, error)
	// PurgeInventory deletes the rows last seen before before and returns
	// how many.
	PurgeInventory(ctx context.Context, before time.Time) (int64, error)
}

InventoryStore stores the SDK inventory of each environment.

type ListDiscoveredAttributes

type ListDiscoveredAttributes struct {
	// contains filtered or unexported fields
}

ListDiscoveredAttributes answers a project's discovered attributes.

func NewListDiscoveredAttributes

func NewListDiscoveredAttributes(store DiscoveredAttributeLister) *ListDiscoveredAttributes

NewListDiscoveredAttributes returns the handler.

func (*ListDiscoveredAttributes) Handle

Handle returns the discovered attributes of project a member sees, by key.

type ListSDKInventory

type ListSDKInventory struct {
	// contains filtered or unexported fields
}

ListSDKInventory answers a member which SDKs use an environment.

func NewListSDKInventory

func NewListSDKInventory(environments RulesetEnvironments, store InventoryStore) *ListSDKInventory

NewListSDKInventory returns the handler.

func (*ListSDKInventory) Handle

func (h *ListSDKInventory) Handle(ctx context.Context, project workspace.ProjectID, environment string) ([]delivery.InventoryRow, error)

Handle returns the inventory of project's environment keyed environment, most recently seen first, or not_found for an environment the project does not have.

type ListSDKKeys

type ListSDKKeys struct {
	// contains filtered or unexported fields
}

ListSDKKeys answers an environment's SDK keys.

func NewListSDKKeys

func NewListSDKKeys(store SDKKeyStore, c clock.Clock) *ListSDKKeys

NewListSDKKeys returns the query.

func (*ListSDKKeys) Handle

func (h *ListSDKKeys) Handle(ctx context.Context, ref SDKKeyRef) ([]SDKKeyState, error)

Handle returns every key of ref's environment, the oldest first, each with its status now.

type MaterializeRuleset

type MaterializeRuleset struct {
	// contains filtered or unexported fields
}

MaterializeRuleset materializes an environment's ruleset from what is stored.

func NewMaterializeRuleset

func NewMaterializeRuleset(d MaterializeRulesetDeps) *MaterializeRuleset

NewMaterializeRuleset returns the handler.

func (*MaterializeRuleset) InUnitOfWork added in v0.2.0

func (h *MaterializeRuleset) InUnitOfWork(ctx context.Context, environment workspace.EnvironmentID) (Ruleset, error)

InUnitOfWork materializes the ruleset of environment as the unit of work ctx carries sees it, its own uncommitted writes included, which is what the write would serve once it commits; or ErrNotFound for an environment that does not exist there.

func (*MaterializeRuleset) Ruleset

func (h *MaterializeRuleset) Ruleset(ctx context.Context, environment workspace.EnvironmentID) (Ruleset, error)

Ruleset materializes the ruleset of environment from one snapshot, so the document and its version never mix the states before and after a write. An environment that no longer exists has no ruleset to serve: ErrRulesetUnavailable.

type MaterializeRulesetDeps

type MaterializeRulesetDeps struct {
	Snapshots    Snapshotter
	Environments RulesetEnvironmentsByID
	Declarations Declarations
	Flags        ConfiguredFlags
}

MaterializeRulesetDeps are what MaterializeRuleset runs on.

type PurgeSDKInventory

type PurgeSDKInventory struct {
	// contains filtered or unexported fields
}

PurgeSDKInventory forgets the SDKs not seen for the retention.

func NewPurgeSDKInventory

func NewPurgeSDKInventory(store InventoryStore, c clock.Clock, retention time.Duration) *PurgeSDKInventory

NewPurgeSDKInventory returns the handler, forgetting rows not seen for retention.

func (*PurgeSDKInventory) Handle

func (h *PurgeSDKInventory) Handle(ctx context.Context) error

Handle deletes the rows last seen more than the retention ago.

type ReadRuleset

type ReadRuleset struct {
	// contains filtered or unexported fields
}

ReadRuleset answers a member the ruleset of one of a project's environments, as its server SDKs receive it.

func NewReadRuleset

func NewReadRuleset(environments RulesetEnvironments, rulesets Rulesets) *ReadRuleset

NewReadRuleset returns the handler.

func (*ReadRuleset) Handle

func (h *ReadRuleset) Handle(ctx context.Context, project workspace.ProjectID, environment string) (Ruleset, error)

Handle returns the ruleset of project's environment keyed environment, the same document a server key receives, or not_found for an environment the project does not have.

type RemoteEvaluation

type RemoteEvaluation struct {
	RulesetVersion int64
	Environment    string
	Protected      bool
	// Results are by flag key, masked for a client key.
	Results map[string]eval.Result
	// Ignored are the attributes left out of the evaluation, by name.
	Ignored []delivery.IgnoredAttribute
}

RemoteEvaluation is what a remote evaluation answers.

type RemoteEvaluationCounts

type RemoteEvaluationCounts struct {
	// contains filtered or unexported fields
}

RemoteEvaluationCounts counts the remote evaluations a replica answers and writes them in rounds as evaluation summaries of the server's own, so reports include the evaluations of apps that hold no ruleset, while no evaluation waits on a write.

func NewRemoteEvaluationCounts

func NewRemoteEvaluationCounts(store SummaryStore, c clock.Clock) *RemoteEvaluationCounts

NewRemoteEvaluationCounts returns the replica's counter, writing to store.

func (*RemoteEvaluationCounts) Add

func (c *RemoteEvaluationCounts) Add(e delivery.RemoteEvaluator, rulesetVersion int64, results map[string]eval.Result)

Add counts the results of one remote evaluation, by their true reason.

func (*RemoteEvaluationCounts) Flush

func (c *RemoteEvaluationCounts) Flush(ctx context.Context) (int, error)

Flush writes what was counted since the last round and returns how many evaluations went uncounted meanwhile because the counter was full. Counts that cannot be written are dropped rather than retried, so a database that is down never grows a replica's memory; it returns the failure.

type RemoteQuery

type RemoteQuery struct {
	Context delivery.RemoteContext
	Flags   []string
	// SDK is the SDK asking, as its User-Agent names it or else its context.
	SDK delivery.SDKIdentity
}

RemoteQuery is a context posted for remote evaluation, and the flags to evaluate: every flag when Flags is nil.

type RevokeSDKKey

type RevokeSDKKey struct {
	// contains filtered or unexported fields
}

RevokeSDKKey revokes an SDK key.

func NewRevokeSDKKey

func NewRevokeSDKKey(d SDKKeyDeps) *RevokeSDKKey

NewRevokeSDKKey returns the handler.

func (*RevokeSDKKey) Handle

Handle revokes the key and records sdk_key.revoked; a revoked key is answered as it is, and nothing is recorded.

type RevokeSDKKeyCommand

type RevokeSDKKeyCommand struct {
	Ref     SDKKeyRef
	Key     delivery.SDKKeyID
	Request governance.Request
}

RevokeSDKKeyCommand names the key Key of Ref's environment to revoke.

type RotateSDKKey

type RotateSDKKey struct {
	// contains filtered or unexported fields
}

RotateSDKKey replaces an SDK key, keeping the old one working for an overlap.

func NewRotateSDKKey

func NewRotateSDKKey(d SDKKeyDeps) *RotateSDKKey

NewRotateSDKKey returns the handler.

func (*RotateSDKKey) Handle

Handle sets the rotated key's expiry and creates its replacement in one unit of work, and records sdk_key.rotated with the replacement and the overlap. The replacement takes the rotated key's place among the active keys, so the limit is not judged.

type RotateSDKKeyCommand

type RotateSDKKeyCommand struct {
	Ref     SDKKeyRef
	Key     delivery.SDKKeyID
	Overlap time.Duration
	Request governance.Request
}

RotateSDKKeyCommand asks for the key Key of Ref's environment to be replaced, the old one ending Overlap after the rotation.

type Ruleset

type Ruleset struct {
	// Version is the ruleset version the document carries.
	Version int64
	// Document is the server-scope ruleset document, as SDKs receive it.
	Document []byte
	// Evaluable is Document decoded, which remote evaluation evaluates, so
	// that a replica decodes a document once rather than once per request.
	Evaluable *eval.Ruleset
}

Ruleset is an environment's ruleset document at one version.

type RulesetEnvironments

type RulesetEnvironments interface {
	// RulesetEnvironment returns the identifier and ruleset version of the
	// environment of project keyed key, or ErrNotFound.
	RulesetEnvironment(ctx context.Context, project workspace.ProjectID, key string) (workspace.EnvironmentID, int64, error)
}

RulesetEnvironments reads the environment a ruleset is materialized for.

type RulesetEnvironmentsByID

type RulesetEnvironmentsByID interface {
	// RulesetEnvironmentByID returns the project of environment and the
	// materials of its ruleset filled with what the environment itself
	// says: its key, its protection and its ruleset version; or ErrNotFound.
	RulesetEnvironmentByID(ctx context.Context, environment workspace.EnvironmentID) (workspace.ProjectID, delivery.Materials, error)
}

RulesetEnvironmentsByID reads the environment a ruleset is materialized for by its identifier.

type RulesetStreams

type RulesetStreams interface {
	// Subscribe returns a subscription to the versions of environment.
	Subscribe(environment workspace.EnvironmentID) RulesetSubscription
	// Latest returns the newest version of environment this replica has
	// heard of while it has streams, 0 when it has heard of none, and above
	// every version while a version may exist that it could not load.
	Latest(environment workspace.EnvironmentID) int64
}

RulesetStreams offers each new ruleset version of an environment to the streams of that environment once this replica has loaded it.

type RulesetSubscription

type RulesetSubscription interface {
	// Changed is sent on when a version above every one offered before is
	// offered. It holds one signal at most, so a subscriber slow to read
	// it misses none: it reads Version when it gets to it.
	Changed() <-chan struct{}
	// Version returns the newest version offered.
	Version() int64
	// Close ends the subscription.
	Close()
}

RulesetSubscription is one stream's view of the ruleset versions of its environment this replica has loaded.

type RulesetVersions

type RulesetVersions interface {
	// BumpProject moves the ruleset version of every environment of project
	// on to its next version at now.
	BumpProject(ctx context.Context, project workspace.ProjectID, now time.Time) error
	// BumpEnvironment moves the ruleset version of environment on to its
	// next version at now.
	BumpEnvironment(ctx context.Context, environment workspace.EnvironmentID, now time.Time) error
}

RulesetVersions moves the ruleset versions of environments on, each to its next version at a time (delivery.NextRulesetVersion).

type Rulesets

type Rulesets interface {
	// Ruleset returns the ruleset of environment at its newest version
	// this replica knows, or ErrRulesetUnavailable.
	Ruleset(ctx context.Context, environment workspace.EnvironmentID) (Ruleset, error)
}

Rulesets answers the current ruleset of an environment.

type SDKInventory

type SDKInventory struct {
	// contains filtered or unexported fields
}

SDKInventory gathers the SDKs a replica sees making requests and writes them in rounds, so no request waits on recording its SDK and an SDK polling many times a minute costs one write.

func NewSDKInventory

func NewSDKInventory(tx Transactor, store InventoryStore, c clock.Clock) *SDKInventory

NewSDKInventory returns the replica's gatherer of the SDK inventory.

func (*SDKInventory) Dropped

func (i *SDKInventory) Dropped() InventoryDrops

Dropped returns the sightings dropped since it was last asked, for the round's warning.

func (*SDKInventory) Flush

func (i *SDKInventory) Flush(ctx context.Context) error

Flush writes the sightings noted since the last round, one unit of work per key. A key's sightings that cannot be written are dropped rather than retried, and counted as dropped: its SDKs' next requests are noted again. It returns the first failure.

func (*SDKInventory) Note

func (i *SDKInventory) Note(key delivery.SDKKey, sdk delivery.SDKIdentity, appVersion string, rulesetVersion int64)

Note keeps a request of key's SDK, naming the app version its context carried ("" for none) and the ruleset version it fetched or was sent (0 for none), for the next round.

type SDKKeyDeps

type SDKKeyDeps struct {
	Tx    Transactor
	Store SDKKeyStore
	Audit AuditLog
	Clock clock.Clock
	IDs   *id.Source
	// Random draws key values.
	Random io.Reader
}

SDKKeyDeps are what the SDK key use cases run on.

type SDKKeyLookup

type SDKKeyLookup interface {
	// SDKKeyByHash returns the key whose value hashes to hash, or
	// ErrNotFound.
	SDKKeyByHash(ctx context.Context, hash delivery.SDKKeyHash) (delivery.SDKKey, error)
	// HeldSDKKeyByHash returns the key whose value hashes to hash when the
	// lookup holds it in memory already, without looking it up anywhere,
	// and false otherwise. A hash known not to name a key is never held.
	HeldSDKKeyByHash(hash delivery.SDKKeyHash) (delivery.SDKKey, bool)
}

SDKKeyLookup finds SDK keys by the hash of their value.

type SDKKeyRef

type SDKKeyRef struct {
	Project     workspace.ProjectID
	Environment string
}

SDKKeyRef names the environment keyed Environment of Project.

type SDKKeyState

type SDKKeyState struct {
	delivery.SDKKey
	Status delivery.SDKKeyStatus
}

SDKKeyState is a key with its status at the time it was read.

type SDKKeyStore

type SDKKeyStore interface {
	// SDKKeyEnvironment returns the identifier of the environment of
	// project keyed key, locking its row for the unit of work when lock is
	// set, so the keys of one environment change one at a time; or
	// ErrNotFound.
	SDKKeyEnvironment(ctx context.Context, project workspace.ProjectID, key string, lock bool) (workspace.EnvironmentID, error)
	// SDKKeys returns every key of environment, the oldest first.
	SDKKeys(ctx context.Context, environment workspace.EnvironmentID) ([]delivery.SDKKey, error)
	// SDKKey returns environment's key identified by key, locking its row
	// when lock is set, or ErrNotFound.
	SDKKey(ctx context.Context, environment workspace.EnvironmentID, key delivery.SDKKeyID, lock bool) (delivery.SDKKey, error)
	// ActiveSDKKeys counts environment's keys of kind neither rotated nor
	// revoked.
	ActiveSDKKeys(ctx context.Context, environment workspace.EnvironmentID, kind delivery.SDKKeyKind) (int, error)
	CreateSDKKey(ctx context.Context, k delivery.SDKKey) error
	// UpdateSDKKey stores a key's name, allowed origins, expiry and
	// revocation.
	UpdateSDKKey(ctx context.Context, k delivery.SDKKey) error
}

SDKKeyStore keeps environments' SDK keys.

type SDKKeyUseStore

type SDKKeyUseStore interface {
	// RecordSDKKeyUse records that key was used at at, unless a use less
	// than delivery.SDKKeyUseInterval before at is recorded already, so
	// replicas writing the same key's use coalesce.
	RecordSDKKeyUse(ctx context.Context, key delivery.SDKKeyID, at time.Time) error
}

SDKKeyUseStore records when SDK keys were last used.

type SDKKeyUses

type SDKKeyUses struct {
	// contains filtered or unexported fields
}

SDKKeyUses gathers the uses of SDK keys a replica sees and writes them in rounds, so authenticating a request never waits on a write and a key presented many times a minute costs one.

func NewSDKKeyUses

func NewSDKKeyUses(store SDKKeyUseStore) *SDKKeyUses

NewSDKKeyUses returns the replica's gatherer of SDK key uses.

func (*SDKKeyUses) Flush

func (u *SDKKeyUses) Flush(ctx context.Context) error

Flush writes the uses noted since the last round. A use that cannot be written is dropped rather than retried: the key's next use after the interval is noted again, and nothing depends on the record but a member's view of their keys. It returns the first failure, for the round's log.

func (*SDKKeyUses) Note

func (u *SDKKeyUses) Note(k delivery.SDKKey, at time.Time)

Note keeps k's use at at for the next round when it is one worth recording and there is room for it.

type ServeRuleset

type ServeRuleset struct {
	// contains filtered or unexported fields
}

ServeRuleset answers a server SDK its environment's ruleset.

func NewServeRuleset

func NewServeRuleset(rulesets Rulesets) *ServeRuleset

NewServeRuleset returns the handler.

func (*ServeRuleset) Handle

func (h *ServeRuleset) Handle(ctx context.Context, key delivery.SDKKey) (Ruleset, error)

Handle returns the ruleset of key's environment. Only a server key receives one (key_kind_not_allowed otherwise): the document carries private segments, which an app shipping a client key must never hold.

type Snapshotter

type Snapshotter interface {
	Snapshot(ctx context.Context, fn func(ctx context.Context) error) error
}

Snapshotter runs a query of several statements on one consistent view.

type SummaryStore

type SummaryStore interface {
	SaveSummaries(ctx context.Context, rows []delivery.SummaryRecord) error
}

SummaryStore stores the rows of evaluation summaries.

type Transactor

type Transactor interface {
	Within(ctx context.Context, fn func(ctx context.Context) error) error
}

Transactor runs a unit of work.

type UpdateSDKKey

type UpdateSDKKey struct {
	// contains filtered or unexported fields
}

UpdateSDKKey renames an SDK key and replaces its allowed origins.

func NewUpdateSDKKey

func NewUpdateSDKKey(d SDKKeyDeps) *UpdateSDKKey

NewUpdateSDKKey returns the handler.

func (*UpdateSDKKey) Handle

Handle applies the change, to a rotated or revoked key too, and records sdk_key.updated; a change to the values the key has stores and records nothing.

type UpdateSDKKeyCommand

type UpdateSDKKeyCommand struct {
	Ref     SDKKeyRef
	Key     delivery.SDKKeyID
	Change  delivery.SDKKeyChange
	Request governance.Request
}

UpdateSDKKeyCommand is a change to the key Key of Ref's environment.

type WatchRuleset

type WatchRuleset struct {
	// contains filtered or unexported fields
}

WatchRuleset follows the ruleset versions of a key's environment for the ruleset stream, which carries versions only: never a document, so either kind of key may hold it.

func NewWatchRuleset

func NewWatchRuleset(streams RulesetStreams, rulesets Rulesets) *WatchRuleset

NewWatchRuleset returns the handler. rulesets is read for the current version, and must not count its answers towards a version's propagation: a stream carries no ruleset.

func (*WatchRuleset) CatchUp

func (h *WatchRuleset) CatchUp(ctx context.Context, key delivery.SDKKey, sent int64) (int64, error)

CatchUp returns the current version of key's environment when the replica has heard of a version above sent, which a failed reload may have left unoffered; otherwise sent.

func (*WatchRuleset) Open

Open subscribes to the versions of key's environment, then reads its current version: in that order, so a version loaded between the two is offered rather than missed. ErrRulesetUnavailable when the replica cannot load the ruleset in ctx's time.

Jump to

Keyboard shortcuts

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