Skip to content

Commit 341330d

Browse files
author
Dave Johnston
committed
[FFM-1355]: SDK doesnt support multiple custom attributes and name not set correctly
The Target builder replaces the attributes map with every new custom attribute. This means we only ever could have one custom attribute. Name was stored as a custom attribute instead of as a named field, the problem is if you have the Java SDK using the same target, then it sends 'name' as a named field, and so conflicts with custom attributes. This PR fixes the issue with the custom attributes and ensures name is stored in a named field.
1 parent 0db9ea1 commit 341330d

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

analyticsservice/analytics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func (as *AnalyticsService) sendDataAndResetCache(ctx context.Context) {
151151
}
152152

153153
targetName := analytic.target.Identifier
154-
if analytic.target.Name != nil {
155-
targetName = *analytic.target.Name
154+
if analytic.target.Name != "" {
155+
targetName = analytic.target.Name
156156
}
157157

158158
td := metricsclient.TargetData{

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (c *CfClient) authenticate(ctx context.Context, target evaluation.Target) {
191191
target.Anonymous,
192192
target.Attributes,
193193
target.Identifier,
194-
target.Name,
194+
&target.Name,
195195
}
196196
c.auth.Target = &t
197197
c.mux.RLock()

dto/target_builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (b *targetBuilder) Lastname(lastname string) TargetBuilderInterface {
6363

6464
// Name target name object
6565
func (b *targetBuilder) Name(name string) TargetBuilderInterface {
66-
b.Custom("name", name)
66+
b.Target.Name = name
6767
return b
6868
}
6969

@@ -76,8 +76,8 @@ func (b *targetBuilder) Anonymous(value bool) TargetBuilderInterface {
7676
// Custom object
7777
func (b *targetBuilder) Custom(key string, value interface{}) TargetBuilderInterface {
7878
m := make(map[string]interface{})
79-
if b.Target.Attributes == nil {
80-
b.Target.Attributes = &m
79+
if b.Target.Attributes != nil {
80+
m = *b.Target.Attributes
8181
}
8282
m[key] = value
8383
b.Target.Attributes = &m

evaluation/target.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package evaluation
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/drone/ff-golang-server-sdk/types"
78

@@ -11,7 +12,7 @@ import (
1112
// Target object
1213
type Target struct {
1314
Identifier string
14-
Name *string
15+
Name string
1516
Anonymous *bool
1617
Attributes *map[string]interface{}
1718
}
@@ -24,7 +25,14 @@ func (t Target) GetAttrValue(attr string) reflect.Value {
2425
if ok {
2526
value = reflect.ValueOf(attrVal)
2627
} else {
27-
value = GetStructFieldValue(t, attr)
28+
// We only have two fields here, so we will access the fields directly, and use reflection if we start adding
29+
// more in the future
30+
switch strings.ToLower(attr) {
31+
case "identifier":
32+
value = reflect.ValueOf(t.Identifier)
33+
case "name":
34+
value = reflect.ValueOf(t.Name)
35+
}
2836
}
2937
return value
3038
}

0 commit comments

Comments
 (0)