Skip to content

Commit

Permalink
Fix merge Redact entity configuration metadata
Browse files Browse the repository at this point in the history
Original work (#4862) adapted for 7.x track

Signed-off-by: Christian Kruse <[email protected]>

go mod tidy

Signed-off-by: Christian Kruse <[email protected]>
  • Loading branch information
c-kruse committed Sep 30, 2022
1 parent 63cc086 commit c7a8875
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
4 changes: 4 additions & 0 deletions api/core/v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ require (
github.com/golang/protobuf v1.5.2
github.com/sensu/sensu-go/api/core/v2 v2.15.0
github.com/sensu/sensu-go/types v0.11.0
github.com/stretchr/testify v1.6.0
)

require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/echlebek/timeproxy v1.0.0 // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
Expand All @@ -27,4 +30,5 @@ require (
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
1 change: 1 addition & 0 deletions api/core/v3/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI=
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
Expand Down
10 changes: 6 additions & 4 deletions backend/api/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (g *GenericClient) getResource(ctx context.Context, name string, value core
return err
}
if redacter, ok := value.(corev3.Redacter); ok {
value = redacter.ProduceRedacted()
redacter.ProduceRedacted()
}
return err
}
Expand Down Expand Up @@ -194,9 +194,11 @@ func (g *GenericClient) list(ctx context.Context, resources interface{}, pred *s
if err := list.UnwrapInto(resources); err != nil {
return err
}
if redacters, ok := resources.([]corev3.Redacter); ok {
for i, redacter := range redacters {
redacters[i] = redacter.ProduceRedacted()
if v3Resources, ok := resources.(*[]corev3.Resource); ok {
for i, resource := range *v3Resources {
if redacter, ok := resource.(corev3.Redacter); ok {
(*v3Resources)[i] = redacter.ProduceRedacted()
}
}
}
return nil
Expand Down
26 changes: 13 additions & 13 deletions backend/api/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ func TestGenericClientStoreV2_sensu_enterprise_go_GH2484(t *testing.T) {
if err != nil {
panic(err)
}
store.On("Get", mock.Anything).Return(wrappedResource, nil)
store.On("List", mock.Anything, mock.Anything).Return(wrap.List{wrappedResource.(*wrap.Wrapper)}, nil)
store.On("Get", mock.Anything, mock.Anything).Return(wrappedResource, nil)
store.On("List", mock.Anything, mock.Anything, mock.Anything).Return(wrap.List{wrappedResource.(*wrap.Wrapper)}, nil)
return store
}
v3AllAccess := func() authorization.Authorizer {
Expand Down Expand Up @@ -633,27 +633,27 @@ func TestGenericClientStoreV2_sensu_enterprise_go_GH2484(t *testing.T) {

ctx := contextWithUser(defaultContext(), "tom", nil)
client := defaultV2TestClient(makeStore(nil), v3AllAccess())
listVal := []corev2.Resource{}
listVal := []corev3.Resource{}
if err := client.List(ctx, &listVal, &store.SelectionPredicate{}); err != nil {
t.Fatal(err)
}
if listVal[0].GetObjectMeta().Labels["password"] != corev2.Redacted {
t.Errorf("Labels['password'] = %s, got: %s", corev2.Redacted, listVal[0].GetObjectMeta().Labels["password"])
if listVal[0].GetMetadata().Labels["password"] != corev2.Redacted {
t.Errorf("Labels['password'] = %s, got: %s", corev2.Redacted, listVal[0].GetMetadata().Labels["password"])
}
if listVal[0].GetObjectMeta().Labels["my_label"] != "test" {
t.Errorf("Labels['my_label'] = %s, got: %s", "test", listVal[0].GetObjectMeta().Labels["my_label"])
if listVal[0].GetMetadata().Labels["my_label"] != "test" {
t.Errorf("Labels['my_label'] = %s, got: %s", "test", listVal[0].GetMetadata().Labels["my_label"])
}

client = defaultV2TestClient(makeStore(nil), v3AllAccess())
getVal := corev3.V2ResourceProxy{Resource: &corev3.EntityConfig{}}
if err := client.Get(ctx, "default", &getVal); err != nil {
getVal := &corev3.EntityConfig{}
if err := client.Get(ctx, "default", getVal); err != nil {
t.Fatal(err)
}
if getVal.GetObjectMeta().Labels["password"] != corev2.Redacted {
t.Errorf("Labels['password'] = %s, got: %s", corev2.Redacted, getVal.GetObjectMeta().Labels["password"])
if getVal.GetMetadata().Labels["password"] != corev2.Redacted {
t.Errorf("Labels['password'] = %s, got: %s", corev2.Redacted, getVal.GetMetadata().Labels["password"])
}
if getVal.GetObjectMeta().Labels["my_label"] != "test" {
t.Errorf("Labels['my_label'] = %s, got: %s", "test", getVal.GetObjectMeta().Labels["my_label"])
if getVal.GetMetadata().Labels["my_label"] != "test" {
t.Errorf("Labels['my_label'] = %s, got: %s", "test", getVal.GetMetadata().Labels["my_label"])
}
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097
github.com/jackc/pgconn v1.12.1
github.com/jackc/pgx/v4 v4.16.1
github.com/json-iterator/go v1.1.12
github.com/lib/pq v1.10.5
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/mholt/archiver/v3 v3.3.1-0.20191129193105-44285f7ed244
Expand All @@ -47,8 +46,8 @@ require (
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff
github.com/robfig/cron/v3 v3.0.1
github.com/sensu/lasr v1.2.1
github.com/sensu/sensu-go/api/core/v2 v2.15.0
github.com/sensu/sensu-go/api/core/v3 v3.7.0
github.com/sensu/sensu-go/api/core/v2 v2.15.1-alpha2
github.com/sensu/sensu-go/api/core/v3 v3.7.1-alpha1
github.com/sensu/sensu-go/types v0.11.0
github.com/shirou/gopsutil/v3 v3.21.12
github.com/sirupsen/logrus v1.7.0
Expand Down Expand Up @@ -107,6 +106,7 @@ require (
github.com/jackc/puddle v1.2.1 // indirect
github.com/jbenet/go-reuseport v0.0.0-20180416043609-15a1cd37f050 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.9.2 // indirect
github.com/klauspost/pgzip v1.2.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/sensu/lasr v1.2.1 h1:4H1QfOrPkwYHMFE5qAI6GwKEFkcI1YRyjjWidz1MihQ=
github.com/sensu/lasr v1.2.1/go.mod h1:VIMtIK67Bcef6dTfctRCBg8EY9M9TtCY9NEFT6Zw5xQ=
github.com/sensu/sensu-go/api/core/v2 v2.14.0/go.mod h1:XCgUjY78ApTahizBz/pkc5KU17L/E5BexeZHkGDdTls=
github.com/sensu/sensu-go/api/core/v2 v2.15.0 h1:TdH4Iq2OfpVqoY3yVXpUVe2lMmC0Ksp9Dq3wpIELXRM=
github.com/sensu/sensu-go/api/core/v2 v2.15.0/go.mod h1:QxGKxqQv4rpweFrR4Jkp1tas3amGzAy0wO0fUwq0suU=
github.com/sensu/sensu-go/api/core/v2 v2.15.1-alpha2 h1:6hUVaCWZkzUPevOXjrSJoGdW4iF3CxdCrahv4m7bPB0=
github.com/sensu/sensu-go/api/core/v2 v2.15.1-alpha2/go.mod h1:MjM7+MCGEyTAgaZ589SiGHwYiaYF7N/58dU0J070u/0=
github.com/sensu/sensu-go/api/core/v3 v3.6.1/go.mod h1:aqNOkJxkrwRq+rPW47XtVWeb5Rk1K5adlCZGBW9nsvM=
github.com/sensu/sensu-go/api/core/v3 v3.6.2/go.mod h1:aqNOkJxkrwRq+rPW47XtVWeb5Rk1K5adlCZGBW9nsvM=
github.com/sensu/sensu-go/api/core/v3 v3.7.0 h1:SgLar+4h3e7B8FveOHGshosmDxJhrP1ovh/1eNS11eM=
github.com/sensu/sensu-go/api/core/v3 v3.7.0/go.mod h1:X0mcDXOt2LCjuu0sCzXNdeeYbLq9QLtxKSpnsDybclg=
github.com/sensu/sensu-go/api/core/v3 v3.7.1-alpha1 h1:nd6ib+RMRI/e7q++kmtcFt5HrJCBtmz6UGUMH132XhY=
github.com/sensu/sensu-go/api/core/v3 v3.7.1-alpha1/go.mod h1:8io5TBGBcuR9B5MiWUi3bqr2+sGe+qcH5p6NjhAlzy4=
github.com/sensu/sensu-go/types v0.10.0/go.mod h1:vFZJ9TYBAjSPYtYt+82PpS9P6m73Vzr4O23lmJonzrA=
github.com/sensu/sensu-go/types v0.11.0 h1:jsVa/apRaJJEdk0Jl7ZUksiBkuEAjCZd/gSBWlrptJA=
github.com/sensu/sensu-go/types v0.11.0/go.mod h1:fhgW3xlvkPFMZiT0IppHySeyN61ZTIKevgSPFSoaQEk=
Expand Down

0 comments on commit c7a8875

Please sign in to comment.