Skip to content

Commit

Permalink
chore: support targetingKey
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps authored and thepabloaguilar committed Jul 26, 2024
1 parent 81eb93c commit 0f94078
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d/go.
google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
Expand Down
13 changes: 9 additions & 4 deletions internal/server/evaluation/ofrep_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"go.opentelemetry.io/otel/trace"
)

const ofrepCtxTargetingKey = "targetingKey"

func (s *Server) OFREPEvaluationBridge(ctx context.Context, input ofrep.EvaluationBridgeInput) (ofrep.EvaluationBridgeOutput, error) {
flag, err := s.store.GetFlag(ctx, storage.NewResource(input.NamespaceKey, input.FlagKey))
if err != nil {
Expand All @@ -33,10 +35,13 @@ func (s *Server) OFREPEvaluationBridge(ctx context.Context, input ofrep.Evaluati
req := &rpcevaluation.EvaluationRequest{
NamespaceKey: input.NamespaceKey,
FlagKey: input.FlagKey,
// OFREP does not have the idea of an `entity` and this is why we're generating one here.
// I might change in the future as the specification grows.
EntityId: uuid.NewString(),
Context: input.Context,
EntityId: uuid.NewString(),
Context: input.Context,
}

// https://openfeature.dev/docs/reference/concepts/evaluation-context/#targeting-key
if targetingKey, ok := input.Context[ofrepCtxTargetingKey]; ok {
req.EntityId = targetingKey
}

switch flag.Type {
Expand Down
7 changes: 6 additions & 1 deletion internal/server/evaluation/ofrep_bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func TestOFREPEvaluationBridge_Variant(t *testing.T) {
FlagKey: flagKey,
NamespaceKey: namespaceKey,
Context: map[string]string{
"hello": "world",
"hello": "world",
"targetingKey": "12345",
},
})
require.NoError(t, err)
Expand Down Expand Up @@ -92,6 +93,10 @@ func TestOFREPEvaluationBridge_Boolean(t *testing.T) {
output, err := s.OFREPEvaluationBridge(context.TODO(), ofrep.EvaluationBridgeInput{
FlagKey: flagKey,
NamespaceKey: namespaceKey,
Context: map[string]string{
"hello": "world",
"targetingKey": "12345",
},
})
require.NoError(t, err)

Expand Down

0 comments on commit 0f94078

Please sign in to comment.