Skip to content

Commit

Permalink
ROX-22101: use gogo proto.Marshal through compatibility layer (stackr…
Browse files Browse the repository at this point in the history
  • Loading branch information
rhybrillou authored Mar 12, 2024
1 parent c0df026 commit bac6c6a
Show file tree
Hide file tree
Showing 77 changed files with 108 additions and 224 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m100tom101

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
Expand Down Expand Up @@ -34,7 +33,7 @@ func addClusterIDToNetworkPolicyApplicationUndoRecord(db *bolt.DB) error {
return err
}
np.ClusterId = string(k)
data, err := proto.Marshal(&np)
data, err := protocompat.Marshal(&np)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"sort"
"strings"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
Expand Down Expand Up @@ -75,7 +74,7 @@ func updateActiveComponents(db *gorocksdb.DB) error {
activeComponent.ActiveContextsSlice = convertActiveContextsMapToSlice(activeComponent.GetDEPRECATEDActiveContexts())
activeComponent.DEPRECATEDActiveContexts = nil

data, err := proto.Marshal(&activeComponent)
data, err := protocompat.Marshal(&activeComponent)
if err != nil {
return errors.Wrap(err, "unable to marshal active component")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations/rocksdbmigration"
"github.com/stackrox/rox/migrator/rockshelper"
"github.com/stackrox/rox/pkg/protocompat"
"github.com/stackrox/rox/pkg/rocksdb"
"github.com/stackrox/rox/pkg/testutils/rocksdbtest"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -110,7 +110,7 @@ func (suite *activeComponentMigrationTestSuite) TestMigration() {
},
}
for _, initial := range initialActiveComponents {
data, err := proto.Marshal(initial)
data, err := protocompat.Marshal(initial)
suite.NoError(err)

key := rocksdbmigration.GetPrefixedKey(activeComponentsPrefix, []byte(initial.GetId()))
Expand Down
3 changes: 1 addition & 2 deletions migrator/migrations/m_105_to_m_106_group_id/migration.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m105tom106

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
Expand Down Expand Up @@ -97,7 +96,7 @@ func addIDsToGroups(db *bolt.DB, groupsStoredByCompositeKey []groupStoredByCompo
}

// 2. Marshal the group proto.
groupData, err := proto.Marshal(grp)
groupData, err := protocompat.Marshal(grp)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package m106to107
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
dbTypes "github.com/stackrox/rox/migrator/types"
"github.com/stackrox/rox/pkg/protocompat"
Expand Down Expand Up @@ -192,7 +191,7 @@ func (suite *categoriesRocksDBMigrationTestSuite) TestPolicyWithNonDefaultCatego
// Insert policy
suite.NoError(boltDB.Update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(policiesBucket)
bytes, err := proto.Marshal(policyWithNonDefaultCategories)
bytes, err := protocompat.Marshal(policyWithNonDefaultCategories)
if err != nil {
return err
}
Expand Down Expand Up @@ -227,7 +226,7 @@ func (suite *categoriesRocksDBMigrationTestSuite) TestPolicyWithDefaultCategorie
// Insert policy
suite.NoError(boltDB.Update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(policiesBucket)
bytes, err := proto.Marshal(policyWithOnlyDefaultCategories)
bytes, err := protocompat.Marshal(policyWithOnlyDefaultCategories)
if err != nil {
return err
}
Expand Down Expand Up @@ -261,7 +260,7 @@ func (suite *categoriesRocksDBMigrationTestSuite) TestPolicyWithBothCategoryType
// Insert policy
suite.NoError(boltDB.Update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(policiesBucket)
bytes, err := proto.Marshal(policyWithBothCategoryTypes)
bytes, err := protocompat.Marshal(policyWithBothCategoryTypes)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m107tom108

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
Expand Down Expand Up @@ -48,7 +47,7 @@ func migratePS(db *gorocksdb.DB) error {
}
if _, ok := ps.ResourceToAccess[authPluginResourceName]; ok {
delete(ps.ResourceToAccess, authPluginResourceName)
data, err := proto.Marshal(ps)
data, err := protocompat.Marshal(ps)
if err != nil {
return errors.Wrap(err, "unable to marshal permission set")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package m107tom108
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations/rocksdbmigration"
"github.com/stackrox/rox/migrator/rockshelper"
"github.com/stackrox/rox/migrator/types"
"github.com/stackrox/rox/pkg/protocompat"
"github.com/stackrox/rox/pkg/rocksdb"
"github.com/stackrox/rox/pkg/testutils"
"github.com/stackrox/rox/pkg/testutils/rocksdbtest"
Expand Down Expand Up @@ -93,7 +93,7 @@ func (suite *psMigrationTestSuite) TestMigration() {
psToUpsert = append(psToUpsert, alreadyMigratedPSs...)

for _, initial := range psToUpsert {
data, err := proto.Marshal(initial)
data, err := protocompat.Marshal(initial)
suite.NoError(err)

key := rocksdbmigration.GetPrefixedKey(psPrefix, []byte(initial.GetId()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m108tom109

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
Expand Down Expand Up @@ -39,7 +38,7 @@ func removeComplianceRunScheduleFromPermissionSets(db *gorocksdb.DB) error {
continue
}
delete(ps.ResourceToAccess, permissionName)
data, err := proto.Marshal(ps)
data, err := protocompat.Marshal(ps)
if err != nil {
return errors.Wrap(err, "unable to marshal permission set")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package m108tom109
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations/rocksdbmigration"
"github.com/stackrox/rox/migrator/rockshelper"
"github.com/stackrox/rox/migrator/types"
"github.com/stackrox/rox/pkg/protocompat"
"github.com/stackrox/rox/pkg/rocksdb"
"github.com/stackrox/rox/pkg/testutils"
"github.com/stackrox/rox/pkg/testutils/rocksdbtest"
Expand Down Expand Up @@ -92,7 +92,7 @@ func (suite *psMigrationTestSuite) TestMigration() {
psToUpsert = append(psToUpsert, alreadyMigratedPSs...)

for _, initial := range psToUpsert {
data, err := proto.Marshal(initial)
data, err := protocompat.Marshal(initial)
suite.NoError(err)

key := rocksdbmigration.GetPrefixedKey(prefix, []byte(initial.GetId()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m110tom111

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
Expand Down Expand Up @@ -109,7 +108,7 @@ func migrateReplacedResourcesInPermissionSets(db *gorocksdb.DB) error {
newPermissionSet.ResourceToAccess[resource] =
propagateAccessForPermission(resource, accessLevel, newPermissionSet.ResourceToAccess)
}
data, err := proto.Marshal(newPermissionSet)
data, err := protocompat.Marshal(newPermissionSet)
if err != nil {
return errors.Wrap(err, "unable to marshal permission set")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package m110tom111
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations/rocksdbmigration"
"github.com/stackrox/rox/migrator/rockshelper"
"github.com/stackrox/rox/migrator/types"
"github.com/stackrox/rox/pkg/protocompat"
"github.com/stackrox/rox/pkg/rocksdb"
"github.com/stackrox/rox/pkg/testutils/rocksdbtest"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -504,7 +504,7 @@ func (suite *psMigrationTestSuite) TearDownTest() {
func (suite *psMigrationTestSuite) TestMigration() {

for _, initial := range UnmigratedPermissionSets {
data, err := proto.Marshal(initial)
data, err := protocompat.Marshal(initial)
suite.NoError(err)

key := rocksdbmigration.GetPrefixedKey(prefix, []byte(initial.GetId()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m56tom57

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/log"
Expand Down Expand Up @@ -116,7 +115,7 @@ func migrateNewPolicyCategories(db *bolt.DB) error {
policy.Name = policyChange.newName
}

obj, err := proto.Marshal(policy)
obj, err := protocompat.Marshal(policy)
if err != nil {
// Unclear how to recover from marshal error, abort the transaction.
return errors.Wrapf(err, "failed to marshal migrated policy %q for key %q", policy.GetName(), policy.GetId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package m56tom57
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/protocompat"
Expand Down Expand Up @@ -32,7 +31,7 @@ func TestPolicyMigration(t *testing.T) {
Name: testName,
Categories: append(policyChange.removeCategories, someOtherCategory),
}
bytes, err := proto.Marshal(testPolicy)
bytes, err := protocompat.Marshal(testPolicy)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package m57tom58
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/bolthelpers"
"github.com/stackrox/rox/pkg/protocompat"
Expand Down Expand Up @@ -40,7 +39,7 @@ func (suite *runSecretsVolumePolicyTestSuite) TearDownTest() {

func insertPolicy(bucket bolthelpers.BucketRef, id string, pb protocompat.Message) error {
return bucket.Update(func(b *bolt.Bucket) error {
bytes, err := proto.Marshal(pb)
bytes, err := protocompat.Marshal(pb)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/log"
Expand Down Expand Up @@ -72,7 +71,7 @@ func migrateScanner(db *bolt.DB) error {

imageIntegration.Categories = append(imageIntegration.Categories, storage.ImageIntegrationCategory_NODE_SCANNER)

newValue, err := proto.Marshal(&imageIntegration)
newValue, err := protocompat.Marshal(&imageIntegration)
if err != nil {
return errors.Wrapf(err, "error marshalling external backup %s", k)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m59tom60

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/log"
Expand Down Expand Up @@ -61,7 +60,7 @@ func migrateNewPolicyCategories(db *bolt.DB) error {
}
migratePolicy(policy)

obj, err := proto.Marshal(policy)
obj, err := protocompat.Marshal(policy)
if err != nil {
// Unclear how to recover from marshal error, abort the transaction.
return errors.Wrapf(err, "failed to marshal migrated policy %q for key %q", policy.GetName(), policy.GetId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package m59tom60
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/protocompat"
Expand Down Expand Up @@ -33,7 +32,7 @@ func TestPolicyMigration(t *testing.T) {
if i == 0 {
testPolicy.Categories = append(testPolicy.Categories, dockerCIS)
}
bytes, err := proto.Marshal(testPolicy)
bytes, err := protocompat.Marshal(testPolicy)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package m60tom61
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/bolthelpers"
"github.com/stackrox/rox/pkg/protocompat"
Expand Down Expand Up @@ -40,7 +39,7 @@ func (suite *networkManagementExecutionPolicyTestSuite) TearDownTest() {

func insertPolicy(bucket bolthelpers.BucketRef, id string, pb protocompat.Message) error {
return bucket.Update(func(b *bolt.Bucket) error {
bytes, err := proto.Marshal(pb)
bytes, err := protocompat.Marshal(pb)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m61tom62

import (
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
Expand Down Expand Up @@ -54,7 +53,7 @@ func migrateCVEs(db *gorocksdb.DB) error {
cve.Types = []storage.CVE_CVEType{cve.GetType()}
cve.Type = storage.CVE_UNKNOWN_CVE

data, err := proto.Marshal(&cve)
data, err := protocompat.Marshal(&cve)
if err != nil {
return errors.Wrapf(err, "marshaling %s", cveID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package m61tom62
import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations/rocksdbmigration"
"github.com/stackrox/rox/migrator/rockshelper"
dbTypes "github.com/stackrox/rox/migrator/types"
"github.com/stackrox/rox/pkg/protocompat"
"github.com/stackrox/rox/pkg/rocksdb"
rocksdbopts "github.com/stackrox/rox/pkg/rocksdb/crud"
"github.com/stackrox/rox/pkg/testutils/rocksdbtest"
Expand Down Expand Up @@ -97,7 +97,7 @@ func (suite *multipleCVETypesMigrationTestSuite) TestMultipleCVETypesMigration()

for _, cve := range cves {
key := rocksdbmigration.GetPrefixedKey(cveBucket, []byte(cve.GetId()))
value, err := proto.Marshal(cve)
value, err := protocompat.Marshal(cve)
suite.NoError(err)
suite.NoError(suite.db.Put(writeOpts, key, value))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package m62tom63

import (
"github.com/gogo/protobuf/proto"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/migrator/migrations"
"github.com/stackrox/rox/migrator/types"
Expand Down Expand Up @@ -55,7 +54,7 @@ func migrateSplunkSourceType(db *bolt.DB) error {
}
}
splunk.DerivedSourceTypeDeprecated = nil
newData, err := proto.Marshal(&notifier)
newData, err := protocompat.Marshal(&notifier)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit bac6c6a

Please sign in to comment.