Skip to content

Commit 5ed9c16

Browse files
authored
fix: flag metadata parsing from snapshot (#4384)
1 parent 83a1aa1 commit 5ed9c16

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

internal/storage/fs/snapshot.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"go.flipt.io/flipt/internal/storage"
2121
"go.flipt.io/flipt/rpc/flipt"
2222
"go.uber.org/zap"
23+
"google.golang.org/protobuf/types/known/structpb"
2324
"google.golang.org/protobuf/types/known/timestamppb"
2425
"gopkg.in/yaml.v3"
2526
)
@@ -378,6 +379,14 @@ func (ss *Snapshot) addDoc(doc *ext.Document) error {
378379
UpdatedAt: ss.now,
379380
}
380381

382+
if f.Metadata != nil {
383+
metadata, err := structpb.NewStruct(f.Metadata)
384+
if err != nil {
385+
return err
386+
}
387+
flag.Metadata = metadata
388+
}
389+
381390
for _, v := range f.Variants {
382391
attachment, err := json.Marshal(v.Attachment)
383392
if err != nil {

internal/storage/fs/snapshot_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"go.flipt.io/flipt/internal/storage"
1818
"go.flipt.io/flipt/rpc/flipt"
1919
"go.uber.org/zap/zaptest"
20+
"google.golang.org/protobuf/types/known/structpb"
2021
)
2122

2223
//go:embed all:testdata
@@ -158,6 +159,12 @@ func (fis *FSIndexSuite) TestGetFlag() {
158159
NamespaceKey: "production",
159160
},
160161
},
162+
Metadata: &structpb.Struct{
163+
Fields: map[string]*structpb.Value{
164+
"foo": {Kind: &structpb.Value_StringValue{StringValue: "bar"}},
165+
"number": {Kind: &structpb.Value_NumberValue{NumberValue: 42}},
166+
},
167+
},
161168
},
162169
},
163170
{
@@ -194,6 +201,7 @@ func (fis *FSIndexSuite) TestGetFlag() {
194201
assert.Equal(t, tc.flag.NamespaceKey, flag.NamespaceKey)
195202
assert.Equal(t, tc.flag.Name, flag.Name)
196203
assert.Equal(t, tc.flag.Description, flag.Description)
204+
assert.Equal(t, tc.flag.Metadata, flag.Metadata)
197205

198206
for i := 0; i < len(flag.Variants); i++ {
199207
v := tc.flag.Variants[i]

internal/storage/fs/testdata/valid/explicit_index/prod/prod.features.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ flags:
44
name: Prod Flag
55
description: description
66
enabled: true
7+
metadata:
8+
foo: bar
9+
number: 42
710
variants:
811
- key: prod-variant
912
name: Prod Variant

0 commit comments

Comments
 (0)