Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add field masker register
d-bytebase32c0816f4a92
diff --git a/backend/plugin/parser/base/interface.go b/backend/plugin/parser/base/interface.gonew file mode 100644index 0000000000..6e43b576be--- /dev/null+++ b/backend/plugin/parser/base/interface.go@@ -0,0 +1,37 @@+package base++import (+ "fmt"+ "sync"++ "github.com/bytebase/bytebase/backend/plugin/db"+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"+)++var (+ mux sync.Mutex+ QueryValidators = make(map[storepb.Engine]ValidateSQLForEditorFunc)+ FieldMaskers = make(map[storepb.Engine]GetMaskedFieldsFunc)+)++type ValidateSQLForEditorFunc func(string) bool++type GetMaskedFieldsFunc func(string, string, *db.SensitiveSchemaInfo) ([]db.SensitiveField, error)++func RegisterQueryValidator(engine storepb.Engine, f ValidateSQLForEditorFunc) {+ mux.Lock()+ defer mux.Unlock()+ if _, dup := QueryValidators[engine]; dup {+ panic(fmt.Sprintf("Register called twice %s", engine))+ }+ QueryValidators[engine] = f+}++func RegisterGetMaskedFieldsFunc(engine storepb.Engine, f GetMaskedFieldsFunc) {+ mux.Lock()+ defer mux.Unlock()+ if _, dup := FieldMaskers[engine]; dup {+ panic(fmt.Sprintf("Register called twice %s", engine))+ }+ FieldMaskers[engine] = f+}diff --git a/backend/plugin/parser/base/query.go b/backend/plugin/parser/base/query.goindex 63f273bb9c..1b8a6083cb 100644--- a/backend/plugin/parser/base/query.go+++ b/backend/plugin/parser/base/query.go@@ -3,27 +3,8 @@ package baseimport ("fmt""strings"- "sync"-- storepb "github.com/bytebase/bytebase/proto/generated-go/store"-)--var (- mux sync.Mutex- QueryValidator = make(map[storepb.Engine]ValidateSQLForEditorFunc))-type ValidateSQLForEditorFunc func(string) bool--func RegisterQueryValidator(engine storepb.Engine, f ValidateSQLForEditorFunc) {- mux.Lock()- defer mux.Unlock()- if _, dup := QueryValidator[engine]; dup {- panic(fmt.Sprintf("Register called twice %s", engine))- }- QueryValidator[engine] = f-}-// SchemaResource is the resource of the schema.type SchemaResource struct {Database stringdiff --git a/backend/plugin/parser/sql/utils.go b/backend/plugin/parser/sql/utils.goindex 6600652aca..aea2785f9e 100644--- a/backend/plugin/parser/sql/utils.go+++ b/backend/plugin/parser/sql/utils.go@@ -137,6 +137,6 @@ func ExtractSensitiveField(dbType storepb.Engine, statement string, currentDatab// 2. SELECT statement// We also support CTE with SELECT statements, but not with DML statements.func ValidateSQLForEditor(engine storepb.Engine, statement string) bool {- f := base.QueryValidator[engine]+ f := base.QueryValidators[engine]return f(statement)}