Documentation
¶
Overview ¶
Package transfer is the domain of moving a project's configuration in and out of the platform as one project document: the document's types, its byte-stable encodings in JSON and YAML, and its strict decoding. The document is a contract read by people and tools the server never sees, so it is versioned apart from the management API and its names are spelled out here and not borrowed from any other type.
Index ¶
- Constants
- Variables
- func CheckCreate(d Document) error
- func CheckMerge(d, current Document) error
- func CheckReplace(d, current Document) error
- func Encode(f Format, d Document) ([]byte, error)
- func FlagConditions(in []Condition) []flags.Condition
- func Pointer(parts ...any) string
- type Attribute
- type Changes
- type Condition
- type Configuration
- type Date
- type Decision
- type Deletions
- type Document
- type Environment
- type Experiment
- type ExperimentStatus
- type ExperimentVariation
- type Flag
- type Format
- type KindChanges
- type MalformedError
- type Mode
- type Override
- type PatchOperation
- type Plan
- type Planned
- type Prerequisite
- type Project
- type Rule
- type SectionPlan
- type Segment
- type Serve
- type Snapshot
- type UnitType
- type Update
- type Variation
- type Warning
Constants ¶
const ( // WarningOwnerReplaced is the warning of an owner the document names who // may not own in the project. WarningOwnerReplaced = "owner_replaced" // WarningProtectionKept is the warning of an existing environment the // document protects, or stops protecting, differently from the project: // an import never changes that. WarningProtectionKept = "protection_kept" )
The warnings an import answers with.
const (
SourceDocument = "document"
)
Source is what an import read its changes from.
const SourceFirebase = "firebase"
SourceFirebase is the source of an import that read a Remote Config template.
const Version = 1
Version is the schema_version this server writes.
Variables ¶
var SupportedVersions = []int{1}
SupportedVersions are the schema_versions this server reads: every one it ever wrote, since a document kept in git outlives the server that wrote it.
Functions ¶
func CheckCreate ¶
CheckCreate returns the refusal of d as the document to make a new project of, nil when it holds what a document alone can tell. Every fault is reported at once, with a pointer into the document, in the order of the document.
It judges what no context judges alone: which sections a create needs, keys repeated within a kind, a unit type and an attribute sharing a key, a standard attribute declared as another type, a configuration for an environment the document does not have, and the form of the rule identifiers and salts. The rules each context holds of its own entities are judged where they are written.
func CheckMerge ¶
CheckMerge returns the refusal of d as a document to merge into the project whose document is current, nil when it holds what a document alone, read with the project, can tell. Every fault is reported at once, with a pointer into the document, in the order of the document. No section is required.
It judges what no context judges alone, as CheckCreate does, and besides a type that changes, which an existing flag or attribute never does.
func CheckReplace ¶ added in v0.4.0
CheckReplace returns the refusal of d as a document to replace the configuration of the project whose document is current with, nil when it holds what a document alone, read with the project, can tell. Every section is required, as for a new project, and at least one environment, since the project equals the document once it is applied; a configuration may name only an environment of the document, since the others are deleted. What the project holds that the document does not name is deleted, so its salts are free for the document to reuse.
func Encode ¶
Encode returns d written in f. The bytes depend on the document alone: two documents of one project are the same file wherever their lists were built in another order, so a diff of two exports shows real changes. The environments keep their order, which is their sort order, and so do the lists whose order serves (variations, rules, tags, an experiment's weights); every other list is by key, in byte order, and a map is too.
func FlagConditions ¶
FlagConditions returns the conditions as the flags context holds them.
Types ¶
type Attribute ¶
type Attribute struct {
Key string `json:"key"`
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
}
Attribute is a declared attribute. The standard attributes every project has are never listed.
type Changes ¶
type Changes struct {
Environments KindChanges
UnitTypes KindChanges
Attributes KindChanges
Segments KindChanges
Flags KindChanges
Experiments KindChanges
}
Changes are what an import did, by kind of entity.
type Condition ¶
type Condition struct {
Kind string `json:"kind"`
Attribute string `json:"attribute,omitempty"`
Op string `json:"op,omitempty"`
// Value is a string, a number, a boolean or a list; absent for an
// operator that takes none.
Value any `json:"value,omitempty"`
Segment string `json:"segment,omitempty"`
Flag string `json:"flag,omitempty"`
Variation string `json:"variation,omitempty"`
}
Condition is one comparison inside a rule or a segment, spelled as the management API spells it so that a person moving between the two sees one shape.
type Configuration ¶
type Configuration struct {
On bool `json:"on"`
OffVariation string `json:"off_variation"`
Fallthrough string `json:"fallthrough"`
Prerequisites []Prerequisite `json:"prerequisites"`
Overrides []Override `json:"overrides"`
Rules []Rule `json:"rules"`
}
Configuration is what a flag serves in one environment.
func (Configuration) Input ¶
func (c Configuration) Input() flags.ConfigurationInput
Input returns the configuration as a write gives it whole. A rule keeps the identifier and a rollout the salt the document names; the flags context gives the rest.
type Date ¶
Date is a calendar day, written as 2006-01-02.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON reads a day, or an instant of which the UTC day counts: a YAML reader hands a bare date over as an instant.
type Decision ¶
type Decision struct {
Outcome string `json:"outcome"`
WinnerVariation string `json:"winner_variation"`
Note string `json:"note"`
}
Decision is what stopping an experiment decided.
type Deletions ¶ added in v0.4.0
type Deletions struct {
Experiments []string
Flags []string
Segments []string
Attributes []string
UnitTypes []string
Environments []string
// NotDraft are the experiments the document does not name that cannot be
// deleted, since only a draft is: deleting one would erase the exposures
// and the history it has.
NotDraft []ExperimentStatus
// Held are the experiments the document names whose flag it does not: the
// flag would take them with it.
Held []flags.Reference
}
Deletions are what a replace deletes once the document is merged: every entity of the project the document does not name, by kind, in the order they are deleted. A kind is deleted before the kinds its entities can be used by, so that what an absent flag required is free when the flag has gone.
func PlanDeletions ¶ added in v0.4.0
PlanDeletions returns what replacing the project whose document is current with doc deletes: whatever the project has that doc does not name, but the standard attributes every project has. Flags are ordered with the flags that require another first.
func (Deletions) Refusal ¶ added in v0.4.0
Refusal returns the refusal of a replace that cannot be applied whatever the project's state is, nil when there is none: 409 not_draft naming every experiment that is not a draft, with a violation each; a flag the document's experiments hold is reported by the deletion itself.
type Document ¶
type Document struct {
SchemaVersion int `json:"schema_version"`
Project *Project `json:"project"`
Environments []Environment `json:"environments"`
UnitTypes []UnitType `json:"unit_types"`
Attributes []Attribute `json:"attributes"`
Segments []Segment `json:"segments"`
Flags []Flag `json:"flags"`
Experiments []Experiment `json:"experiments"`
}
Document is a project's whole configuration: what an export writes and an import reads. Identity is the key; no entity identifier travels, except the rule identifiers and rollout salts that keep a unit in its bucket.
A section that is nil was absent from the document read, which an import into a project treats as untouched; an export always writes every section.
func Decode ¶
Decode reads a document from data written in f. It is strict, so that a document from a newer server fails loudly on an older one instead of importing with silent loss: a field the document does not define is refused naming its JSON Pointer, as is a value of the wrong type, and so is data after the document. Every fault found is reported at once.
A schema_version this server does not read is the invalid error schema_version_unsupported, naming the versions it does; any other fault is the invalid error invalid_document with a violation per fault.
func Effective ¶
Effective returns doc as it applies to the project whose document is current: what a document that names a flag leaves of the flag is its definition and the configurations it holds, so the configuration in an environment the document does not hold stays as the project has it; and what the document leaves open it takes from the project. A rule without an identifier that equals a rule the project has in that configuration is that rule, and a rollout without a salt keeps the one it has, so that a document written by hand, with neither, is the same project when imported again; a rule that equals none is new, and is given both when it is written. The order of overrides and prerequisites is the project's where the same ones are named, since it carries no meaning a document can write.
func FirebaseDocument ¶ added in v0.4.0
FirebaseDocument returns the document that merges a translated template into the environment of a project whose document is current: the attributes the translation declares and a flag for every parameter, and nothing else, so that a merge leaves the rest of the project as it is.
A flag the project has is written whole, so it is its current entry with only what the translation sets changed: the description, the tags, the variations and its configuration in the environment, whose prerequisites and overrides are kept. Its name, owner, lifetime, archiving and every other environment stay. A new flag is configured in the environment only, on, and the merge gives it its initial configuration, off, in the others.
func FromSnapshot ¶
FromSnapshot returns the document that holds s, and nothing else: no identifier but the rules', no author of an override, no member, credential or history.
type Environment ¶
type Environment struct {
Key string `json:"key"`
Name string `json:"name"`
Protected bool `json:"protected"`
}
Environment is an environment; its place in the document's list is its sort order.
type Experiment ¶
type Experiment struct {
Key string `json:"key"`
Name string `json:"name"`
Hypothesis string `json:"hypothesis"`
Owner string `json:"owner"`
Tags []string `json:"tags"`
Flag string `json:"flag"`
UnitType string `json:"unit_type"`
Variations []ExperimentVariation `json:"variations"`
TrafficAllocation int `json:"traffic_allocation"`
InclusionSalt string `json:"inclusion_salt"`
VariationSalt string `json:"variation_salt"`
Status string `json:"status"`
ExpectedEndAt *Date `json:"expected_end_at"`
StartedAt *time.Time `json:"started_at"`
StoppedAt *time.Time `json:"stopped_at"`
ArchivedAt *time.Time `json:"archived_at"`
Decision *Decision `json:"decision"`
}
Experiment is an experiment as it stands, whatever its status.
type ExperimentStatus ¶ added in v0.4.0
type ExperimentStatus struct{ Key, Status string }
ExperimentStatus is an experiment with its status.
type ExperimentVariation ¶
ExperimentVariation is one variation's share of an experiment's allocated traffic, in basis points. The list's order fixes the cumulative bucket ranges, so it is kept.
type Flag ¶
type Flag struct {
Key string `json:"key"`
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Owner string `json:"owner"`
Tags []string `json:"tags"`
Lifetime string `json:"lifetime"`
// ExpectedRemovalAt is null for a permanent flag.
ExpectedRemovalAt *time.Time `json:"expected_removal_at"`
AutomaticExposure bool `json:"automatic_exposure"`
Archived bool `json:"archived"`
Variations []Variation `json:"variations"`
// Configurations are keyed by environment key.
Configurations map[string]Configuration `json:"configurations"`
}
Flag is a flag's definition with its configuration in every environment.
func (Flag) VariationInputs ¶
func (f Flag) VariationInputs() *[]flags.VariationInput
VariationInputs returns the flag's variations as a write gives them, nil when the document lists none, which gives a boolean flag its two.
type Format ¶
type Format string
Format is how a document is written: JSON is the canonical encoding and YAML is derived from it field for field.
func ParseFormat ¶
ParseFormat returns the format named name, and whether there is one.
type KindChanges ¶
KindChanges are what an import did to the entities of one kind, by key.
type MalformedError ¶
type MalformedError struct{ Detail string }
MalformedError is input that is not a document in the format at all: text that does not parse, or that holds more than one document. The adapter answers it as a request it cannot decode, where a document that parses but breaks a rule is answered with pointers into it.
func (*MalformedError) Error ¶
func (e *MalformedError) Error() string
type Mode ¶
type Mode string
Mode is how an import applies a document to the platform.
const ( // ModeCreate makes a new project of exactly the document. ModeCreate Mode = "create" // ModeMerge creates or updates what the document names in a project and // leaves the rest. ModeMerge Mode = "merge" // ModeReplace merges the document into a project, then deletes what the // document does not name, unless something still uses it. ModeReplace Mode = "replace" )
The modes.
type Override ¶
type Override struct {
UnitType string `json:"unit_type"`
UnitID string `json:"unit_id"`
Variation string `json:"variation"`
Note string `json:"note"`
}
Override pins a variation for one unit. Who wrote it does not travel: the importer is its author.
type PatchOperation ¶
PatchOperation is one operation of an RFC 6902 JSON Patch.
type Plan ¶
type Plan struct {
Environments SectionPlan
UnitTypes SectionPlan
Attributes SectionPlan
Segments SectionPlan
Flags SectionPlan
Experiments SectionPlan
}
Plan is what merging a document into a project would create and update. A merge deletes nothing.
func Compare ¶
Compare returns what applying doc, as Effective leaves it, to the project whose document is current creates and updates. An entity the two agree on is in neither list: whether two entities agree is whether the document writes them alike, which is the patch between them being empty. A section doc lacks plans nothing.
type Planned ¶
type Planned struct {
// Index is the entity's place in its section of the document.
Index int
Key string
// Patch turns the entity as the project has it into the entity as the
// merge leaves it, over the entity's entry of the document; nil for a
// created entity.
Patch []PatchOperation
}
Planned is an entity a merge creates or updates.
type Prerequisite ¶
Prerequisite requires another flag to serve one of its variations.
type Project ¶
type Project struct {
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
}
Project is the project's own fields.
type Rule ¶
type Rule struct {
// ID keeps the rule's identity across instances, so an SDK's rule_id
// stays stable; a hand-written document may leave it out.
ID string `json:"id"`
Description string `json:"description"`
Conditions []Condition `json:"conditions"`
Serve Serve `json:"serve"`
}
Rule is an ordered set of conditions, all of which must hold for it to serve.
type SectionPlan ¶
SectionPlan is what a merge does to the entities of one section, in the order of the document.
type Segment ¶
type Segment struct {
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
Private bool `json:"private"`
Conditions []Condition `json:"conditions"`
}
Segment is a named set of attribute conditions.
type Serve ¶
type Serve struct {
Kind string `json:"kind"`
Variation string `json:"variation,omitempty"`
Experiment string `json:"experiment,omitempty"`
UnitType string `json:"unit_type,omitempty"`
// Percentage is a rollout's share in basis points; nil for another
// kind, since 0 is a share too.
Percentage *int `json:"percentage,omitempty"`
// Salt is a rollout's; it decides which units fall in the share, so it
// travels. A hand-written document may leave it out.
Salt string `json:"salt,omitempty"`
}
Serve is what a matching rule serves, spelled as the management API spells it.
type Snapshot ¶
type Snapshot struct {
Project workspace.Project
Environments []workspace.Environment
UnitTypes []workspace.UnitType
// Attributes include the standard ones, which a document never lists.
Attributes []workspace.Attribute
Segments []flags.Segment
Flags []flags.Flag
// Configurations are each flag's, in the environments it has one in.
Configurations map[flags.FlagID][]flags.EnvironmentConfiguration
Experiments []experiments.Experiment
// Emails are the addresses of the members who own a flag or an
// experiment: members do not travel, so an owner does as an address.
Emails map[access.MemberID]string
}
Snapshot is a project's configuration as the contexts hold it, read in one consistent view.
type UnitType ¶
type UnitType struct {
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
}
UnitType is a declared kind of unit.
type Update ¶
type Update struct {
Key string
Patch []PatchOperation
}
Update is an entity an import changed, with the patch that turns the entity as it was into the entity as it is, over the entity's entry of the document.
type Variation ¶
type Variation struct {
Key string `json:"key"`
// Value is JSON of the flag's type.
Value json.RawMessage `json:"value"`
Name string `json:"name"`
Description string `json:"description"`
}
Variation is one of the values a flag serves.
type Warning ¶
type Warning struct {
// Code is the stable name of the warning, such as owner_replaced.
Code string
// Pointer is where in the document it applies, "" for the document as a
// whole.
Pointer string
Detail string
// Params are the values a client explains the warning with.
Params map[string]any
}
Warning says something an import did differently from what the document asks, or could not do, without refusing it.
func FirebaseWarnings ¶ added in v0.4.0
FirebaseWarnings returns the warnings of a translation as an import answers them, their pointers into the template.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package firebase translates a Firebase Remote Config template into the flags, rules and attributes to merge into one environment: parameters become flags, conditional values become rules, and everything the translation cannot reproduce becomes a coded warning pointing into the template.
|
Package firebase translates a Firebase Remote Config template into the flags, rules and attributes to merge into one environment: parameters become flags, conditional values become rules, and everything the translation cannot reproduce becomes a coded warning pointing into the template. |