Documentation
¶
Overview ¶
Package controlplane is the document format of the Semaphore control plane: the manifest, the flag-set documents and the flag objects that a publisher writes to a store (for example S3) and that the relay proxy reads.
A publisher fills the exported structs, calls a Marshal function and writes the bytes. The relay decodes the same bytes with an Unmarshal function and runs the same Validate functions, so "valid for the publisher" and "accepted by the relay" are one definition.
Format ¶
The manifest and the flag-set documents are YAML (JSON is accepted and can be written with the JSON variants) and start with a header: apiVersion "semaphore/v1" and kind "Manifest" or "FlagSet". Flag objects are headerless: a flag file is a top-level map keyed by flag names, which is the flag file format that the engine loads today (flag format v1). Their version and text format are listed in the manifest entry.
Output is deterministic: fields keep the order of the structs, map keys are sorted, no anchors or aliases are written and every string that a YAML 1.1 or 1.2 reader could read as another type (yes, no, on, off, y, n, 007, 1e3, 2026-01-01, null, ...) is double quoted.
Reading and validating ¶
The Unmarshal functions read YAML and JSON through one reader. Field names are case sensitive; duplicate keys, non-string keys, NaN, infinity, a second YAML document and an integer field with a fraction or an overflow are a *DecodeError, which never contains the text of a value. A float keeps its type (written 2.0) and an integer stays an integer, in both formats. Anchors, aliases and merge keys are accepted on read and never written.
The Validate functions return a *ValidationError whose FieldErrors carry a stable Code, the Kind of the entry (object, flag set, flag, document), its Name and Index, so a reader can keep the good entries and drop the bad ones without parsing text. Of two objects or flag sets with one name, and of an API key held by two flag sets, the first in document order keeps it and the later one has the problem. An object with a newer content version is an entry problem (CodeUnsupportedVersion), not a failure of the manifest. A wrong kind or apiVersion rejects the document whole (*KindError, *UnsupportedVersionError; they match ErrInvalid too).
Compatibility ¶
Within a version only additive optional fields are allowed. Readers ignore unknown fields of published documents (the Unmarshal functions report them in DecodeInfo) so an older relay reads the documents of a newer publisher. A document with an unsupported apiVersion or the wrong kind is rejected whole. A breaking change is a new apiVersion with new types side by side.
The Go API of this package follows semantic versioning from its first release. It is the only public, stability-guaranteed Go package of the module; the production files import only the standard library and gopkg.in/yaml.v3.
Example ¶
The whole publisher flow: marshal the flags, the flag-set document and the manifest, validate them as the relay will, then upload the objects first and the manifest last.
package main
import (
"fmt"
"github.com/blackbirdworks/semaphore/controlplane"
)
func main() {
flags := controlplane.Flags{"new-cart": {
Variations: map[string]any{"enabled": true, "disabled": false},
DefaultRule: &controlplane.Rule{Variation: new("disabled")},
Targeting: []controlplane.Rule{
{Name: new("pilot"), Query: new(`plan eq "pilot"`), Variation: new("enabled")},
},
}}
err := controlplane.ValidateFlags(flags)
if err != nil {
fmt.Println(err)
return
}
body, err := controlplane.MarshalFlags(flags)
if err != nil {
fmt.Println(err)
return
}
sum := controlplane.ChecksumOf(body)
key, err := controlplane.ObjectKey(sum, "yaml")
if err != nil {
fmt.Println(err)
return
}
set := &controlplane.FlagSetDocument{FlagSets: []controlplane.FlagSet{{
Name: "cart", Sources: []string{"cart-flags"}, APIKeys: []string{"9b2c4f3a-7d1e-4e0b-8a55-3c6d2f1e9a07"},
}}}
setBody, err := controlplane.MarshalFlagSet(set)
if err != nil {
fmt.Println(err)
return
}
setSum := controlplane.ChecksumOf(setBody)
setKey, err := controlplane.ObjectKey(setSum, "yaml")
if err != nil {
fmt.Println(err)
return
}
manifest := &controlplane.Manifest{
Channel: "prod",
Generation: 1,
Objects: []controlplane.ManifestObject{
{
Name: "cart-flags",
Kind: controlplane.KindFlags,
Connection: "cart-bucket",
Key: key,
Checksum: sum,
Size: int64(len(body)),
Format: controlplane.FormatYAML,
},
{
Name: "cart-sets",
Kind: controlplane.KindFlagSets,
Connection: "cart-control",
Key: setKey,
Checksum: setSum,
Size: int64(len(setBody)),
Format: controlplane.FormatYAML,
},
},
}
// The same checks the relay runs. An empty header means the current one.
err = controlplane.ValidateManifest(manifest)
if err != nil {
fmt.Println(err)
return
}
err = controlplane.ValidateFlagSet(set, manifest)
if err != nil {
fmt.Println(err)
return
}
manifestBody, err := controlplane.MarshalManifest(manifest)
if err != nil {
fmt.Println(err)
return
}
// Upload body and setBody first, manifestBody last.
fmt.Println(manifest.Objects[0].Key)
fmt.Print(string(manifestBody[:len("apiVersion: semaphore/v1\nkind: Manifest\n")]))
}
Output: objects/sha256/51/51261bbe10356e8c36b7431ed8bf585372f8309d7e7dfa51b971a72fe7e031c3.yaml apiVersion: semaphore/v1 kind: Manifest
Index ¶
- Constants
- Variables
- func MarshalFlagSet(d *FlagSetDocument) ([]byte, error)
- func MarshalFlagSetJSON(d *FlagSetDocument) ([]byte, error)
- func MarshalFlags(f Flags) ([]byte, error)
- func MarshalFlagsJSON(f Flags) ([]byte, error)
- func MarshalManifest(m *Manifest) ([]byte, error)
- func MarshalManifestJSON(m *Manifest) ([]byte, error)
- func MarshalSegments(d *SegmentsDocument) ([]byte, error)
- func MarshalSegmentsJSON(d *SegmentsDocument) ([]byte, error)
- func ObjectKey(sum Checksum, ext string) (string, error)
- func UnmarshalFlagSet(data []byte) (*FlagSetDocument, DecodeInfo, error)
- func UnmarshalFlags(data []byte, format string) (Flags, DecodeInfo, error)
- func UnmarshalManifest(data []byte) (*Manifest, DecodeInfo, error)
- func UnmarshalSegments(data []byte) (*SegmentsDocument, DecodeInfo, error)
- func ValidateFlagSet(doc *FlagSetDocument, manifest *Manifest) error
- func ValidateFlagSetDocuments(docs []*FlagSetDocument, manifest *Manifest) error
- func ValidateFlags(flags Flags) error
- func ValidateManifest(manifest *Manifest, opts ...ValidateOption) error
- func ValidateSegments(doc *SegmentsDocument) error
- func VerifyChecksum(data []byte, want Checksum) error
- type Checksum
- type ChecksumMismatchError
- type Code
- type DecodeError
- type DecodeInfo
- type EntryKind
- type Experimentation
- type FieldError
- type Flag
- type FlagSet
- type FlagSetDocument
- type Flags
- type KindError
- type Manifest
- type ManifestObject
- type MemberList
- type ProgressiveRollout
- type ProgressiveRolloutStep
- type Rule
- type ScheduledStep
- type SegmentCache
- type SegmentDefinition
- type SegmentVersion
- type SegmentsDocument
- type UnsupportedVersionError
- type ValidateOption
- type ValidationError
Examples ¶
Constants ¶
const ( // MaxSegmentMembers is the most members of a static segment. MaxSegmentMembers = 100_000 // MaxSegmentMemberBytes is the most bytes of the members of one static segment (the sum of their lengths). MaxSegmentMemberBytes = 4 << 20 // MaxSegmentMemberLen is the longest member of a static segment. MaxSegmentMemberLen = 4096 // MaxSegmentNameLen is the longest name of a segment. MaxSegmentNameLen = 64 // MaxSegmentKeyLen is the longest key or version of a dynamic segment. MaxSegmentKeyLen = 512 // MinVersionInterval is the shortest poll interval of a version key. MinVersionInterval = 100 * time.Millisecond // MaxSegmentDuration is the longest interval or time-to-live of a segment. MaxSegmentDuration = 24 * time.Hour // MaxCacheEntries is the most cache entries that a lookup segment may ask for. MaxCacheEntries = 10_000_000 )
The limits of a segments document and of the segments in it.
const ( // SegmentModeSnapshot pulls the whole member set and keeps it in memory. It is the default. SegmentModeSnapshot = "snapshot" // SegmentModeLookup asks the store for each evaluation. SegmentModeLookup = "lookup" // SegmentLayoutSet stores the members in one set. SegmentLayoutSet = "set" // SegmentLayoutKeys stores one key per member (lookup only). SegmentLayoutKeys = "keys" // SegmentMissingNotMember: a segment that does not exist has no member. It is the default. SegmentMissingNotMember = "notMember" // SegmentMissingUnknown: a segment that does not exist is unknown. SegmentMissingUnknown = "unknown" )
The values of the fields of a segment.
const ( // APIVersion is the document version this package writes. APIVersion = "semaphore/v1" // DocumentKindManifest is the kind of a manifest document. DocumentKindManifest = "Manifest" // DocumentKindFlagSet is the kind of a flag-set document. DocumentKindFlagSet = "FlagSet" // DocumentKindSegments is the kind of a segments document. DocumentKindSegments = "Segments" // KindFlags is the manifest object kind of a flag file. KindFlags = "flags" // KindFlagSets is the manifest object kind of a flag-set document. KindFlagSets = "flagSets" // KindSegments is the manifest object kind of a segments document. KindSegments = "segments" // FormatYAML is the YAML text format of an object. FormatYAML = "yaml" // FormatJSON is the JSON text format of an object. FormatJSON = "json" // FormatTOML is the TOML text format of an object (flag files only; this package does not read it). FormatTOML = "toml" // AlgorithmSHA256 is the only checksum algorithm of schema v1. AlgorithmSHA256 = "sha256" // ObjectVersion1 is the version of the content schema of an object: the headerless flag format. ObjectVersion1 = 1 )
const ( // DefaultMaxObjectBytes is the largest size of one object (16 MiB). DefaultMaxObjectBytes int64 = 16 << 20 // DefaultMaxTotalBytes is the largest sum of the sizes of the distinct objects of a manifest (1 GiB). DefaultMaxTotalBytes int64 = 1 << 30 // DefaultMaxManifestBytes is the largest size of the marshalled manifest (16 MiB). DefaultMaxManifestBytes int64 = 16 << 20 )
The limits the relay reader applies to what it downloads. A publisher must stay inside them, or the reader rejects what was published; the s3publish package uses these values as its defaults.
const DefaultMaxObjects = 20000
DefaultMaxObjects is the default bound on the number of objects of a manifest (validation and memory). The relay makes it a setting with the same default; pass WithMaxObjects to change it.
const NoIndex = -1
NoIndex is the Index of a FieldError whose entry has no position in a list.
Variables ¶
var ( // ErrUnsupportedAPIVersion is matched by an UnsupportedVersionError: a document whose apiVersion this // package does not read. ErrUnsupportedAPIVersion = errors.New("controlplane: unsupported apiVersion") // ErrWrongKind is matched by a KindError: a document of another kind than the one asked for. ErrWrongKind = errors.New("controlplane: wrong document kind") // ErrInvalid is matched by every ValidationError, UnsupportedVersionError and KindError. ErrInvalid = errors.New("controlplane: invalid document") // ErrChecksumMismatch is returned by VerifyChecksum when the bytes do not match. ErrChecksumMismatch = errors.New("controlplane: checksum mismatch") // ErrUnsupportedChecksum is returned for a checksum algorithm other than sha256. ErrUnsupportedChecksum = errors.New("controlplane: unsupported checksum algorithm") // ErrInvalidChecksum is returned for a checksum value that is not 64 lower-case hex characters. ErrInvalidChecksum = errors.New("controlplane: invalid checksum value") // ErrInvalidExtension is returned by ObjectKey for an extension that is not [a-z0-9]+. ErrInvalidExtension = errors.New("controlplane: invalid object extension") // ErrNilDocument is returned when a nil document is marshalled or validated. ErrNilDocument = errors.New("controlplane: nil document") // ErrUnsupportedFormat is returned for a text format this package does not read (for example toml). ErrUnsupportedFormat = errors.New("controlplane: unsupported format") // ErrUnsupportedValue is returned by a Marshal function for a value that cannot be written: NaN, infinity, // a map with non-string keys, a string that is not valid UTF-8, or a type outside the format. ErrUnsupportedValue = errors.New("controlplane: unsupported value") // ErrDecode is matched by every DecodeError: a document that is not readable. ErrDecode = errors.New("controlplane: decode") )
Functions ¶
func MarshalFlagSet ¶
func MarshalFlagSet(d *FlagSetDocument) ([]byte, error)
MarshalFlagSet writes d as deterministic YAML. See MarshalManifest for the header rules.
func MarshalFlagSetJSON ¶
func MarshalFlagSetJSON(d *FlagSetDocument) ([]byte, error)
MarshalFlagSetJSON writes d as deterministic indented JSON.
func MarshalFlags ¶
MarshalFlags writes a flag file as deterministic YAML. The file has no header.
func MarshalFlagsJSON ¶
MarshalFlagsJSON writes a flag file as deterministic indented JSON.
func MarshalManifest ¶
MarshalManifest writes m as deterministic YAML. An empty APIVersion or Kind is filled in; any other value than the current one is an error. m is not changed and not validated.
func MarshalManifestJSON ¶
MarshalManifestJSON writes m as deterministic indented JSON: the same document, field order and number types as MarshalManifest.
func MarshalSegments ¶
func MarshalSegments(d *SegmentsDocument) ([]byte, error)
MarshalSegments writes d as deterministic YAML. See MarshalManifest for the header rules.
func MarshalSegmentsJSON ¶
func MarshalSegmentsJSON(d *SegmentsDocument) ([]byte, error)
MarshalSegmentsJSON writes d as deterministic indented JSON.
func ObjectKey ¶
ObjectKey returns the immutable content-addressed key of an object: objects/sha256/<2 hex>/<hex>.<ext>. The checksum must be a valid sha256 (ErrUnsupportedChecksum, ErrInvalidChecksum) and ext must match [a-z0-9]+ without a dot (ErrInvalidExtension), so a key can never contain a path separator or a ".." element.
func UnmarshalFlagSet ¶
func UnmarshalFlagSet(data []byte) (*FlagSetDocument, DecodeInfo, error)
UnmarshalFlagSet reads a flag-set document from YAML or JSON. See UnmarshalManifest.
func UnmarshalFlags ¶
func UnmarshalFlags(data []byte, format string) (Flags, DecodeInfo, error)
UnmarshalFlags reads a flag file. format is "yaml" (or empty) or "json"; toml is not read by this package (ErrUnsupportedFormat). Input that is valid JSON is read as JSON whatever the format says, as JSON is YAML; format "json" requires valid JSON. A flag file has no header: any top-level map is flag format v1.
func UnmarshalManifest ¶
func UnmarshalManifest(data []byte) (*Manifest, DecodeInfo, error)
UnmarshalManifest reads a manifest from YAML or JSON. It rejects another kind or an unsupported apiVersion whole (*KindError, *UnsupportedVersionError) and reports unknown fields in DecodeInfo. It does not validate; call ValidateManifest. The rules of every Unmarshal function:
- YAML and JSON go through one reader: field names are case sensitive, duplicate keys, non-string keys, NaN, infinity, a second YAML document and trailing JSON data are a *DecodeError;
- an integer field rejects a fraction and an overflow; an integer value keeps its type (int, or uint64 above the int64 range) and a float keeps float64, in both formats;
- anchors, aliases and merge keys are accepted on read (and never written);
- an error never contains the text of a value.
Example ¶
package main
import (
"fmt"
"github.com/blackbirdworks/semaphore/controlplane"
)
func main() {
doc := []byte("apiVersion: semaphore/v1\nkind: Manifest\nchannel: prod\ngeneration: 3\nfuture: true\nobjects: []\n")
manifest, info, err := controlplane.UnmarshalManifest(doc)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(manifest.Channel, manifest.Generation, info.UnknownFields)
}
Output: prod 3 [future]
Example (UnsupportedVersion) ¶
package main
import (
"fmt"
"github.com/blackbirdworks/semaphore/controlplane"
)
func main() {
_, _, err := controlplane.UnmarshalManifest([]byte("apiVersion: semaphore/v2\nkind: Manifest\n"))
fmt.Println(err)
}
Output: controlplane: unsupported apiVersion: got "semaphore/v2", supported "semaphore/v1"
func UnmarshalSegments ¶
func UnmarshalSegments(data []byte) (*SegmentsDocument, DecodeInfo, error)
UnmarshalSegments reads a segments document from YAML or JSON. See UnmarshalManifest.
func ValidateFlagSet ¶
func ValidateFlagSet(doc *FlagSetDocument, manifest *Manifest) error
ValidateFlagSet checks a flag-set document. When manifest is not nil every source must name an object of kind flags of the manifest. Header failures are returned as for ValidateManifest.
Problems name the flag set (Kind EntryFlagSet, Name, Index) so a caller can keep the good flag sets. Of two flag sets with one name, and of an API key held by two flag sets, the first in document order keeps it and the later flag set has the problem (CodeDuplicateName, CodeDuplicateKey). The text of an API key is never printed.
func ValidateFlagSetDocuments ¶
func ValidateFlagSetDocuments(docs []*FlagSetDocument, manifest *Manifest) error
ValidateFlagSetDocuments checks a set of flag-set documents together, as the relay sees them: the flag sets of every document share one namespace. On top of what ValidateFlagSet checks per document, a flag-set name used in two documents is CodeDuplicateName and an API key held by flag sets of two documents is CodeDuplicateKey. The first in document order keeps the name or key and the later flag set has the problem. Paths are prefixed with the position of the document (documents[1].flagSets[0].apiKeys[0]) and a duplicate key names the path of the first use, never the text of the key. When manifest is not nil every source must resolve in it.
func ValidateFlags ¶
ValidateFlags checks a flag file with the structural rules of the engine's own validation, so that a flag accepted here is not dropped when the relay loads it: variations present, not null and all of one type, a default rule, enabled targeting rules with a query and an outcome, declared variations, valid percentages (finite, not negative, a non-zero sum), complete progressive rollouts (both steps, variations, dates in order), and the same checks on scheduled steps (whose rules may be partial updates of a named rule). A disabled targeting rule is not checked. It does not compile queries; the engine does.
Problems have Kind EntryFlag and the flag name in Name, so a caller can keep the good flags.
func ValidateManifest ¶
func ValidateManifest(manifest *Manifest, opts ...ValidateOption) error
ValidateManifest runs the checks the relay runs on a manifest (an empty header means the current one).
A wrong kind or an unsupported apiVersion rejects the document whole (*KindError, *UnsupportedVersionError, both match ErrInvalid too). Every other problem is a *ValidationError whose FieldErrors name the entry, so a caller can keep the good entries: an object with a problem is one that has a FieldError of Kind EntryObject with its Index. Of two objects with one name the first keeps it and the later one has the problem. An object with a newer content version is an entry problem (CodeUnsupportedVersion), not a failure of the manifest.
Example (WithMaxObjects) ¶
package main
import (
"fmt"
"github.com/blackbirdworks/semaphore/controlplane"
)
func main() {
manifest := &controlplane.Manifest{Channel: "prod", Generation: 1}
fmt.Println(controlplane.ValidateManifest(manifest, controlplane.WithMaxObjects(10)))
}
Output: <nil>
func ValidateSegments ¶
func ValidateSegments(doc *SegmentsDocument) error
ValidateSegments checks a segments document (an empty header means the current one). Header failures are returned as for ValidateManifest; the other problems are a *ValidationError whose problems have Kind EntrySegment, so a caller can keep the good segments. Of two segments with one name the first keeps it. It mirrors the validation of the engine's segment definition; the parity test of the flagcheck package keeps the two together.
func VerifyChecksum ¶
VerifyChecksum checks that data has the checksum want. It returns ErrUnsupportedChecksum for an algorithm other than sha256, ErrInvalidChecksum for a value that is not 64 lower-case hex characters (upper-case hex is invalid, not a mismatch) and a *ChecksumMismatchError (matches ErrChecksumMismatch) when the digest differs.
Example ¶
package main
import (
"fmt"
"github.com/blackbirdworks/semaphore/controlplane"
)
func main() {
sum := controlplane.ChecksumOf([]byte("hello"))
fmt.Println(controlplane.VerifyChecksum([]byte("hello"), sum))
fmt.Println(controlplane.VerifyChecksum([]byte("hellO"), sum) != nil)
}
Output: <nil> true
Types ¶
type Checksum ¶
type Checksum struct {
// Algorithm is AlgorithmSHA256.
Algorithm string `json:"algorithm" yaml:"algorithm"`
// Value is the lower-case hex digest.
Value string `json:"value" yaml:"value"`
}
Checksum is a content checksum: an algorithm and a lower-case hex value.
func ChecksumOf ¶
ChecksumOf returns the sha256 of the exact bytes, as lower-case hex. (The function is not named Checksum because that name is the wire type.)
type ChecksumMismatchError ¶
type ChecksumMismatchError struct {
// Want is the listed value.
Want string
// Got is the computed value.
Got string
}
ChecksumMismatchError carries the two digests of a failed VerifyChecksum.
func (*ChecksumMismatchError) Error ¶
func (e *ChecksumMismatchError) Error() string
Error implements error.
func (*ChecksumMismatchError) Is ¶
func (*ChecksumMismatchError) Is(target error) bool
Is reports a match with ErrChecksumMismatch.
type Code ¶
type Code string
Code is a stable, machine-readable reason of a FieldError.
const ( // CodeUnresolvedSource: a flag set source names no flags object of the manifest. CodeUnresolvedSource Code = "unresolved-source" // CodeDuplicateKey: an API key that an earlier flag set already holds. CodeDuplicateKey Code = "duplicate-key" // CodeDuplicateName: a name that an earlier entry already holds. CodeDuplicateName Code = "duplicate-name" // CodeInvalidName: a name that does not match ^[a-z][a-z0-9-]{0,62}$. CodeInvalidName Code = "invalid-name" // CodeUnsupportedVersion: an object whose content version is not supported. CodeUnsupportedVersion Code = "unsupported-version" // CodeInvalidChecksum: a checksum with another algorithm than sha256 or a malformed value. CodeInvalidChecksum Code = "invalid-checksum" // CodeInvalidValue: a value that is not allowed. CodeInvalidValue Code = "invalid-value" // CodeMissingValue: a required value is absent. CodeMissingValue Code = "missing-value" // CodeTooManyObjects: the manifest lists more objects than the limit. CodeTooManyObjects Code = "too-many-objects" // CodeUndeclaredVariation: a rule names a variation that the flag does not declare. CodeUndeclaredVariation Code = "undeclared-variation" )
The codes of a FieldError.
type DecodeError ¶
type DecodeError struct {
// Path addresses the field, such as "flagSets[0].apiKeys". Empty for the document.
Path string
// Reason says what is wrong, for example "expected a list".
Reason string
// Line is the line of the problem (1-based), or 0 when unknown.
Line int
}
DecodeError says where and why a document cannot be read. It never contains the text of a value (a value may be a secret such as an API key); Path holds field names and indexes only.
func (*DecodeError) Is ¶
func (*DecodeError) Is(target error) bool
Is reports a match with ErrDecode.
type DecodeInfo ¶
type DecodeInfo struct {
// UnknownFields lists the paths of fields that the structs of this package do not know, for example
// "objects[2].extra", sorted by key within each mapping. Published documents are forward compatible:
// unknown fields are reported, not fatal.
UnknownFields []string
}
DecodeInfo reports what a decoder noticed besides the document.
type EntryKind ¶
type EntryKind string
EntryKind says which entry of a document a FieldError belongs to.
const ( // EntryDocument: the document as a whole (header, channel, generation, object count). EntryDocument EntryKind = "document" // EntryObject: an entry of manifest.objects. EntryObject EntryKind = "object" // EntryFlagSet: an entry of flagSets. EntryFlagSet EntryKind = "flagSet" // EntrySegment: a segment of a segments document. EntrySegment EntryKind = "segment" // EntryFlag: a flag of a flag file. EntryFlag EntryKind = "flag" )
The entry kinds of a FieldError.
type Experimentation ¶
type Experimentation struct {
Start *time.Time `json:"start,omitempty" yaml:"start,omitempty"`
End *time.Time `json:"end,omitempty" yaml:"end,omitempty"`
}
Experimentation limits a flag to a time window.
type FieldError ¶
type FieldError struct {
// Path addresses the field, such as "objects[1].checksum.value".
Path string
// Reason says what is wrong, in words.
Reason string
// Code is the stable reason.
Code Code
// Kind is the kind of entry that has the problem.
Kind EntryKind
// Name is the name of the entry (object name, flag set name, flag name); empty for a document.
Name string
// Index is the position of the entry in its list, or NoIndex.
Index int
}
FieldError is one problem of a document. A caller can keep the entries without a problem and drop the others with Kind, Name and Index, without parsing text. The Reason never contains a secret such as an API key.
type Flag ¶
type Flag struct {
TrackEvents *bool `json:"trackEvents,omitempty" yaml:"trackEvents,omitempty"`
Disable *bool `json:"disable,omitempty" yaml:"disable,omitempty"`
Version *string `json:"version,omitempty" yaml:"version,omitempty"`
Converter *string `json:"converter,omitempty" yaml:"converter,omitempty"`
Variations map[string]any `json:"variations,omitempty" yaml:"variations,omitempty"`
Targeting []Rule `json:"targeting,omitempty" yaml:"targeting,omitempty"`
BucketingKey *string `json:"bucketingKey,omitempty" yaml:"bucketingKey,omitempty"`
DefaultRule *Rule `json:"defaultRule,omitempty" yaml:"defaultRule,omitempty"`
ScheduledRollout []ScheduledStep `json:"scheduledRollout,omitempty" yaml:"scheduledRollout,omitempty"`
Experimentation *Experimentation `json:"experimentation,omitempty" yaml:"experimentation,omitempty"`
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}
Flag is one flag of a flag file.
type FlagSet ¶
type FlagSet struct {
// Name is the unique name of the flag set.
Name string `json:"name" yaml:"name"`
// Sources are names of manifest objects of kind flags; a later source wins on a duplicate flag key.
Sources []string `json:"sources" yaml:"sources"`
// SegmentSources are names of manifest objects of kind segments; the segments that the rules of this flag set
// name with segment("name") are defined there. A name must be defined once in all the sources of a flag set.
SegmentSources []string `json:"segmentSources,omitempty" yaml:"segmentSources,omitempty"`
// APIKeys are plain inline keys (UUIDs). They are secrets: never log them.
APIKeys []string `json:"apiKeys,omitempty" yaml:"apiKeys,omitempty"`
}
FlagSet binds flag objects and API keys.
type FlagSetDocument ¶
type FlagSetDocument struct {
// APIVersion is the document version, "semaphore/v1". Empty means the current version when marshalling.
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
// Kind is "FlagSet". Empty means "FlagSet" when marshalling.
Kind string `json:"kind" yaml:"kind"`
// FlagSets are the flag-set definitions.
FlagSets []FlagSet `json:"flagSets" yaml:"flagSets"`
}
FlagSetDocument is the document of kind FlagSet.
type KindError ¶
type KindError struct {
// Got is the kind of the document.
Got string
// Want is the kind that was asked for.
Want string
}
KindError is returned for a document of another kind than the one asked for.
type Manifest ¶
type Manifest struct {
// APIVersion is the document version, "semaphore/v1". Empty means the current version when marshalling.
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
// Kind is "Manifest". Empty means "Manifest" when marshalling.
Kind string `json:"kind" yaml:"kind"`
// Channel names the channel (environment) of the manifest.
Channel string `json:"channel" yaml:"channel"`
// Generation increases strictly with every publication of a channel, starting at 1.
Generation uint64 `json:"generation" yaml:"generation"`
// CreatedAt is informational.
CreatedAt *time.Time `json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
// Objects are the source objects.
Objects []ManifestObject `json:"objects" yaml:"objects"`
}
Manifest lists the objects of one channel at one generation. It is the pointer to the current state and is written last by a publisher.
type ManifestObject ¶
type ManifestObject struct {
// Name is the logical name, unique in the manifest; flag sets reference objects by it.
Name string `json:"name" yaml:"name"`
// Kind is KindFlags, KindFlagSets or KindSegments.
Kind string `json:"kind" yaml:"kind"`
// Connection names a connection of the relay bootstrap file; it fixes endpoint, bucket and credentials.
Connection string `json:"connection" yaml:"connection"`
// Key is the key of the object in the bucket of the connection.
Key string `json:"key" yaml:"key"`
// Format is FormatYAML, FormatJSON or (flags only) FormatTOML.
Format string `json:"format" yaml:"format"`
// Version is the version of the content schema; 0 means ObjectVersion1.
Version int `json:"version,omitempty" yaml:"version,omitempty"`
// Checksum is the checksum of the exact stored bytes.
Checksum Checksum `json:"checksum" yaml:"checksum"`
// Size is the size of the stored bytes.
Size int64 `json:"size" yaml:"size"`
// VersionID is an optional object version id of the store.
VersionID string `json:"versionId,omitempty" yaml:"versionId,omitempty"`
}
ManifestObject is one source object of a manifest.
type MemberList ¶
type MemberList []string
MemberList is the member list of a static segment. It is a list of strings like any other, except that the decoder rejects an item that is null or is not a string (it would otherwise drop the first and turn the other into text).
type ProgressiveRollout ¶
type ProgressiveRollout struct {
Initial *ProgressiveRolloutStep `json:"initial,omitempty" yaml:"initial,omitempty"`
End *ProgressiveRolloutStep `json:"end,omitempty" yaml:"end,omitempty"`
}
ProgressiveRollout ramps a rule from an initial to an end step.
type ProgressiveRolloutStep ¶
type ProgressiveRolloutStep struct {
Variation *string `json:"variation,omitempty" yaml:"variation,omitempty"`
Percentage *float64 `json:"percentage,omitempty" yaml:"percentage,omitempty"`
Date *time.Time `json:"date,omitempty" yaml:"date,omitempty"`
}
ProgressiveRolloutStep is one end of a progressive rollout.
type Rule ¶
type Rule struct {
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Query *string `json:"query,omitempty" yaml:"query,omitempty"`
Variation *string `json:"variation,omitempty" yaml:"variation,omitempty"`
Percentage map[string]float64 `json:"percentage,omitempty" yaml:"percentage,omitempty"`
ProgressiveRollout *ProgressiveRollout `json:"progressiveRollout,omitempty" yaml:"progressiveRollout,omitempty"`
Disable *bool `json:"disable,omitempty" yaml:"disable,omitempty"`
OnError *string `json:"onError,omitempty" yaml:"onError,omitempty"`
}
Rule is a targeting rule or the default rule.
type ScheduledStep ¶
type ScheduledStep struct {
Date *time.Time `json:"date,omitempty" yaml:"date,omitempty"`
TrackEvents *bool `json:"trackEvents,omitempty" yaml:"trackEvents,omitempty"`
Disable *bool `json:"disable,omitempty" yaml:"disable,omitempty"`
Version *string `json:"version,omitempty" yaml:"version,omitempty"`
Variations map[string]any `json:"variations,omitempty" yaml:"variations,omitempty"`
Targeting []Rule `json:"targeting,omitempty" yaml:"targeting,omitempty"`
BucketingKey *string `json:"bucketingKey,omitempty" yaml:"bucketingKey,omitempty"`
DefaultRule *Rule `json:"defaultRule,omitempty" yaml:"defaultRule,omitempty"`
Experimentation *Experimentation `json:"experimentation,omitempty" yaml:"experimentation,omitempty"`
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}
ScheduledStep updates fields of a flag at a date. The flag fields are the optional fields of Flag that the engine allows in a step (a nested scheduledRollout is not part of the format).
type SegmentCache ¶
type SegmentCache struct {
// MaxEntries is the most cached answers.
MaxEntries int `json:"maxEntries,omitempty" yaml:"maxEntries,omitempty"`
// TTL is how long an answer is cached, a duration such as "30s".
TTL string `json:"ttl,omitempty" yaml:"ttl,omitempty"`
}
SegmentCache sizes the cache of a lookup segment.
type SegmentDefinition ¶
type SegmentDefinition struct {
// Name is the name that rules use: segment("name").
Name string `json:"name" yaml:"name"`
// Connection names a connection of the relay bootstrap file: a dynamic segment.
Connection string `json:"connection,omitempty" yaml:"connection,omitempty"`
// Members are the members of a static segment. An empty list is a static segment with no member.
Members MemberList `json:"members,omitempty" yaml:"members,omitempty"`
// Mode is "snapshot" (default) or "lookup" (dynamic only).
Mode string `json:"mode,omitempty" yaml:"mode,omitempty"`
// Key is the key of the set (layout set) or the prefix of the member keys (layout keys) in the store.
Key string `json:"key,omitempty" yaml:"key,omitempty"`
// Layout is "set" (default) or "keys". The keys layout is lookup only.
Layout string `json:"layout,omitempty" yaml:"layout,omitempty"`
// MissingKey is "notMember" (default) or "unknown": what a segment that does not exist in the store means.
MissingKey string `json:"missingKey,omitempty" yaml:"missingKey,omitempty"`
// OnError is what a lookup that could not be answered becomes: "notMember" (default), "unknown" or "member".
OnError string `json:"onError,omitempty" yaml:"onError,omitempty"`
// Version says how the version of the segment is learned (dynamic only).
Version *SegmentVersion `json:"version,omitempty" yaml:"version,omitempty"`
// Cache sizes the cache of a lookup segment.
Cache *SegmentCache `json:"cache,omitempty" yaml:"cache,omitempty"`
}
SegmentDefinition is one segment. It has no type: with a Connection it is a dynamic segment (its members are in a store, and the store kind is the one of the connection of the relay bootstrap file), without one it is a static segment with its Members inline. Exactly one of the two must be given.
type SegmentVersion ¶
type SegmentVersion struct {
// Value is a version that the document carries.
Value string `json:"value,omitempty" yaml:"value,omitempty"`
// Key is the version key in the store.
Key string `json:"key,omitempty" yaml:"key,omitempty"`
// Interval is the poll period of Key, a duration such as "5s" (needs Key).
Interval string `json:"interval,omitempty" yaml:"interval,omitempty"`
}
SegmentVersion is the version of a dynamic segment: the publisher bumps Value, or the writer of the members bumps the version key Key in the store, which the relay polls every Interval. Value and Key are exclusive.
type SegmentsDocument ¶
type SegmentsDocument struct {
// APIVersion is the document version, "semaphore/v1". Empty means the current version when marshalling.
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
// Kind is "Segments". Empty means "Segments" when marshalling.
Kind string `json:"kind" yaml:"kind"`
// Segments are the definitions.
Segments []SegmentDefinition `json:"segments" yaml:"segments"`
}
SegmentsDocument is the document of kind Segments: named segment definitions.
type UnsupportedVersionError ¶
type UnsupportedVersionError struct {
// Got is the apiVersion of the document.
Got string
// Supported is the apiVersion this package reads.
Supported string
}
UnsupportedVersionError is returned for a document whose apiVersion is not supported.
func (*UnsupportedVersionError) Error ¶
func (e *UnsupportedVersionError) Error() string
Error implements error.
func (*UnsupportedVersionError) Is ¶
func (*UnsupportedVersionError) Is(target error) bool
Is reports a match with ErrUnsupportedAPIVersion and ErrInvalid.
type ValidateOption ¶
type ValidateOption func(*validateConfig)
ValidateOption changes how a Validate function checks.
func WithMaxObjects ¶
func WithMaxObjects(limit int) ValidateOption
WithMaxObjects sets the largest number of objects a manifest may list (default DefaultMaxObjects). A value of zero or less keeps the default.
type ValidationError ¶
type ValidationError struct {
// Problems are the problems in document order.
Problems []FieldError
}
ValidationError lists every problem found by a Validate function.
func (*ValidationError) Is ¶
func (*ValidationError) Is(target error) bool
Is reports a match with ErrInvalid.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package filepublish is the file-store counterpart of an S3 bucket for s3publish.Publisher: a Store implements s3publish.API over a directory, so the upload protocol (objects first, manifest last, conditional write of the manifest) is the one of S3 and is not copied.
|
Package filepublish is the file-store counterpart of an S3 bucket for s3publish.Publisher: a Store implements s3publish.API over a directory, so the upload protocol (objects first, manifest last, conditional write of the manifest) is the one of S3 and is not copied. |
|
Package flagcheck validates the bytes of a flag object with the engine of the relay: the same decoder and the same validity checks the relay applies when it loads a flag file, and that "semaphore-cli lint" applies.
|
Package flagcheck validates the bytes of a flag object with the engine of the relay: the same decoder and the same validity checks the relay applies when it loads a flag file, and that "semaphore-cli lint" applies. |
|
Package manifestsig signs and verifies the bytes of a control-plane manifest with ed25519 (standard library only).
|
Package manifestsig signs and verifies the bytes of a control-plane manifest with ed25519 (standard library only). |
|
Package s3publish publishes control-plane documents to an S3 bucket so that a reader polling the manifest never sees a half-written state.
|
Package s3publish publishes control-plane documents to an S3 bucket so that a reader polling the manifest never sees a half-written state. |