Documentation
¶
Overview ¶
Package transfer holds the use cases of the transfer context: a project's configuration leaving the platform as a project document.
Index ¶
- type AuditLog
- type ConfigurationImport
- type Effect
- type ExperimentImport
- type Experiments
- type ExperimentsImport
- type ExportProject
- type ExportProjectDeps
- type ExportQuery
- type Exported
- type FlagImport
- type FlagUpdate
- type Flags
- type FlagsImport
- type History
- type ImportIntoProject
- type ImportIntoProjectCommand
- type ImportIntoProjectDeps
- type ImportNewProject
- type ImportNewProjectCommand
- type ImportNewProjectDeps
- type ImportResult
- type Members
- type Owners
- type ProjectLocker
- type Projects
- type Rulesets
- type SegmentImport
- type SegmentUpdate
- type Snapshotter
- type Transactor
- type Workspace
- type WorkspaceImport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ConfigurationImport ¶
type ConfigurationImport struct {
Project workspace.ProjectID
Flag string
Environment string
Input flags.ConfigurationInput
Caller *access.MemberID
Request governance.Request
}
ConfigurationImport is the configuration to write whole for a flag in one environment, with the rule identifiers and rollout salts it names.
type Effect ¶
type Effect struct {
Changed bool
Rulesets bool
// Environments are the environments whose ruleset the ordinary write
// would have moved on, for a write that moves only some: a running
// experiment's traffic allocation grown moves the ones holding its
// rules.
Environments []workspace.EnvironmentID
}
Effect is what a write of an import port did: whether it changed anything, and whether the ordinary write would have moved a ruleset on, which the import does once per environment when it is done. A write to a segment or to a flag's definition moves every environment's on, a write of a configuration its own environment's.
type ExperimentImport ¶
type ExperimentImport struct {
Project workspace.ProjectID
Key string
Name string
Hypothesis string
Owner *access.MemberID
Caller *access.MemberID
Tags []string
Flag string
UnitType string
Variations []experiments.Weight
TrafficAllocation int
// InclusionSalt and VariationSalt are the document's, "" for one it
// leaves out: a new draft is given them, an existing experiment keeps
// them.
InclusionSalt string
VariationSalt string
Status experiments.Status
ExpectedEndAt *time.Time
StartedAt *time.Time
StoppedAt *time.Time
ArchivedAt *time.Time
Decision *experiments.Decision
// Avoid are the salts the import gives rollouts, which no salt drawn for a
// new draft may be.
Avoid []string
Request governance.Request
}
ExperimentImport is an experiment as a document gives it, to create or to change. Owner is the member the document's owner resolved to, nil for none: the importing member owns a new experiment then, and an existing one keeps its owner.
type Experiments ¶
type Experiments interface {
// ProjectExperiments returns every experiment of the project, whatever
// its status.
ProjectExperiments(ctx context.Context, project workspace.ProjectID) ([]experiments.Experiment, error)
}
Experiments reads experiments, which the experiments context owns.
type ExperimentsImport ¶
type ExperimentsImport interface {
CreateExperiment(ctx context.Context, in ExperimentImport) (Effect, error)
UpdateExperiment(ctx context.Context, in ExperimentImport) (Effect, error)
// CheckSalts refuses two experiments of a project sharing a salt once
// every experiment is written: until then one may take a salt another
// gives up later in the same import.
CheckSalts(ctx context.Context) error
}
ExperimentsImport writes what the experiments context owns, as WorkspaceImport does. It creates an experiment exactly as the document has it, and changes one that exists only as an edit of its status allows, refusing frozen otherwise: it never moves an experiment through its status.
type ExportProject ¶
type ExportProject struct {
// contains filtered or unexported fields
}
ExportProject writes a project's configuration as a project document.
func NewExportProject ¶
func NewExportProject(d ExportProjectDeps) *ExportProject
NewExportProject returns the handler.
func (*ExportProject) Handle ¶
func (h *ExportProject) Handle(ctx context.Context, q ExportQuery) (Exported, error)
Handle returns the document of the project q names. Everything it holds is read in one snapshot, so it is the project as it was at one instant, and Latest is the newest entry of that instant: an import naming it as the state it was based on is refused when the project has moved on since. An unknown project is the not_found refusal.
type ExportProjectDeps ¶
type ExportProjectDeps struct {
Snapshots Snapshotter
Projects Projects
Workspace Workspace
Flags Flags
Experiments Experiments
Members Members
History History
}
ExportProjectDeps are what the export reads.
type ExportQuery ¶
ExportQuery says which project to export, and in which encoding.
type Exported ¶
type Exported struct {
Project workspace.Project
// Document is the document written in the format asked for.
Document []byte
// Latest is the newest audit entry of the project when the document was
// read, which any later change to the project moves on; the zero
// identifier when the project has none.
Latest governance.EntryID
}
Exported is a project document with what identifies the state of the project it holds.
type FlagImport ¶
type FlagImport struct {
Project workspace.ProjectID
Key string
Type flags.Type
Name, Description string
Owner *access.MemberID
Caller *access.MemberID
Tags []string
Lifetime flags.Lifetime
ExpectedRemovalAt *time.Time
AutomaticExposure bool
Variations *[]flags.VariationInput
Request governance.Request
}
FlagImport is a flag to create, switched off in every environment of its project. Owner is the member who owns it, Caller the member importing.
type FlagUpdate ¶
type FlagUpdate struct {
Project workspace.ProjectID
Key string
Name, Description string
Owner *access.MemberID
Tags []string
Lifetime flags.Lifetime
ExpectedRemovalAt *time.Time
AutomaticExposure bool
Variations *[]flags.VariationInput
Request governance.Request
}
FlagUpdate is the definition a flag is to have. Owner is the member who is to own it, nil to leave the owner as it is.
type Flags ¶
type Flags interface {
// Segments returns the project's segments by key.
Segments(ctx context.Context, project workspace.ProjectID) ([]flags.Segment, error)
// ProjectFlags returns every flag of the project, archived ones included.
ProjectFlags(ctx context.Context, project workspace.ProjectID) ([]flags.Flag, error)
// ProjectConfigurations returns the configuration of every flag of the
// project in every environment, by flag, each flag's by the
// environments' order.
ProjectConfigurations(ctx context.Context, project workspace.ProjectID) (map[flags.FlagID][]flags.EnvironmentConfiguration, error)
}
Flags reads segments, flags and their configurations, which the flags context owns.
type FlagsImport ¶
type FlagsImport interface {
CreateSegment(ctx context.Context, in SegmentImport) (Effect, error)
UpdateSegment(ctx context.Context, in SegmentUpdate) (Effect, error)
CreateFlag(ctx context.Context, in FlagImport) (Effect, error)
UpdateFlag(ctx context.Context, in FlagUpdate) (Effect, error)
// ArchiveFlag archives the flag keyed key; its configuration can still
// be written.
ArchiveFlag(ctx context.Context, project workspace.ProjectID, key string, req governance.Request) (Effect, error)
// RestoreFlag brings an archived flag back.
RestoreFlag(ctx context.Context, project workspace.ProjectID, key string, req governance.Request) (Effect, error)
// WriteConfiguration writes the configuration whole; one the flag has
// already is not written.
WriteConfiguration(ctx context.Context, in ConfigurationImport) (Effect, error)
}
FlagsImport writes what the flags context owns, as WorkspaceImport does.
type History ¶
type History interface {
// LatestProjectEntry returns the identifier of the newest audit entry of
// project, the zero identifier when it has none.
LatestProjectEntry(ctx context.Context, project workspace.ProjectID) (governance.EntryID, error)
}
History tells how far a project's history has come, which the audit log of the governance context keeps.
type ImportIntoProject ¶
type ImportIntoProject struct {
// contains filtered or unexported fields
}
ImportIntoProject applies a project document to a project that exists.
func NewImportIntoProject ¶
func NewImportIntoProject(d ImportIntoProjectDeps) *ImportIntoProject
NewImportIntoProject returns the handler.
func (*ImportIntoProject) Handle ¶
func (h *ImportIntoProject) Handle(ctx context.Context, cmd ImportIntoProjectCommand) (ImportResult, error)
Handle merges the document into the project, whole or not at all, in one unit of work that holds the project's row from before the project is read: what the document names is created or updated, written through the context that owns it as an ordinary write is, each entity that differs recording its own audit entry, and the rest is left as it is. An import that changes nothing writes nothing, records nothing and moves no ruleset on; one that changes something records one entry for the import and moves each changed environment's ruleset on once. The unit of work bypasses protection in every environment. With a dry run the whole unit of work runs, so every check the database makes is made, and is then rolled back.
IfMatch is judged under the project's row before anything is written. A document that breaks a rule is refused whole, with every fault found.
type ImportIntoProjectCommand ¶
type ImportIntoProjectCommand struct {
Project workspace.ProjectID
Document transfer.Document
DryRun bool
IfMatch *string
Caller *access.MemberID
Request governance.Request
}
ImportIntoProjectCommand is the document to merge into Project. IfMatch, when given, is the entity tag of the project's state the import is based on, as an answer to a dry run gave it. Caller is the member importing.
type ImportIntoProjectDeps ¶
type ImportIntoProjectDeps struct {
Tx Transactor
Projects ProjectLocker
Workspace Workspace
Flags Flags
Experiments Experiments
Members Members
History History
WorkspaceImport WorkspaceImport
FlagsImport FlagsImport
ExperimentsImport ExperimentsImport
Owners Owners
Rulesets Rulesets
Audit AuditLog
Clock clock.Clock
IDs *id.Source
}
ImportIntoProjectDeps are what ImportIntoProject runs on.
type ImportNewProject ¶
type ImportNewProject struct {
// contains filtered or unexported fields
}
ImportNewProject creates a project from a project document.
func NewImportNewProject ¶
func NewImportNewProject(d ImportNewProjectDeps) *ImportNewProject
NewImportNewProject returns the handler.
func (*ImportNewProject) Handle ¶
func (h *ImportNewProject) Handle(ctx context.Context, cmd ImportNewProjectCommand) (ImportResult, error)
Handle creates the project, whole or not at all: the document is checked as a document, then each entity is written through the context that owns it in one unit of work, in the order they name each other, each recording its own audit entry, followed by one entry for the import. Every fault of the document is reported at once, with a pointer into it: an entity the document check refuses is not written, and the others are, so that their contexts judge them too, in a unit of work that is then rolled back. The unit of work bypasses protection in every environment: a project made from a document has no ruleset to review. With a dry run the whole unit of work runs, so every check the database makes is made, and is then rolled back.
type ImportNewProjectCommand ¶
type ImportNewProjectCommand struct {
Document transfer.Document
Key *string
Name *string
DryRun bool
Caller *access.MemberID
Request governance.Request
}
ImportNewProjectCommand is the document to create a project from. Key and Name, when given, replace the document's. Caller is the member importing, nil for a token that acts for none.
type ImportNewProjectDeps ¶
type ImportNewProjectDeps struct {
Tx Transactor
Workspace WorkspaceImport
Flags FlagsImport
Experiments ExperimentsImport
Owners Owners
Rulesets Rulesets
Audit AuditLog
Clock clock.Clock
IDs *id.Source
}
ImportNewProjectDeps are what ImportNewProject runs on.
type ImportResult ¶
type ImportResult struct {
// Project is the project's key, name and description as they are, or
// would be.
Project transfer.Project
Mode transfer.Mode
Source string
DryRun bool
Changes transfer.Changes
Warnings []transfer.Warning
// Latest is the newest audit entry of the project before the import, the
// zero identifier when it has none or there was no project yet: the state
// a later import can name as the one it is based on.
Latest governance.EntryID
}
ImportResult is what an import did, or with a dry run what it would do.
type Members ¶
type Members interface {
// MemberEmails returns the email address of each of members that exists.
MemberEmails(ctx context.Context, members []access.MemberID) (map[access.MemberID]string, error)
}
Members reads who owns what, which the access context knows.
type Owners ¶
type Owners interface {
// OwnerByEmail returns the member with email, whatever its case, who
// may own in project, and whether there is one.
OwnerByEmail(ctx context.Context, project workspace.ProjectID, email string) (access.MemberID, bool, error)
}
Owners resolves the owners a document names, who are email addresses.
type ProjectLocker ¶
type ProjectLocker interface {
// LockProject returns the project, and whether there is one.
LockProject(ctx context.Context, project workspace.ProjectID) (workspace.Project, bool, error)
}
ProjectLocker locks a project's row for the unit of work, which an import holds from before it reads what the project has until it commits.
type Projects ¶
type Projects interface {
// Projects returns every project when all is set, else those of ids,
// ordered by key.
Projects(ctx context.Context, all bool, ids []workspace.ProjectID) ([]workspace.Project, error)
}
Projects reads projects.
type Rulesets ¶
type Rulesets interface {
// Environment marks the ruleset of environment changed.
Environment(ctx context.Context, environment workspace.EnvironmentID) error
}
Rulesets marks the rulesets an import changed, in its unit of work.
type SegmentImport ¶
type SegmentImport struct {
Project workspace.ProjectID
Key string
Name, Description string
Private bool
Conditions []flags.Condition
Request governance.Request
}
SegmentImport is a segment to create.
type SegmentUpdate ¶
type SegmentUpdate struct {
Project workspace.ProjectID
Key string
Name, Description string
Private bool
Conditions []flags.Condition
Request governance.Request
}
SegmentUpdate is the values a segment is to have.
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, so what it answers never mixes the states before and after a write committed between its statements.
type Transactor ¶
Transactor runs a unit of work. An import is one: it applies whole or not at all, and a dry run is one that is rolled back.
type Workspace ¶
type Workspace interface {
// Environments returns the project's environments by sort order.
Environments(ctx context.Context, project workspace.ProjectID) ([]workspace.Environment, error)
// UnitTypes returns the project's unit types by key.
UnitTypes(ctx context.Context, project workspace.ProjectID) ([]workspace.UnitType, error)
// Attributes returns the project's attributes by key, the standard ones
// included.
Attributes(ctx context.Context, project workspace.ProjectID) ([]workspace.Attribute, error)
}
Workspace reads what a project declares, which the workspace context owns.
type WorkspaceImport ¶
type WorkspaceImport interface {
// CreateProject creates a project holding only the standard
// attributes; a key in use is already_exists.
CreateProject(ctx context.Context, key, name, description string, req governance.Request) (workspace.Project, error)
// UpdateProject writes the project's name and description and returns
// the project as it is, and whether that changed anything.
UpdateProject(ctx context.Context, project workspace.ProjectID, name, description string, req governance.Request,
) (workspace.Project, bool, error)
// CreateEnvironment creates an environment at sortOrder, protected or
// not, configuring every flag the project has in it, as written by by.
CreateEnvironment(ctx context.Context, project workspace.ProjectID, key, name string, protected bool, sortOrder int,
by *access.MemberID, req governance.Request) (workspace.Environment, error)
// UpdateEnvironment writes an environment's name, and says whether that
// changed anything. Whether it is protected is never an import's to
// change.
UpdateEnvironment(ctx context.Context, project workspace.ProjectID, key, name string, req governance.Request) (bool, error)
CreateUnitType(ctx context.Context, project workspace.ProjectID, key, name, description string,
req governance.Request) (workspace.UnitType, error)
UpdateUnitType(ctx context.Context, project workspace.ProjectID, key, name, description string, req governance.Request) (bool, error)
CreateAttribute(ctx context.Context, project workspace.ProjectID, key, name, description string,
typ workspace.AttributeType, req governance.Request) (workspace.Attribute, error)
// UpdateAttribute writes an attribute's name and description; its type
// never changes.
UpdateAttribute(ctx context.Context, project workspace.ProjectID, key, name, description string, req governance.Request) (bool, error)
}
WorkspaceImport writes what the workspace context owns. Each method runs the context's validation and records the audit entry of the ordinary write, in the unit of work the context carries, and none moves a ruleset on.