Documentation
¶
Overview ¶
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.
The check is what the relay would do, so a flag that passes here is not dropped at load time. Besides the structural rules of controlplane.ValidateFlags it compiles the targeting queries, checks the percentages, the variations and the rollouts, as the engine does.
The package imports the engine, which is heavy. It is separate from controlplane and from s3publish on purpose: a publisher that only needs the document format does not pull it in.
Index ¶
- Variables
- func Check(body []byte, format string) error
- func CheckPublicDuplicates(sets []KeylessSet) error
- func CheckSegmentReferences(flagSet string, flags []FlagFile, sources []SegmentFile) error
- func CheckSegments(body []byte) error
- func Definition(seg *controlplane.SegmentDefinition) (segment.Definition, bool)
- func Winners(flags []FlagFile) map[string]string
- type Error
- type FlagFile
- type FlagProblem
- type KeylessSet
- type PublicError
- type PublicOwner
- type PublicProblem
- type ReferenceError
- type ReferenceProblem
- type SegmentFile
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("flagcheck: invalid flag file")
ErrInvalid is matched (errors.Is) by every *Error, and by the failure to decode the file.
var ErrPublicDuplicate = errors.New("flagcheck: a flag key is defined in two keyless flag sets")
ErrPublicDuplicate is matched (errors.Is) by the error of CheckPublicDuplicates.
var ErrSegments = errors.New("flagcheck: invalid segments")
ErrSegments is matched (errors.Is) by the errors of the segment checks of this package.
Functions ¶
func Check ¶
Check decodes a flag file in the given format ("yaml", "json" or "toml") with the loader of the relay and validates every flag. It returns nil, an error that matches ErrInvalid and wraps the decoding failure, or an *Error.
func CheckPublicDuplicates ¶
func CheckPublicDuplicates(sets []KeylessSet) error
CheckPublicDuplicates checks the flag sets that are published without API keys. The relay merges them into one public view and rejects a generation in which two of them define the same flag key (flagruntime.PublicName), so a publication must not contain one. The flags of a flag set are those of its flag files merged in order (Winners). It returns nil or a *PublicError that lists every such flag key in key order, with its flag sets in name order.
func CheckSegmentReferences ¶
func CheckSegmentReferences(flagSet string, flags []FlagFile, sources []SegmentFile) error
CheckSegmentReferences checks the segments of one flag set: a segment name must be defined once in all its segment sources, and every segment("name") that a targeting rule of a flag uses must be defined there. A flag set that has no segment source and no rule that uses a segment is fine. The queries are read with the engine's own reader of the segment terms of a rule. It returns nil or a *ReferenceError.
func CheckSegments ¶
CheckSegments decodes a segments document, validates it with the rules of the controlplane package, and then validates every segment with the validation of the engine, so that a segment that passes is not dropped when the relay builds its catalog. It returns nil, or an error that matches ErrSegments.
func Definition ¶
func Definition(seg *controlplane.SegmentDefinition) (segment.Definition, bool)
Definition converts a segment of a segments document to the definition of the engine. A segment with a connection is a dynamic segment: its store kind is not known to a publisher, so the definition has the type of a Redis store, which the engine validates like the other store types. A static segment is of the type file. The second result is false when a field cannot be converted (a duration that does not parse): the document validation reports it.
func Winners ¶
Winners tells, for each flag key of the flag files of a flag set (in the order of its sources), the name of the object whose definition the flag set serves: a later source wins on a duplicate key. It follows the merge of the relay; a test of the relay keeps the two together. A file that does not decode has no flag here.
Types ¶
type Error ¶
type Error struct {
Problems []FlagProblem
}
Error lists the flags that the engine rejects, sorted by flag key.
type FlagFile ¶
type FlagFile struct {
// Name is the name of the manifest object.
Name string
// Format is "yaml" or "json".
Format string
// Body is the flag file.
Body []byte
}
FlagFile is one flag object of a flag set.
type FlagProblem ¶
type FlagProblem struct {
// Err is the reason given by the engine, as it is: it may quote the file (a query, a value), so do not log it
// where an API key matters. Error() of the *Error does not carry that text.
Err error
// Flag is the key of the flag.
Flag string
}
FlagProblem is one flag that the engine rejects.
func (FlagProblem) Message ¶
func (p FlagProblem) Message() string
Message is the text for one problem: "flag <key>: <category>". It is safe to print and to log: the key, and the category of the engine's reason, never the text of the engine (see Err).
type KeylessSet ¶
type KeylessSet struct {
// Name is the name of the flag set.
Name string
// Flags are the flag files of its sources, in the order of the sources.
Flags []FlagFile
}
KeylessSet is a flag set that is published without API keys, with the flag files of its sources in order.
type PublicError ¶
type PublicError struct {
Problems []PublicProblem
}
PublicError lists the flag keys that CheckPublicDuplicates rejects, sorted by key.
func (*PublicError) Error ¶
func (e *PublicError) Error() string
Error implements error: one entry per flag key (see PublicProblem.Message), separated by "; ".
func (*PublicError) Is ¶
func (*PublicError) Is(target error) bool
Is reports a match with ErrPublicDuplicate.
type PublicOwner ¶
type PublicOwner struct {
// FlagSet is the name of the flag set.
FlagSet string
// Object is the flag object of the flag set whose definition it serves.
Object string
}
PublicOwner is one keyless flag set that defines a flag key.
type PublicProblem ¶
type PublicProblem struct {
// Flag is the flag key.
Flag string
// Owners are the keyless flag sets that define it, sorted by name.
Owners []PublicOwner
}
PublicProblem is one flag key that two or more keyless flag sets define.
func (PublicProblem) Message ¶
func (p PublicProblem) Message() string
Message is the text for one flag key: "flag <key>: defined in the keyless flag sets <set> (flag object <object>) and <set> (flag object <object>)". The sets are in name order.
type ReferenceError ¶
type ReferenceError struct {
// FlagSet is the name of the flag set.
FlagSet string
// Problems are the problems, in order.
Problems []ReferenceProblem
}
ReferenceError lists the problems of CheckSegmentReferences.
func (*ReferenceError) Is ¶
func (*ReferenceError) Is(target error) bool
Is reports a match with ErrSegments.
func (*ReferenceError) Unwrap ¶
func (e *ReferenceError) Unwrap() []error
Unwrap lists the problems as errors of their own, so that a report can show one line for each.
type ReferenceProblem ¶
type ReferenceProblem struct {
// Object is the flag object, or the segments object for a duplicate name.
Object string
// Flag is the key of the flag that uses the segment (empty for a duplicate name).
Flag string
// Segment is the name of the segment.
Segment string
// Reason says what is wrong.
Reason string
// Rule is the position of the targeting rule in the flag, or -1.
Rule int
}
ReferenceProblem is one reference to a segment that cannot be resolved, or one name that is defined twice.
type SegmentFile ¶
type SegmentFile struct {
// Doc is the decoded document. Nil means that the object was not read (another connection, skipped by Verify):
// the names that it could define are unknown, so a reference is not reported as undefined while one is not read.
Doc *controlplane.SegmentsDocument
// Name is the name of the manifest object.
Name string
}
SegmentFile is one segments object of a flag set.