diff --git a/pkg/feature/feature.go b/pkg/feature/feature.go index 2957ed26..13351e3c 100644 --- a/pkg/feature/feature.go +++ b/pkg/feature/feature.go @@ -361,6 +361,7 @@ type Feature struct { Value interface{} FeatureType eval.ConfigType Namespace string + Metadata map[string]any Overrides []*Override UnitTests []UnitTest diff --git a/pkg/star/feature.go b/pkg/star/feature.go index eef59491..ed3878c9 100644 --- a/pkg/star/feature.go +++ b/pkg/star/feature.go @@ -155,6 +155,10 @@ func (fb *featureBuilder) Build() (*feature.CompiledFeature, error) { return nil, errors.Wrap(err, "description") } f.Namespace = fb.namespace + f.Metadata, err = fb.getMetadata(featureVal) + if err != nil { + return nil, errors.Wrap(err, "metadata") + } overrideVals, err := fb.addOverrides(f, featureVal) if err != nil { @@ -297,10 +301,11 @@ func (fb *featureBuilder) getDescription(featureVal *starlarkstruct.Struct) (str return dsc.GoString(), nil } -func (fb *featureBuilder) getMetadata(featureVal *starlarkstruct.Struct) (*structpb.Value, error) { +func (fb *featureBuilder) getMetadata(featureVal *starlarkstruct.Struct) (map[string]any, error) { metadataVal, err := featureVal.Attr(MetadataAttrName) if err != nil { - return nil, errors.Wrap(err, "metadata attribute") + //lint:ignore nilerr `Struct.Attr` returns error if attribute doesn't exist + return nil, nil } metadataDict, ok := metadataVal.(*starlark.Dict) if !ok { @@ -310,7 +315,7 @@ func (fb *featureBuilder) getMetadata(featureVal *starlarkstruct.Struct) (*struc if err != nil { return nil, errors.Wrap(err, "translate metadata attribute") } - return structpb.NewValue(metadataMap) + return metadataMap, nil } func (fb *featureBuilder) addOverrides(f *feature.Feature, featureVal *starlarkstruct.Struct) ([]starlark.Value, error) { diff --git a/pkg/star/static/traverse.go b/pkg/star/static/traverse.go index 406f5589..aea6534f 100644 --- a/pkg/star/static/traverse.go +++ b/pkg/star/static/traverse.go @@ -41,7 +41,7 @@ func defaultNoop(v *build.Expr) error { return nil } func descriptionNoop(v *build.StringExpr) error { return nil } func rulesNoop(rules *overridesWrapper) error { return nil } func importsNoop(imports *importsWrapper) error { return nil } -func metadataNoop(ast *starFeatureAST) error { return nil} +func metadataNoop(ast *starFeatureAST) error { return nil } type defaultFn func(v *build.Expr) error type descriptionFn func(v *build.StringExpr) error @@ -71,7 +71,7 @@ func newTraverser(f *build.File, nv feature.NamespaceVersion) *traverser { descriptionFn: descriptionNoop, overridesFn: rulesNoop, protoImportsFn: importsNoop, - metadataFn: metadataNoop, + metadataFn: metadataNoop, } } @@ -98,7 +98,7 @@ func (t *traverser) withProtoImportsFn(fn importsFn) *traverser { func (t *traverser) withMetadataFn(fn metadataFn) *traverser { t.metadataFn = fn return t -} +} func (t *traverser) traverse() error { imports := t.getProtoImports() @@ -339,10 +339,6 @@ type importVal struct { assignExpr *build.AssignExpr } -type metadataWrapper struct { - metadataExpr *build.DictExpr -} - func newOverride(li build.Expr) (*override, error) { tupleV, ok := li.(*build.TupleExpr) if !ok { diff --git a/pkg/star/static/walk.go b/pkg/star/static/walk.go index 1b5587cf..8816a9bf 100644 --- a/pkg/star/static/walk.go +++ b/pkg/star/static/walk.go @@ -514,7 +514,7 @@ func (w *walker) mutateMetadataFn(f *featurev1beta1.StaticFeature) metadataFn { if metadataProto == nil { return nil } - metadataStarDict, err := w.genJSONValue(metadataProto, nil) + metadataStarDict, err := w.genJSONValue(metadataProto, nil) if err != nil { return err }