FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor: use gogo proto.Message type through compatibility layer (#9… · stackrox/stackrox@a70cec5 · GitHub

refactor: use gogo proto.Message type through compatibility layer (#9… · stackrox/stackrox@a70cec5 · GitHub
Skip to content

Navigation Menu

Commit a70cec5

Browse files
authored
refactor: use gogo proto.Message type through compatibility layer (#9280)
1 parent 958fd0f commit a70cec5

132 files changed

Lines changed: 587 additions & 633 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎central/audit/audit.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/stackrox/rox/pkg/grpc/requestinfo"
1717
"github.com/stackrox/rox/pkg/httputil"
1818
"github.com/stackrox/rox/pkg/notifier"
19+
"github.com/stackrox/rox/pkg/protocompat"
1920
"github.com/stackrox/rox/pkg/protoutils"
2021
"github.com/stackrox/rox/pkg/sac"
2122
"github.com/stackrox/rox/pkg/secrets"
@@ -62,7 +63,7 @@ func requestToAny(req interface{}) *types.Any {
6263
if req == nil {
6364
return nil
6465
}
65-
msg, ok := req.(proto.Message)
66+
msg, ok := req.(protocompat.Message)
6667
if !ok {
6768
return nil
6869
}

‎central/convert/testutils/utils.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"testing"
66

77
"github.com/golang/protobuf/jsonpb"
8-
"github.com/golang/protobuf/proto"
8+
"github.com/stackrox/rox/pkg/protocompat"
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111
)
1212

13-
// AssertProtoMessageEqual asserts the equality of two proto.Messages by marshalling them to JSON
13+
// AssertProtoMessageEqual asserts the equality of two protocompat.Messages by marshalling them to JSON
1414
// and comparing the JSON output.
15-
func AssertProtoMessageEqual(t *testing.T, a, b proto.Message) {
15+
func AssertProtoMessageEqual(t *testing.T, a, b protocompat.Message) {
1616
m := jsonpb.Marshaler{}
1717

1818
jsonA := &bytes.Buffer{}

‎central/declarativeconfig/manager_impl.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"sync/atomic"
1010
"time"
1111

12-
"github.com/gogo/protobuf/proto"
1312
"github.com/hashicorp/go-multierror"
1413
"github.com/mitchellh/hashstructure/v2"
1514
"github.com/pkg/errors"
@@ -24,6 +23,7 @@ import (
2423
"github.com/stackrox/rox/pkg/errox"
2524
"github.com/stackrox/rox/pkg/k8scfgwatch"
2625
"github.com/stackrox/rox/pkg/maputil"
26+
"github.com/stackrox/rox/pkg/protocompat"
2727
"github.com/stackrox/rox/pkg/sac"
2828
"github.com/stackrox/rox/pkg/sac/resources"
2929
"github.com/stackrox/rox/pkg/set"
@@ -40,7 +40,7 @@ const (
4040
consecutiveReconciliationErrorThreshold = 3
4141
)
4242

43-
type protoMessagesByType = map[reflect.Type][]proto.Message
43+
type protoMessagesByType = map[reflect.Type][]protocompat.Message
4444

4545
type managerImpl struct {
4646
once sync.Once
@@ -182,7 +182,7 @@ func (m *managerImpl) UpdateDeclarativeConfigContents(handlerID string, contents
182182
return
183183
}
184184

185-
transformedConfigurations := make(map[reflect.Type][]proto.Message, len(configurations))
185+
transformedConfigurations := make(map[reflect.Type][]protocompat.Message, len(configurations))
186186
var transformationErrors *multierror.Error
187187
for _, configuration := range configurations {
188188
transformedConfig, err := m.universalTransformer.Transform(configuration)
@@ -327,7 +327,7 @@ func (m *managerImpl) doDeletion(transformedMessagesByHandler map[string]protoMe
327327
// In case err == nil, the health status will be set to healthy.
328328
// In case err != nil _and_ the number of errors for this message is >= the given threshold, the health
329329
// status will be set to unhealthy.
330-
func (m *managerImpl) updateHealthForMessage(handler string, message proto.Message, err error, threshold int32) {
330+
func (m *managerImpl) updateHealthForMessage(handler string, message protocompat.Message, err error, threshold int32) {
331331
messageID := m.idExtractor(message)
332332
healthStatus := declarativeConfigUtils.HealthStatusForProtoMessage(message, handler, err, m.idExtractor, m.nameExtractor)
333333

@@ -344,7 +344,7 @@ func (m *managerImpl) updateHealthForMessage(handler string, message proto.Messa
344344
}
345345
}
346346

347-
func (m *managerImpl) registerHealthForMessages(handler string, messages ...proto.Message) {
347+
func (m *managerImpl) registerHealthForMessages(handler string, messages ...protocompat.Message) {
348348
for _, message := range messages {
349349
health := declarativeConfigUtils.HealthStatusForProtoMessage(message, handler, nil, m.idExtractor, m.nameExtractor)
350350
m.registerDeclarativeConfigHealth(health)

‎central/declarativeconfig/manager_impl_test.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/gogo/protobuf/proto"
109
"github.com/pkg/errors"
1110
declarativeConfigHealthMock "github.com/stackrox/rox/central/declarativeconfig/health/datastore/mocks"
1211
"github.com/stackrox/rox/central/declarativeconfig/types"
@@ -16,6 +15,7 @@ import (
1615
"github.com/stackrox/rox/pkg/declarativeconfig"
1716
transformMocks "github.com/stackrox/rox/pkg/declarativeconfig/transform/mocks"
1817
"github.com/stackrox/rox/pkg/errox"
18+
"github.com/stackrox/rox/pkg/protocompat"
1919
"github.com/stretchr/testify/assert"
2020
"github.com/stretchr/testify/require"
2121
"go.uber.org/mock/gomock"
@@ -241,25 +241,25 @@ func TestReconcileTransformedMessages_Success(t *testing.T) {
241241

242242
m.reconcileTransformedMessages(map[string]protoMessagesByType{
243243
"test-handler-1": {
244-
types.PermissionSetType: []proto.Message{
244+
types.PermissionSetType: []protocompat.Message{
245245
permissionSet1,
246246
permissionSet2,
247247
},
248-
types.AccessScopeType: []proto.Message{
248+
types.AccessScopeType: []protocompat.Message{
249249
accessScope,
250250
},
251251
},
252252
"test-handler-2": {
253-
types.RoleType: []proto.Message{
253+
types.RoleType: []protocompat.Message{
254254
role,
255255
},
256-
types.AuthProviderType: []proto.Message{
256+
types.AuthProviderType: []protocompat.Message{
257257
authProvider,
258258
},
259-
types.GroupType: []proto.Message{
259+
types.GroupType: []protocompat.Message{
260260
group,
261261
},
262-
types.NotifierType: []proto.Message{
262+
types.NotifierType: []protocompat.Message{
263263
notifier,
264264
},
265265
},
@@ -308,7 +308,7 @@ func TestReconcileTransformedMessages_ErrorPropagatedToReporter(t *testing.T) {
308308
for i := 0; i < consecutiveReconciliationErrorThreshold; i++ {
309309
m.reconcileTransformedMessages(map[string]protoMessagesByType{
310310
"test-handler-1": {
311-
types.PermissionSetType: []proto.Message{
311+
types.PermissionSetType: []protocompat.Message{
312312
permissionSet1,
313313
},
314314
},
@@ -349,7 +349,7 @@ func TestReconcileTransformedMessages_SkipReconciliationWithNoChanges(t *testing
349349

350350
messages := map[string]protoMessagesByType{
351351
"test-handler-1": {
352-
types.PermissionSetType: []proto.Message{
352+
types.PermissionSetType: []protocompat.Message{
353353
permissionSet1,
354354
},
355355
},
@@ -398,7 +398,7 @@ func TestReconcileTransformedMessages_SkipDeletion(t *testing.T) {
398398

399399
messages := map[string]protoMessagesByType{
400400
"test-handler-1": {
401-
types.PermissionSetType: []proto.Message{
401+
types.PermissionSetType: []protocompat.Message{
402402
permissionSet1,
403403
},
404404
},
@@ -463,7 +463,7 @@ func TestReconcileTransformedMessages_SkipUpsert(t *testing.T) {
463463

464464
messages := map[string]protoMessagesByType{
465465
"test-handler-1": {
466-
types.PermissionSetType: []proto.Message{
466+
types.PermissionSetType: []protocompat.Message{
467467
permissionSet1,
468468
},
469469
},
@@ -512,7 +512,7 @@ func TestUpdateDeclarativeConfigContents_RegisterHealthStatus(t *testing.T) {
512512
Description: "test-description",
513513
AccessScope: "access-scope",
514514
PermissionSet: "permission-set",
515-
}).Return(map[reflect.Type][]proto.Message{
515+
}).Return(map[reflect.Type][]protocompat.Message{
516516
types.RoleType: {
517517
&storage.Role{
518518
Name: "test-name",

‎central/declarativeconfig/types/extractors.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package types
33
import (
44
"fmt"
55

6-
"github.com/gogo/protobuf/proto"
76
"github.com/stackrox/rox/generated/storage"
87
"github.com/stackrox/rox/pkg/errox"
8+
"github.com/stackrox/rox/pkg/protocompat"
99
"github.com/stackrox/rox/pkg/utils"
1010
)
1111

1212
// IDExtractor extracts the ID from proto messages.
13-
type IDExtractor func(m proto.Message) string
13+
type IDExtractor func(m protocompat.Message) string
1414

1515
// NameExtractor extracts the name from proto messages.
16-
type NameExtractor func(m proto.Message) string
16+
type NameExtractor func(m protocompat.Message) string
1717

1818
// UniversalIDExtractor provides a way to extract the ID from proto messages.
1919
func UniversalIDExtractor() IDExtractor {
@@ -25,7 +25,7 @@ func UniversalNameExtractor() NameExtractor {
2525
return extractNameFromProtoMessage
2626
}
2727

28-
func extractIDFromProtoMessage(message proto.Message) string {
28+
func extractIDFromProtoMessage(message protocompat.Message) string {
2929
// Special case, as the group specifies the ID nested within the groups properties.
3030
if group, ok := message.(*storage.Group); ok {
3131
return group.GetProps().GetId()
@@ -48,7 +48,7 @@ func extractIDFromProtoMessage(message proto.Message) string {
4848
return messageWithID.GetId()
4949
}
5050

51-
func extractNameFromProtoMessage(message proto.Message) string {
51+
func extractNameFromProtoMessage(message protocompat.Message) string {
5252
// Special case, as the group specifies no name we will use a combination of multiple values to identify it.
5353
if group, ok := message.(*storage.Group); ok {
5454
return fmt.Sprintf("group %s:%s:%s for auth provider ID %s",

‎central/declarativeconfig/updater/access_scope_updater.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package updater
33
import (
44
"context"
55

6-
"github.com/gogo/protobuf/proto"
76
"github.com/hashicorp/go-multierror"
87
"github.com/pkg/errors"
98
declarativeConfigHealth "github.com/stackrox/rox/central/declarativeconfig/health/datastore"
@@ -12,6 +11,7 @@ import (
1211
"github.com/stackrox/rox/generated/storage"
1312
"github.com/stackrox/rox/pkg/declarativeconfig"
1413
"github.com/stackrox/rox/pkg/errox"
14+
"github.com/stackrox/rox/pkg/protocompat"
1515
"github.com/stackrox/rox/pkg/set"
1616
)
1717

@@ -33,7 +33,7 @@ func newAccessScopeUpdater(datastore roleDataStore.DataStore, healthDS declarati
3333
}
3434
}
3535

36-
func (u *accessScopeUpdater) Upsert(ctx context.Context, m proto.Message) error {
36+
func (u *accessScopeUpdater) Upsert(ctx context.Context, m protocompat.Message) error {
3737
accessScope, ok := m.(*storage.SimpleAccessScope)
3838
if !ok {
3939
return errox.InvariantViolation.Newf("wrong type passed to access scope updater: %T", accessScope)

‎central/declarativeconfig/updater/auth_provider_updater.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package updater
33
import (
44
"context"
55

6-
"github.com/gogo/protobuf/proto"
76
"github.com/hashicorp/go-multierror"
87
"github.com/pkg/errors"
98
authProviderDatastore "github.com/stackrox/rox/central/authprovider/datastore"
@@ -15,6 +14,7 @@ import (
1514
"github.com/stackrox/rox/pkg/declarativeconfig"
1615
"github.com/stackrox/rox/pkg/errox"
1716
"github.com/stackrox/rox/pkg/logging"
17+
"github.com/stackrox/rox/pkg/protocompat"
1818
"github.com/stackrox/rox/pkg/sac"
1919
"github.com/stackrox/rox/pkg/sac/resources"
2020
"github.com/stackrox/rox/pkg/set"
@@ -52,7 +52,7 @@ func newAuthProviderUpdater(authProvidersDS authproviders.Store, registry authpr
5252
}
5353
}
5454

55-
func (u *authProviderUpdater) Upsert(ctx context.Context, m proto.Message) error {
55+
func (u *authProviderUpdater) Upsert(ctx context.Context, m protocompat.Message) error {
5656
authProvider, ok := m.(*storage.AuthProvider)
5757
if !ok {
5858
return errox.InvariantViolation.Newf("wrong type passed to auth provider updater: %T", authProvider)

‎central/declarativeconfig/updater/group_updater.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package updater
33
import (
44
"context"
55

6-
"github.com/gogo/protobuf/proto"
76
"github.com/hashicorp/go-multierror"
87
"github.com/pkg/errors"
98
declarativeConfigHealth "github.com/stackrox/rox/central/declarativeconfig/health/datastore"
@@ -12,6 +11,7 @@ import (
1211
"github.com/stackrox/rox/generated/storage"
1312
"github.com/stackrox/rox/pkg/declarativeconfig"
1413
"github.com/stackrox/rox/pkg/errox"
14+
"github.com/stackrox/rox/pkg/protocompat"
1515
"github.com/stackrox/rox/pkg/set"
1616
)
1717

@@ -33,7 +33,7 @@ func newGroupUpdater(datastore groupDataStore.DataStore, healthDS declarativeCon
3333
}
3434
}
3535

36-
func (u *groupUpdater) Upsert(ctx context.Context, m proto.Message) error {
36+
func (u *groupUpdater) Upsert(ctx context.Context, m protocompat.Message) error {
3737
group, ok := m.(*storage.Group)
3838
if !ok {
3939
return errox.InvariantViolation.Newf("wrong type passed to group updater: %T", group)

‎central/declarativeconfig/updater/mocks/updater.go‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎central/declarativeconfig/updater/notifier_updater.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package updater
33
import (
44
"context"
55

6-
"github.com/gogo/protobuf/proto"
76
"github.com/hashicorp/go-multierror"
87
"github.com/pkg/errors"
98
declarativeConfigHealth "github.com/stackrox/rox/central/declarativeconfig/health/datastore"
@@ -18,6 +17,7 @@ import (
1817
"github.com/stackrox/rox/pkg/integrationhealth"
1918
"github.com/stackrox/rox/pkg/notifier"
2019
"github.com/stackrox/rox/pkg/notifiers"
20+
"github.com/stackrox/rox/pkg/protocompat"
2121
"github.com/stackrox/rox/pkg/set"
2222
"github.com/stackrox/rox/pkg/utils"
2323
)
@@ -58,7 +58,7 @@ func newNotifierUpdater(notifierDS notifierDataStore.DataStore, policyCleaner po
5858
}
5959
}
6060

61-
func (u *notifierUpdater) Upsert(ctx context.Context, m proto.Message) error {
61+
func (u *notifierUpdater) Upsert(ctx context.Context, m protocompat.Message) error {
6262
notifierProto, ok := m.(*storage.Notifier)
6363
if !ok {
6464
return errox.InvariantViolation.Newf("wrong type passed to role updater: %T", notifierProto)

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL