transfer

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package transfer holds the use cases of the transfer context: a project's configuration leaving the platform as a project document.

Index

Constants

View Source
const DefaultFirebaseUnitType = "anonymous"

DefaultFirebaseUnitType is the unit type percent rollouts bucket on when the import names none.

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
	// CheckServed refuses with in_use the configurations that serve one of
	// the experiments keyed keys while belonging to a flag other than the
	// experiment's, once every configuration is written: a document may move
	// a draft to another flag and drop the rules serving it together.
	CheckServed(ctx context.Context, project workspace.ProjectID, keys []string) error
	// DeleteExperiment deletes a draft experiment, which a rule serving it
	// keeps unless the rule belongs to one of the flags keyed leaving, which
	// the import deletes too.
	DeleteExperiment(ctx context.Context, project workspace.ProjectID, key string, leaving []string, req governance.Request) 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

type ExportQuery struct {
	Project workspace.ProjectID
	Format  transfer.Format
}

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 FirebaseAttribute added in v0.4.0

type FirebaseAttribute struct {
	Key  string
	Type workspace.AttributeType
}

FirebaseAttribute is an attribute the translation declares.

type FirebaseFlag added in v0.4.0

type FirebaseFlag struct {
	Key          string
	Type         flags.Type
	Description  string
	Tags         []string
	Variations   []transfer.Variation
	On           bool
	OffVariation string
	Fallthrough  string
	Rules        []transfer.Rule
}

FirebaseFlag is a flag the import wrote, as the project stores it in the target environment.

type FirebaseImportResult added in v0.4.0

type FirebaseImportResult struct {
	ImportResult
	// Flags are those of the template, by key.
	Flags      []FirebaseFlag
	Attributes []FirebaseAttribute
}

FirebaseImportResult is what an import of a template did, with the flags it left in the environment and the attributes it declared.

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)
	// DeleteSegment deletes a segment, refusing one a rule still names with
	// in_use.
	DeleteSegment(ctx context.Context, project workspace.ProjectID, key string, req governance.Request) (Effect, error)
	// DeleteFlag deletes a flag with its configurations, archiving it first
	// when it is not archived. A flag another requires, or a draft or running
	// experiment holds, is in_use.
	DeleteFlag(ctx context.Context, project workspace.ProjectID, key string, req governance.Request) (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 ImportFirebaseTemplate added in v0.4.0

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

ImportFirebaseTemplate merges a Firebase Remote Config template into one environment of a project. It is a merge like any other: the template is translated, inside the unit of work, into the project document that holds the flags and attributes it describes, and that document is applied.

func NewImportFirebaseTemplate added in v0.4.0

func NewImportFirebaseTemplate(d ImportIntoProjectDeps) *ImportFirebaseTemplate

NewImportFirebaseTemplate returns the handler. It runs on the same dependencies as ImportIntoProject.

func (*ImportFirebaseTemplate) Handle added in v0.4.0

Handle translates the template from the project's state under the project's row and merges what it describes into the environment, whole or not at all: a new flag is on there and off elsewhere, and an existing one keeps its other environments, its prerequisites and its overrides. A template that cannot be translated, an environment or a unit type the project lacks is refused as an invalid document, every fault found.

type ImportFirebaseTemplateCommand added in v0.4.0

type ImportFirebaseTemplateCommand struct {
	Project     workspace.ProjectID
	Template    firebase.Template
	Environment string
	UnitType    string
	DryRun      bool
	IfMatch     *string
	Caller      *access.MemberID
	Request     governance.Request
}

ImportFirebaseTemplateCommand is the template to merge into Environment of Project. UnitType is the unit type percent rollouts bucket on, the default one when empty. IfMatch is the entity tag of the project's state the import is based on, as for ImportIntoProjectCommand.

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

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
	// Mode is merge, or replace, which also deletes what the document does not
	// name; the zero value is merge.
	Mode     transfer.Mode
	Document transfer.Document
	DryRun   bool
	IfMatch  *string
	Caller   *access.MemberID
	Request  governance.Request
	// contains filtered or unexported fields
}

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
	SDKKeys           SDKKeys
	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

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)
	// ProjectMemberEmails returns the email address of each of members that
	// holds a grant in project, which is the set of addresses anyone who can
	// read the project already sees among its members; any other member is
	// absent.
	ProjectMemberEmails(ctx context.Context, project workspace.ProjectID, 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 SDKKeys added in v0.4.0

type SDKKeys interface {
	// LiveSDKKeys returns the identifiers of the keys of environment that
	// still authenticate: neither revoked nor past the end of their overlap.
	LiveSDKKeys(ctx context.Context, environment workspace.EnvironmentID) ([]string, error)
}

SDKKeys tells which SDK keys an environment holds, which keep an import from deleting it.

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

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

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)
	// DeleteEnvironment deletes an environment with everything it holds,
	// refusing the project's last and a protected one.
	DeleteEnvironment(ctx context.Context, project workspace.ProjectID, key string, req governance.Request) error
	// DeleteUnitType and DeleteAttribute delete a declaration, refusing one
	// something still names with in_use. Neither moves a ruleset on, though the
	// ordinary deletion moves every environment's: the import does.
	DeleteUnitType(ctx context.Context, project workspace.ProjectID, key string, req governance.Request) error
	DeleteAttribute(ctx context.Context, project workspace.ProjectID, key string, req governance.Request) 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.

Jump to

Keyboard shortcuts

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