Documentation ¶
Overview ¶
This package governs the specifics of a feature, like what individual files make up a feature.
Index ¶
- Variables
- func ComplianceCheck(f FeatureFile, nsMD *metadata.NamespaceConfigRepoMetadata) error
- func ParseFeaturePath(featurePath string) (namespaceName string, featureName string, err error)
- func ProtoToJSON(fProto *lekkov1beta1.Feature, registry *protoregistry.Types) ([]byte, error)
- func ValToAny(value interface{}) (*anypb.Any, error)
- type CompiledFeature
- type EvaluableFeature
- type Feature
- func FromProto(fProto *lekkov1beta1.Feature) (*Feature, error)
- func NewBoolFeature(value bool) *Feature
- func NewComplexFeature(value protoreflect.ProtoMessage) *Feature
- func NewEncodedJSONFeature(encodedJSON []byte) (*Feature, error)
- func NewFloatFeature(value float64) *Feature
- func NewIntFeature(value int64) *Feature
- func NewJSONFeature(value *structpb.Value) *Feature
- func NewStringFeature(value string) *Feature
- func (f *Feature) AddBoolRule(rule string, ast *rulesv1beta2.Rule, val bool) error
- func (f *Feature) AddFloatRule(rule string, ast *rulesv1beta2.Rule, val float64) error
- func (f *Feature) AddIntRule(rule string, ast *rulesv1beta2.Rule, val int64) error
- func (f *Feature) AddJSONRule(rule string, ast *rulesv1beta2.Rule, val *structpb.Value) error
- func (f *Feature) AddJSONUnitTest(context map[string]interface{}, val *structpb.Value, starCtx, starVal string) error
- func (f *Feature) AddStringRule(rule string, ast *rulesv1beta2.Rule, val string) error
- func (f *Feature) PrintJSON(registry *protoregistry.Types)
- func (f *Feature) RunUnitTests() ([]*TestResult, error)
- func (f *Feature) ToEvaluableFeature() (EvaluableFeature, error)
- func (f *Feature) ToJSON(registry *protoregistry.Types) ([]byte, error)
- func (f *Feature) ToProto() (*lekkov1beta1.Feature, error)
- type FeatureContents
- type FeatureFile
- type FeatureType
- type ResultPath
- type Rule
- type TestResult
- type UnitTest
- type ValidatorResult
- type ValidatorResultType
Constants ¶
This section is empty.
Variables ¶
var ErrTypeMismatch = fmt.Errorf("type mismatch")
Functions ¶
func ComplianceCheck ¶
func ComplianceCheck(f FeatureFile, nsMD *metadata.NamespaceConfigRepoMetadata) error
func ParseFeaturePath ¶
func ProtoToJSON ¶
func ProtoToJSON(fProto *lekkov1beta1.Feature, registry *protoregistry.Types) ([]byte, error)
Types ¶
type CompiledFeature ¶
type CompiledFeature struct { Feature *Feature TestResults []*TestResult ValidatorResults []*ValidatorResult }
Contains the compiled feature model, along with any validator results and unit test results that were collected as part of compilation.
type EvaluableFeature ¶
type EvaluableFeature interface { // Evaluate Feature returns a protobuf.Any. // For user defined protos, we shouldn't attempt to Unmarshal // this unless we know the type. For primitive types, we can // safely unmarshal into BoolValue, StringValue, etc. Evaluate(evalContext map[string]interface{}) (*anypb.Any, ResultPath, error) }
func NewV1Beta3 ¶
func NewV1Beta3(f *featurev1beta1.Feature) EvaluableFeature
type Feature ¶
type Feature struct {
Key, Description string
Value interface{}
FeatureType FeatureType
Rules []*Rule
UnitTests []*UnitTest
}
func NewBoolFeature ¶
func NewComplexFeature ¶
func NewComplexFeature(value protoreflect.ProtoMessage) *Feature
func NewEncodedJSONFeature ¶
func NewFloatFeature ¶
func NewIntFeature ¶
func NewJSONFeature ¶
func NewStringFeature ¶
func (*Feature) AddBoolRule ¶
func (*Feature) AddFloatRule ¶
func (*Feature) AddIntRule ¶
func (*Feature) AddJSONRule ¶
func (*Feature) AddJSONUnitTest ¶
func (*Feature) AddStringRule ¶
func (*Feature) PrintJSON ¶
func (f *Feature) PrintJSON(registry *protoregistry.Types)
func (*Feature) RunUnitTests ¶
func (f *Feature) RunUnitTests() ([]*TestResult, error)
func (*Feature) ToEvaluableFeature ¶
func (f *Feature) ToEvaluableFeature() (EvaluableFeature, error)
type FeatureContents ¶
type FeatureContents struct { File *FeatureFile Star []byte JSON []byte Proto []byte SHA string }
type FeatureFile ¶
type FeatureFile struct { Name string // Filename of the featureName.star file. StarlarkFileName string // Filename of an featureName.proto file. // This is optional. ProtoFileName string // Filename of a compiled .json file. CompiledJSONFileName string // Filename of a compiled .proto.bin file. CompiledProtoBinFileName string // name of the namespace directory NamespaceName string }
FeatureFile is a parsed feature from an on desk representation. This is intended to remain stable across feature versions.
func GroupFeatureFiles ¶
func GroupFeatureFiles( ctx context.Context, pathToNamespace string, fsProvider fs.Provider, ) ([]FeatureFile, error)
This groups feature files in a way that is governed by the namespace metadata. TODO naming conventions.
func NewFeatureFile ¶
func NewFeatureFile(nsName, featureName string) FeatureFile
func (FeatureFile) RootPath ¶
func (ff FeatureFile) RootPath(filename string) string
func (FeatureFile) Verify ¶
func (ff FeatureFile) Verify() error
type FeatureType ¶
type FeatureType string
Indicates the lekko-specific types that are allowed in feature flags.
const ( FeatureTypeBool FeatureType = "bool" FeatureTypeInt FeatureType = "int" FeatureTypeFloat FeatureType = "float" FeatureTypeString FeatureType = "string" FeatureTypeProto FeatureType = "proto" FeatureTypeJSON FeatureType = "json" )
type ResultPath ¶
type ResultPath []int
Stores the path of the tree node that returned the final value after successful evaluation. See the readme for an illustration.
type Rule ¶
type Rule struct { Condition string // source of truth ConditionAST *rulesv1beta2.Rule // by-product of Condition Value interface{} }
type TestResult ¶
type TestResult struct { Test string // a string representation of the test, as written in starlark TestIndex int // The index of the test in the list of tests. Error error // human-readable error }
This struct holds information about a test run.
func NewTestResult ¶
func NewTestResult(testStar string, testIndex int) *TestResult
func (*TestResult) DebugString ¶
func (tr *TestResult) DebugString() string
func (*TestResult) Identifier ¶
func (tr *TestResult) Identifier() string
Creates a short string - a human-readable version of this unit test that is helpful for debugging and printing errors. e.g. 'test 1 ["{"org"...]' idx refers to the index of the unit test in the list of unit tests written in starlark.
func (*TestResult) Passed ¶
func (tr *TestResult) Passed() bool
func (*TestResult) WithError ¶
func (tr *TestResult) WithError(err error) *TestResult
type UnitTest ¶
type UnitTest struct { Context map[string]interface{} ExpectedValue interface{} // The starlark textual representation of the context and expected value. // These fields are helpful for print statements. ContextStar, ExpectedValueStar string }
func NewUnitTest ¶
func (UnitTest) Run ¶
func (ut UnitTest) Run(idx int, eval EvaluableFeature) *TestResult
type ValidatorResult ¶
type ValidatorResult struct { // Indicates whether this validator result applies on a rule value, the default value, or a test value. Type ValidatorResultType // If this is a rule value validator result, specifies the index of the rule that this result applies to. // If this is a test value validator result, specifies the index of the unit test that this result applies to. Index int // A string representation of the starlark value that was invalid Value string Error error // human-readable error describing what the validation error was }
Holds the results of validation checks performed on the compiled feature. Since a validation check is done on a single final feature value, There will be 1 validator result for the default value and 1 for each subsequent rule.
func NewValidatorResult ¶
func NewValidatorResult(t ValidatorResultType, index int, starVal string) *ValidatorResult
func (*ValidatorResult) DebugString ¶
func (vr *ValidatorResult) DebugString() string
func (*ValidatorResult) Identifier ¶
func (vr *ValidatorResult) Identifier() string
func (*ValidatorResult) Passed ¶
func (vr *ValidatorResult) Passed() bool
func (*ValidatorResult) WithError ¶
func (vr *ValidatorResult) WithError(err error) *ValidatorResult
type ValidatorResultType ¶
type ValidatorResultType int
const ( ValidatorResultTypeDefault ValidatorResultType = iota ValidatorResultTypeRule ValidatorResultTypeTest )