Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: cannot unmarshal existed sql review policy (#8546)
ecmadaoa8fa528d764f
diff --git a/backend/api/v1/org_policy_service.go b/backend/api/v1/org_policy_service.goindex 3fe66ac070..75b91bb702 100644--- a/backend/api/v1/org_policy_service.go+++ b/backend/api/v1/org_policy_service.go@@ -588,10 +588,11 @@ func (s *OrgPolicyService) convertPolicyPayloadToString(policy *v1pb.Policy) (stif err != nil {return "", status.Errorf(codes.InvalidArgument, err.Error())}- if err := payload.Validate(); err != nil {- return "", status.Errorf(codes.InvalidArgument, err.Error())+ payloadBytes, err := protojson.Marshal(payload)+ if err != nil {+ return "", status.Errorf(codes.Internal, "failed to marshal sql review policy with error: %v", err)}- return payload.String()+ return string(payloadBytes), nilcase v1pb.PolicyType_MASKING:if err := s.licenseService.IsFeatureEnabled(api.FeatureSensitiveData); err != nil {return "", status.Errorf(codes.PermissionDenied, err.Error())@@ -850,30 +851,30 @@ func convertToV1PBSQLReviewPolicy(payloadStr string) (*v1pb.Policy_SqlReviewPoli}, nil}-func convertToSQLReviewPolicyPayload(policy *v1pb.SQLReviewPolicy) (*advisor.SQLReviewPolicy, error) {- var ruleList []*advisor.SQLReviewRule+func convertToSQLReviewPolicyPayload(policy *v1pb.SQLReviewPolicy) (*storepb.SQLReviewPolicy, error) {+ var ruleList []*storepb.SQLReviewRulefor _, rule := range policy.Rules {- var level advisor.SQLReviewRuleLevel+ var level storepb.SQLReviewRuleLevelswitch rule.Level {case v1pb.SQLReviewRuleLevel_ERROR:- level = advisor.SchemaRuleLevelError+ level = storepb.SQLReviewRuleLevel_ERRORcase v1pb.SQLReviewRuleLevel_WARNING:- level = advisor.SchemaRuleLevelWarning+ level = storepb.SQLReviewRuleLevel_WARNINGcase v1pb.SQLReviewRuleLevel_DISABLED:- level = advisor.SchemaRuleLevelDisabled+ level = storepb.SQLReviewRuleLevel_DISABLEDdefault:return nil, errors.Errorf("invalid rule level %v", rule.Level)}- ruleList = append(ruleList, &advisor.SQLReviewRule{+ ruleList = append(ruleList, &storepb.SQLReviewRule{Level: level,Payload: rule.Payload,- Type: advisor.SQLReviewRuleType(rule.Type),+ Type: rule.Type,Comment: rule.Comment,Engine: convertEngine(rule.Engine),})}- return &advisor.SQLReviewPolicy{+ return &storepb.SQLReviewPolicy{Name: policy.Name,RuleList: ruleList,}, nildiff --git a/backend/legacyapi/policy.go b/backend/legacyapi/policy.goindex 7004b10a1a..438e7254ca 100644--- a/backend/legacyapi/policy.go+++ b/backend/legacyapi/policy.go@@ -4,6 +4,11 @@ import ("encoding/json""github.com/pkg/errors"+ "google.golang.org/grpc/codes"+ "google.golang.org/grpc/status"+ "google.golang.org/protobuf/encoding/protojson"++ storepb "github.com/bytebase/bytebase/proto/generated-go/store""github.com/bytebase/bytebase/backend/plugin/advisor")@@ -169,11 +174,37 @@ func UnmarshalBackupPlanPolicy(payload string) (*BackupPlanPolicy, error) {// UnmarshalSQLReviewPolicy will unmarshal payload to SQL review policy.func UnmarshalSQLReviewPolicy(payload string) (*advisor.SQLReviewPolicy, error) {- var sr advisor.SQLReviewPolicy- if err := json.Unmarshal([]byte(payload), &sr); err != nil {- return nil, errors.Wrapf(err, "failed to unmarshal SQL review policy %q", payload)+ storePolicy := new(storepb.SQLReviewPolicy)+ if err := protojson.Unmarshal([]byte(payload), storePolicy); err != nil {+ return nil, status.Errorf(codes.Internal, "failed to unmarshal stored sql review policy with error: %v", err)+ }++ var ruleList []*advisor.SQLReviewRule+ for _, rule := range storePolicy.RuleList {+ var level advisor.SQLReviewRuleLevel+ switch rule.Level {+ case storepb.SQLReviewRuleLevel_ERROR:+ level = advisor.SchemaRuleLevelError+ case storepb.SQLReviewRuleLevel_WARNING:+ level = advisor.SchemaRuleLevelWarning+ case storepb.SQLReviewRuleLevel_DISABLED:+ level = advisor.SchemaRuleLevelDisabled+ default:+ return nil, errors.Errorf("invalid rule level %v", rule.Level)+ }+ ruleList = append(ruleList, &advisor.SQLReviewRule{+ Level: level,+ Payload: rule.Payload,+ Type: advisor.SQLReviewRuleType(rule.Type),+ Comment: rule.Comment,+ Engine: rule.Engine,+ })}- return &sr, nil++ return &advisor.SQLReviewPolicy{+ Name: storePolicy.Name,+ RuleList: ruleList,+ }, nil}// EnvironmentTierPolicy is the tier of an environment.diff --git a/frontend/src/store/modules/v1/policy.ts b/frontend/src/store/modules/v1/policy.tsindex 1f381d7b68..9cdb17a102 100644--- a/frontend/src/store/modules/v1/policy.ts+++ b/frontend/src/store/modules/v1/policy.ts@@ -266,6 +266,7 @@ export const getDefaultBackupPlanPolicy = (enforce: true,backupPlanPolicy: {schedule: defaultBackupSchedule,+ retentionDuration: undefined,},};};diff --git a/frontend/src/types/proto/store/policy.ts b/frontend/src/types/proto/store/policy.tsindex 0121490fff..7eb4d88321 100644--- a/frontend/src/types/proto/store/policy.ts+++ b/frontend/src/types/proto/store/policy.ts@@ -1,10 +1,55 @@/* eslint-disable */import _m0 from "protobufjs/minimal";import { Expr } from "../google/type/expr";-import { MaskingLevel, maskingLevelFromJSON, maskingLevelToJSON } from "./common";+import { Engine, engineFromJSON, engineToJSON, MaskingLevel, maskingLevelFromJSON, maskingLevelToJSON } from "./common";export const protobufPackage = "bytebase.store";+export enum SQLReviewRuleLevel {+ LEVEL_UNSPECIFIED = 0,+ ERROR = 1,+ WARNING = 2,+ DISABLED = 3,+ UNRECOGNIZED = -1,+}++export function sQLReviewRuleLevelFromJSON(object: any): SQLReviewRuleLevel {+ switch (object) {+ case 0:+ case "LEVEL_UNSPECIFIED":+ return SQLReviewRuleLevel.LEVEL_UNSPECIFIED;+ case 1:+ case "ERROR":+ return SQLReviewRuleLevel.ERROR;+ case 2:+ case "WARNING":+ return SQLReviewRuleLevel.WARNING;+ case 3:+ case "DISABLED":+ return SQLReviewRuleLevel.DISABLED;+ case -1:+ case "UNRECOGNIZED":+ default:+ return SQLReviewRuleLevel.UNRECOGNIZED;+ }+}++export function sQLReviewRuleLevelToJSON(object: SQLReviewRuleLevel): string {+ switch (object) {+ case SQLReviewRuleLevel.LEVEL_UNSPECIFIED:+ return "LEVEL_UNSPECIFIED";+ case SQLReviewRuleLevel.ERROR:+ return "ERROR";+ case SQLReviewRuleLevel.WARNING:+ return "WARNING";+ case SQLReviewRuleLevel.DISABLED:+ return "DISABLED";+ case SQLReviewRuleLevel.UNRECOGNIZED:+ default:+ return "UNRECOGNIZED";+ }+}+export interface IamPolicy {/** Collection of binding. */bindings: Binding[];@@ -118,6 +163,19 @@ export interface MaskingRulePolicy_MaskingRule {maskingLevel: MaskingLevel;}+export interface SQLReviewPolicy {+ name: string;+ ruleList: SQLReviewRule[];+}++export interface SQLReviewRule {+ type: string;+ level: SQLReviewRuleLevel;+ payload: string;+ engine: Engine;+ comment: string;+}+function createBaseIamPolicy(): IamPolicy {return { bindings: [] };}@@ -741,6 +799,191 @@ export const MaskingRulePolicy_MaskingRule = {},};+function createBaseSQLReviewPolicy(): SQLReviewPolicy {+ return { name: "", ruleList: [] };+}++export const SQLReviewPolicy = {+ encode(message: SQLReviewPolicy, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {+ if (message.name !== "") {+ writer.uint32(10).string(message.name);+ }+ for (const v of message.ruleList) {+ SQLReviewRule.encode(v!, writer.uint32(18).fork()).ldelim();+ }+ return writer;+ },++ decode(input: _m0.Reader | Uint8Array, length?: number): SQLReviewPolicy {+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);+ let end = length === undefined ? reader.len : reader.pos + length;+ const message = createBaseSQLReviewPolicy();+ while (reader.pos < end) {+ const tag = reader.uint32();+ switch (tag >>> 3) {+ case 1:+ if (tag !== 10) {+ break;+ }++ message.name = reader.string();+ continue;+ case 2:+ if (tag !== 18) {+ break;+ }++ message.ruleList.push(SQLReviewRule.decode(reader, reader.uint32()));+ continue;+ }+ if ((tag & 7) === 4 || tag === 0) {+ break;+ }+ reader.skipType(tag & 7);+ }+ return message;+ },++ fromJSON(object: any): SQLReviewPolicy {+ return {+ name: isSet(object.name) ? String(object.name) : "",+ ruleList: Array.isArray(object?.ruleList) ? object.ruleList.map((e: any) => SQLReviewRule.fromJSON(e)) : [],+ };+ },++ toJSON(message: SQLReviewPolicy): unknown {+ const obj: any = {};+ message.name !== undefined && (obj.name = message.name);+ if (message.ruleList) {+ obj.ruleList = message.ruleList.map((e) => e ? SQLReviewRule.toJSON(e) : undefined);+ } else {+ obj.ruleList = [];+ }+ return obj;+ },++ create(base?: DeepPartial<SQLReviewPolicy>): SQLReviewPolicy {+ return SQLReviewPolicy.fromPartial(base ?? {});+ },++ fromPartial(object: DeepPartial<SQLReviewPolicy>): SQLReviewPolicy {+ const message = createBaseSQLReviewPolicy();+ message.name = object.name ?? "";+ message.ruleList = object.ruleList?.map((e) => SQLReviewRule.fromPartial(e)) || [];+ return message;+ },+};++function createBaseSQLReviewRule(): SQLReviewRule {+ return { type: "", level: 0, payload: "", engine: 0, comment: "" };+}++export const SQLReviewRule = {+ encode(message: SQLReviewRule, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {+ if (message.type !== "") {+ writer.uint32(10).string(message.type);+ }+ if (message.level !== 0) {+ writer.uint32(16).int32(message.level);+ }+ if (message.payload !== "") {+ writer.uint32(26).string(message.payload);+ }+ if (message.engine !== 0) {+ writer.uint32(32).int32(message.engine);+ }+ if (message.comment !== "") {+ writer.uint32(42).string(message.comment);+ }+ return writer;+ },++ decode(input: _m0.Reader | Uint8Array, length?: number): SQLReviewRule {+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);+ let end = length === undefined ? reader.len : reader.pos + length;+ const message = createBaseSQLReviewRule();+ while (reader.pos < end) {+ const tag = reader.uint32();+ switch (tag >>> 3) {+ case 1:+ if (tag !== 10) {+ break;+ }++ message.type = reader.string();+ continue;+ case 2:+ if (tag !== 16) {+ break;+ }++ message.level = reader.int32() as any;+ continue;+ case 3:+ if (tag !== 26) {+ break;+ }++ message.payload = reader.string();+ continue;+ case 4:+ if (tag !== 32) {+ break;+ }++ message.engine = reader.int32() as any;+ continue;+ case 5:+ if (tag !== 42) {+ break;+ }++ message.comment = reader.string();+ continue;+ }+ if ((tag & 7) === 4 || tag === 0) {+ break;+ }+ reader.skipType(tag & 7);+ }+ return message;+ },++ fromJSON(object: any): SQLReviewRule {+ return {+ type: isSet(object.type) ? String(object.type) : "",+ level: isSet(object.level) ? sQLReviewRuleLevelFromJSON(object.level) : 0,+ payload: isSet(object.payload) ? String(object.payload) : "",+ engine: isSet(object.engine) ? engineFromJSON(object.engine) : 0,+ comment: isSet(object.comment) ? String(object.comment) : "",+ };+ },++ toJSON(message: SQLReviewRule): unknown {+ const obj: any = {};+ message.type !== undefined && (obj.type = message.type);+ message.level !== undefined && (obj.level = sQLReviewRuleLevelToJSON(message.level));+ message.payload !== undefined && (obj.payload = message.payload);+ message.engine !== undefined && (obj.engine = engineToJSON(message.engine));+ message.comment !== undefined && (obj.comment = message.comment);+ return obj;+ },++ create(base?: DeepPartial<SQLReviewRule>): SQLReviewRule {+ return SQLReviewRule.fromPartial(base ?? {});+ },++ fromPartial(object: DeepPartial<SQLReviewRule>): SQLReviewRule {+ const message = createBaseSQLReviewRule();+ message.type = object.type ?? "";+ message.level = object.level ?? 0;+ message.payload = object.payload ?? "";+ message.engine = object.engine ?? 0;+ message.comment = object.comment ?? "";+ return message;+ },+};+type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;export type DeepPartial<T> = T extends Builtin ? Tdiff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 547fc86143..211a526ace 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -131,8 +131,11 @@- [MaskingPolicy](#bytebase-store-MaskingPolicy)- [MaskingRulePolicy](#bytebase-store-MaskingRulePolicy)- [MaskingRulePolicy.MaskingRule](#bytebase-store-MaskingRulePolicy-MaskingRule)+ - [SQLReviewPolicy](#bytebase-store-SQLReviewPolicy)+ - [SQLReviewRule](#bytebase-store-SQLReviewRule)- [MaskingExceptionPolicy.MaskingException.Action](#bytebase-store-MaskingExceptionPolicy-MaskingException-Action)+ - [SQLReviewRuleLevel](#bytebase-store-SQLReviewRuleLevel)- [store/project.proto](#store_project-proto)- [Project](#bytebase-store-Project)@@ -2051,6 +2054,41 @@ MaskingExceptionPolicy is the allowlist of users who can access sensitive data.++<a name="bytebase-store-SQLReviewPolicy"></a>++### SQLReviewPolicy++++| Field | Type | Label | Description |+| ----- | ---- | ----- | ----------- |+| name | [string](#string) | | |+| rule_list | [SQLReviewRule](#bytebase-store-SQLReviewRule) | repeated | |+++++++<a name="bytebase-store-SQLReviewRule"></a>++### SQLReviewRule++++| Field | Type | Label | Description |+| ----- | ---- | ----- | ----------- |+| type | [string](#string) | | |+| level | [SQLReviewRuleLevel](#bytebase-store-SQLReviewRuleLevel) | | |+| payload | [string](#string) | | |+| engine | [Engine](#bytebase-store-Engine) | | |+| comment | [string](#string) | | |+++++@@ -2066,6 +2104,20 @@ MaskingExceptionPolicy is the allowlist of users who can access sensitive data.| EXPORT | 2 | |++<a name="bytebase-store-SQLReviewRuleLevel"></a>++### SQLReviewRuleLevel+++| Name | Number | Description |+| ---- | ------ | ----------- |+| LEVEL_UNSPECIFIED | 0 | |+| ERROR | 1 | |+| WARNING | 2 | |+| DISABLED | 3 | |++diff --git a/proto/generated-go/store/policy.pb.go b/proto/generated-go/store/policy.pb.goindex 8c8a82b7df..32c8531568 100644--- a/proto/generated-go/store/policy.pb.go+++ b/proto/generated-go/store/policy.pb.go@@ -21,6 +21,58 @@ const (_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20))+type SQLReviewRuleLevel int32++const (+ SQLReviewRuleLevel_LEVEL_UNSPECIFIED SQLReviewRuleLevel = 0+ SQLReviewRuleLevel_ERROR SQLReviewRuleLevel = 1+ SQLReviewRuleLevel_WARNING SQLReviewRuleLevel = 2+ SQLReviewRuleLevel_DISABLED SQLReviewRuleLevel = 3+)++// Enum value maps for SQLReviewRuleLevel.+var (+ SQLReviewRuleLevel_name = map[int32]string{+ 0: "LEVEL_UNSPECIFIED",+ 1: "ERROR",+ 2: "WARNING",+ 3: "DISABLED",+ }+ SQLReviewRuleLevel_value = map[string]int32{+ "LEVEL_UNSPECIFIED": 0,+ "ERROR": 1,+ "WARNING": 2,+ "DISABLED": 3,+ }+)++func (x SQLReviewRuleLevel) Enum() *SQLReviewRuleLevel {+ p := new(SQLReviewRuleLevel)+ *p = x+ return p+}++func (x SQLReviewRuleLevel) String() string {+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))+}++func (SQLReviewRuleLevel) Descriptor() protoreflect.EnumDescriptor {+ return file_store_policy_proto_enumTypes[0].Descriptor()+}++func (SQLReviewRuleLevel) Type() protoreflect.EnumType {+ return &file_store_policy_proto_enumTypes[0]+}++func (x SQLReviewRuleLevel) Number() protoreflect.EnumNumber {+ return protoreflect.EnumNumber(x)+}++// Deprecated: Use SQLReviewRuleLevel.Descriptor instead.+func (SQLReviewRuleLevel) EnumDescriptor() ([]byte, []int) {+ return file_store_policy_proto_rawDescGZIP(), []int{0}+}+type MaskingExceptionPolicy_MaskingException_Action int32const (@@ -54,11 +106,11 @@ func (x MaskingExceptionPolicy_MaskingException_Action) String() string {}func (MaskingExceptionPolicy_MaskingException_Action) Descriptor() protoreflect.EnumDescriptor {- return file_store_policy_proto_enumTypes[0].Descriptor()+ return file_store_policy_proto_enumTypes[1].Descriptor()}func (MaskingExceptionPolicy_MaskingException_Action) Type() protoreflect.EnumType {- return &file_store_policy_proto_enumTypes[0]+ return &file_store_policy_proto_enumTypes[1]}func (x MaskingExceptionPolicy_MaskingException_Action) Number() protoreflect.EnumNumber {@@ -405,6 +457,140 @@ func (x *MaskingRulePolicy) GetRules() []*MaskingRulePolicy_MaskingRule {return nil}+type SQLReviewPolicy struct {+ state protoimpl.MessageState+ sizeCache protoimpl.SizeCache+ unknownFields protoimpl.UnknownFields++ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`+ RuleList []*SQLReviewRule `protobuf:"bytes,2,rep,name=rule_list,json=ruleList,proto3" json:"rule_list,omitempty"`+}++func (x *SQLReviewPolicy) Reset() {+ *x = SQLReviewPolicy{}+ if protoimpl.UnsafeEnabled {+ mi := &file_store_policy_proto_msgTypes[6]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+ }+}++func (x *SQLReviewPolicy) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*SQLReviewPolicy) ProtoMessage() {}++func (x *SQLReviewPolicy) ProtoReflect() protoreflect.Message {+ mi := &file_store_policy_proto_msgTypes[6]+ if protoimpl.UnsafeEnabled && x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use SQLReviewPolicy.ProtoReflect.Descriptor instead.+func (*SQLReviewPolicy) Descriptor() ([]byte, []int) {+ return file_store_policy_proto_rawDescGZIP(), []int{6}+}++func (x *SQLReviewPolicy) GetName() string {+ if x != nil {+ return x.Name+ }+ return ""+}++func (x *SQLReviewPolicy) GetRuleList() []*SQLReviewRule {+ if x != nil {+ return x.RuleList+ }+ return nil+}++type SQLReviewRule struct {+ state protoimpl.MessageState+ sizeCache protoimpl.SizeCache+ unknownFields protoimpl.UnknownFields++ Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`+ Level SQLReviewRuleLevel `protobuf:"varint,2,opt,name=level,proto3,enum=bytebase.store.SQLReviewRuleLevel" json:"level,omitempty"`+ Payload string `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`+ Engine Engine `protobuf:"varint,4,opt,name=engine,proto3,enum=bytebase.store.Engine" json:"engine,omitempty"`+ Comment string `protobuf:"bytes,5,opt,name=comment,proto3" json:"comment,omitempty"`+}++func (x *SQLReviewRule) Reset() {+ *x = SQLReviewRule{}+ if protoimpl.UnsafeEnabled {+ mi := &file_store_policy_proto_msgTypes[7]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+ }+}++func (x *SQLReviewRule) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*SQLReviewRule) ProtoMessage() {}++func (x *SQLReviewRule) ProtoReflect() protoreflect.Message {+ mi := &file_store_policy_proto_msgTypes[7]+ if protoimpl.UnsafeEnabled && x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use SQLReviewRule.ProtoReflect.Descriptor instead.+func (*SQLReviewRule) Descriptor() ([]byte, []int) {+ return file_store_policy_proto_rawDescGZIP(), []int{7}+}++func (x *SQLReviewRule) GetType() string {+ if x != nil {+ return x.Type+ }+ return ""+}++func (x *SQLReviewRule) GetLevel() SQLReviewRuleLevel {+ if x != nil {+ return x.Level+ }+ return SQLReviewRuleLevel_LEVEL_UNSPECIFIED+}++func (x *SQLReviewRule) GetPayload() string {+ if x != nil {+ return x.Payload+ }+ return ""+}++func (x *SQLReviewRule) GetEngine() Engine {+ if x != nil {+ return x.Engine+ }+ return Engine_ENGINE_UNSPECIFIED+}++func (x *SQLReviewRule) GetComment() string {+ if x != nil {+ return x.Comment+ }+ return ""+}+type MaskingExceptionPolicy_MaskingException struct {state protoimpl.MessageStatesizeCache protoimpl.SizeCache@@ -425,7 +611,7 @@ type MaskingExceptionPolicy_MaskingException struct {func (x *MaskingExceptionPolicy_MaskingException) Reset() {*x = MaskingExceptionPolicy_MaskingException{}if protoimpl.UnsafeEnabled {- mi := &file_store_policy_proto_msgTypes[6]+ mi := &file_store_policy_proto_msgTypes[8]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -438,7 +624,7 @@ func (x *MaskingExceptionPolicy_MaskingException) String() string {func (*MaskingExceptionPolicy_MaskingException) ProtoMessage() {}func (x *MaskingExceptionPolicy_MaskingException) ProtoReflect() protoreflect.Message {- mi := &file_store_policy_proto_msgTypes[6]+ mi := &file_store_policy_proto_msgTypes[8]if protoimpl.UnsafeEnabled && x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -496,7 +682,7 @@ type MaskingRulePolicy_MaskingRule struct {func (x *MaskingRulePolicy_MaskingRule) Reset() {*x = MaskingRulePolicy_MaskingRule{}if protoimpl.UnsafeEnabled {- mi := &file_store_policy_proto_msgTypes[7]+ mi := &file_store_policy_proto_msgTypes[9]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -509,7 +695,7 @@ func (x *MaskingRulePolicy_MaskingRule) String() string {func (*MaskingRulePolicy_MaskingRule) ProtoMessage() {}func (x *MaskingRulePolicy_MaskingRule) ProtoReflect() protoreflect.Message {- mi := &file_store_policy_proto_msgTypes[7]+ mi := &file_store_policy_proto_msgTypes[9]if protoimpl.UnsafeEnabled && x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -620,9 +806,33 @@ var file_store_policy_proto_rawDesc = []byte{0x61, 0x73, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01,0x28, 0x0e, 0x32, 0x1c, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74,0x6f, 0x72, 0x65, 0x2e, 0x4d, 0x61, 0x73, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c,- 0x52, 0x0c, 0x6d, 0x61, 0x73, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x42, 0x14,- 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x73,- 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,+ 0x52, 0x0c, 0x6d, 0x61, 0x73, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x22, 0x61,+ 0x0a, 0x0f, 0x53, 0x51, 0x4c, 0x52, 0x65, 0x76, 0x69, 0x65, 0x77, 0x50, 0x6f, 0x6c, 0x69, 0x63,+ 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,+ 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x3a, 0x0a, 0x09, 0x72, 0x75, 0x6c, 0x65, 0x5f, 0x6c, 0x69,+ 0x73, 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62,+ 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x53, 0x51, 0x4c, 0x52, 0x65, 0x76,+ 0x69, 0x65, 0x77, 0x52, 0x75, 0x6c, 0x65, 0x52, 0x08, 0x72, 0x75, 0x6c, 0x65, 0x4c, 0x69, 0x73,+ 0x74, 0x22, 0xc1, 0x01, 0x0a, 0x0d, 0x53, 0x51, 0x4c, 0x52, 0x65, 0x76, 0x69, 0x65, 0x77, 0x52,+ 0x75, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,+ 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x38, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c,+ 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x22, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73,+ 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x53, 0x51, 0x4c, 0x52, 0x65, 0x76, 0x69, 0x65,+ 0x77, 0x52, 0x75, 0x6c, 0x65, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65,+ 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x03, 0x20, 0x01,+ 0x28, 0x09, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x2e, 0x0a, 0x06, 0x65,+ 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x16, 0x2e, 0x62, 0x79,+ 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x6e, 0x67,+ 0x69, 0x6e, 0x65, 0x52, 0x06, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63,+ 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f,+ 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x2a, 0x51, 0x0a, 0x12, 0x53, 0x51, 0x4c, 0x52, 0x65, 0x76, 0x69,+ 0x65, 0x77, 0x52, 0x75, 0x6c, 0x65, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x15, 0x0a, 0x11, 0x4c,+ 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44,+ 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x0b, 0x0a,+ 0x07, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49,+ 0x53, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x03, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65,+ 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06,+ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,}var (@@ -637,38 +847,45 @@ func file_store_policy_proto_rawDescGZIP() []byte {return file_store_policy_proto_rawDescData}-var file_store_policy_proto_enumTypes = make([]protoimpl.EnumInfo, 1)-var file_store_policy_proto_msgTypes = make([]protoimpl.MessageInfo, 8)+var file_store_policy_proto_enumTypes = make([]protoimpl.EnumInfo, 2)+var file_store_policy_proto_msgTypes = make([]protoimpl.MessageInfo, 10)var file_store_policy_proto_goTypes = []interface{}{- (MaskingExceptionPolicy_MaskingException_Action)(0), // 0: bytebase.store.MaskingExceptionPolicy.MaskingException.Action- (*IamPolicy)(nil), // 1: bytebase.store.IamPolicy- (*Binding)(nil), // 2: bytebase.store.Binding- (*MaskingPolicy)(nil), // 3: bytebase.store.MaskingPolicy- (*MaskData)(nil), // 4: bytebase.store.MaskData- (*MaskingExceptionPolicy)(nil), // 5: bytebase.store.MaskingExceptionPolicy- (*MaskingRulePolicy)(nil), // 6: bytebase.store.MaskingRulePolicy- (*MaskingExceptionPolicy_MaskingException)(nil), // 7: bytebase.store.MaskingExceptionPolicy.MaskingException- (*MaskingRulePolicy_MaskingRule)(nil), // 8: bytebase.store.MaskingRulePolicy.MaskingRule- (*expr.Expr)(nil), // 9: google.type.Expr- (MaskingLevel)(0), // 10: bytebase.store.MaskingLevel+ (SQLReviewRuleLevel)(0), // 0: bytebase.store.SQLReviewRuleLevel+ (MaskingExceptionPolicy_MaskingException_Action)(0), // 1: bytebase.store.MaskingExceptionPolicy.MaskingException.Action+ (*IamPolicy)(nil), // 2: bytebase.store.IamPolicy+ (*Binding)(nil), // 3: bytebase.store.Binding+ (*MaskingPolicy)(nil), // 4: bytebase.store.MaskingPolicy+ (*MaskData)(nil), // 5: bytebase.store.MaskData+ (*MaskingExceptionPolicy)(nil), // 6: bytebase.store.MaskingExceptionPolicy+ (*MaskingRulePolicy)(nil), // 7: bytebase.store.MaskingRulePolicy+ (*SQLReviewPolicy)(nil), // 8: bytebase.store.SQLReviewPolicy+ (*SQLReviewRule)(nil), // 9: bytebase.store.SQLReviewRule+ (*MaskingExceptionPolicy_MaskingException)(nil), // 10: bytebase.store.MaskingExceptionPolicy.MaskingException+ (*MaskingRulePolicy_MaskingRule)(nil), // 11: bytebase.store.MaskingRulePolicy.MaskingRule+ (*expr.Expr)(nil), // 12: google.type.Expr+ (MaskingLevel)(0), // 13: bytebase.store.MaskingLevel+ (Engine)(0), // 14: bytebase.store.Engine}var file_store_policy_proto_depIdxs = []int32{- 2, // 0: bytebase.store.IamPolicy.bindings:type_name -> bytebase.store.Binding- 9, // 1: bytebase.store.Binding.condition:type_name -> google.type.Expr- 4, // 2: bytebase.store.MaskingPolicy.mask_data:type_name -> bytebase.store.MaskData- 10, // 3: bytebase.store.MaskData.masking_level:type_name -> bytebase.store.MaskingLevel- 7, // 4: bytebase.store.MaskingExceptionPolicy.masking_exceptions:type_name -> bytebase.store.MaskingExceptionPolicy.MaskingException- 8, // 5: bytebase.store.MaskingRulePolicy.rules:type_name -> bytebase.store.MaskingRulePolicy.MaskingRule- 0, // 6: bytebase.store.MaskingExceptionPolicy.MaskingException.action:type_name -> bytebase.store.MaskingExceptionPolicy.MaskingException.Action- 10, // 7: bytebase.store.MaskingExceptionPolicy.MaskingException.masking_level:type_name -> bytebase.store.MaskingLevel- 9, // 8: bytebase.store.MaskingExceptionPolicy.MaskingException.condition:type_name -> google.type.Expr- 9, // 9: bytebase.store.MaskingRulePolicy.MaskingRule.condition:type_name -> google.type.Expr- 10, // 10: bytebase.store.MaskingRulePolicy.MaskingRule.masking_level:type_name -> bytebase.store.MaskingLevel- 11, // [11:11] is the sub-list for method output_type- 11, // [11:11] is the sub-list for method input_type- 11, // [11:11] is the sub-list for extension type_name- 11, // [11:11] is the sub-list for extension extendee- 0, // [0:11] is the sub-list for field type_name+ 3, // 0: bytebase.store.IamPolicy.bindings:type_name -> bytebase.store.Binding+ 12, // 1: bytebase.store.Binding.condition:type_name -> google.type.Expr+ 5, // 2: bytebase.store.MaskingPolicy.mask_data:type_name -> bytebase.store.MaskData+ 13, // 3: bytebase.store.MaskData.masking_level:type_name -> bytebase.store.MaskingLevel+ 10, // 4: bytebase.store.MaskingExceptionPolicy.masking_exceptions:type_name -> bytebase.store.MaskingExceptionPolicy.MaskingException+ 11, // 5: bytebase.store.MaskingRulePolicy.rules:type_name -> bytebase.store.MaskingRulePolicy.MaskingRule+ 9, // 6: bytebase.store.SQLReviewPolicy.rule_list:type_name -> bytebase.store.SQLReviewRule+ 0, // 7: bytebase.store.SQLReviewRule.level:type_name -> bytebase.store.SQLReviewRuleLevel+ 14, // 8: bytebase.store.SQLReviewRule.engine:type_name -> bytebase.store.Engine+ 1, // 9: bytebase.store.MaskingExceptionPolicy.MaskingException.action:type_name -> bytebase.store.MaskingExceptionPolicy.MaskingException.Action+ 13, // 10: bytebase.store.MaskingExceptionPolicy.MaskingException.masking_level:type_name -> bytebase.store.MaskingLevel+ 12, // 11: bytebase.store.MaskingExceptionPolicy.MaskingException.condition:type_name -> google.type.Expr+ 12, // 12: bytebase.store.MaskingRulePolicy.MaskingRule.condition:type_name -> google.type.Expr+ 13, // 13: bytebase.store.MaskingRulePolicy.MaskingRule.masking_level:type_name -> bytebase.store.MaskingLevel+ 14, // [14:14] is the sub-list for method output_type+ 14, // [14:14] is the sub-list for method input_type+ 14, // [14:14] is the sub-list for extension type_name+ 14, // [14:14] is the sub-list for extension extendee+ 0, // [0:14] is the sub-list for field type_name}func init() { file_store_policy_proto_init() }@@ -751,7 +968,7 @@ func file_store_policy_proto_init() {}}file_store_policy_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {- switch v := v.(*MaskingExceptionPolicy_MaskingException); i {+ switch v := v.(*SQLReviewPolicy); i {case 0:return &v.statecase 1:@@ -763,6 +980,30 @@ func file_store_policy_proto_init() {}}file_store_policy_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {+ switch v := v.(*SQLReviewRule); i {+ case 0:+ return &v.state+ case 1:+ return &v.sizeCache+ case 2:+ return &v.unknownFields+ default:+ return nil+ }+ }+ file_store_policy_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {+ switch v := v.(*MaskingExceptionPolicy_MaskingException); i {+ case 0:+ return &v.state+ case 1:+ return &v.sizeCache+ case 2:+ return &v.unknownFields+ default:+ return nil+ }+ }+ file_store_policy_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {switch v := v.(*MaskingRulePolicy_MaskingRule); i {case 0:return &v.state@@ -780,8 +1021,8 @@ func file_store_policy_proto_init() {File: protoimpl.DescBuilder{GoPackagePath: reflect.TypeOf(x{}).PkgPath(),RawDescriptor: file_store_policy_proto_rawDesc,- NumEnums: 1,- NumMessages: 8,+ NumEnums: 2,+ NumMessages: 10,NumExtensions: 0,NumServices: 0,},diff --git a/proto/store/policy.proto b/proto/store/policy.protoindex a18a43284c..945ad0166e 100644--- a/proto/store/policy.proto+++ b/proto/store/policy.proto@@ -79,3 +79,23 @@ message MaskingRulePolicy {}repeated MaskingRule rules = 1;}++message SQLReviewPolicy {+ string name = 1;+ repeated SQLReviewRule rule_list = 2;+}++message SQLReviewRule {+ string type = 1;+ SQLReviewRuleLevel level = 2;+ string payload = 3;+ Engine engine = 4;+ string comment = 5;+}++enum SQLReviewRuleLevel {+ LEVEL_UNSPECIFIED = 0;+ ERROR = 1;+ WARNING = 2;+ DISABLED = 3;+}