Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: change field names

d-bytebaseb95c58330c6e
diff --git a/backend/plugin/db/util/mask_sensitive_data.go b/backend/plugin/db/util/mask_sensitive_data.go
index 7de229cb8c..c5c287ffb1 100644
--- a/backend/plugin/db/util/mask_sensitive_data.go
+++ b/backend/plugin/db/util/mask_sensitive_data.go
@@ -31,7 +31,7 @@ func extractSensitiveField(dbType db.Type, statement string, currentDatabase str
currentDatabase: currentDatabase,
schemaInfo: schemaInfo,
}
- result, err := extractor.extractTiDBSensitiveField(statement)
+ result, err := extractor.ExtractTiDBSensitiveField(statement)
if err != nil {
return nil, err
}
@@ -52,7 +52,7 @@ func extractSensitiveField(dbType db.Type, statement string, currentDatabase str
currentDatabase: currentDatabase,
schemaInfo: schemaInfo,
}
- result, err := extractor.extractMySQLSensitiveField(statement)
+ result, err := extractor.ExtractMySQLSensitiveField(statement)
if err != nil {
return nil, err
}
@@ -61,7 +61,7 @@ func extractSensitiveField(dbType db.Type, statement string, currentDatabase str
extractor := &PGSensitiveFieldExtractor{
schemaInfo: schemaInfo,
}
- result, err := extractor.extractPostgreSQLSensitiveField(statement)
+ result, err := extractor.ExtractPostgreSQLSensitiveField(statement)
if err != nil {
tableNotFound := regexp.MustCompile("^Table \"(.*)\\.(.*)\" not found$")
content := tableNotFound.FindStringSubmatch(err.Error())
@@ -95,8 +95,8 @@ func extractSensitiveField(dbType db.Type, statement string, currentDatabase str
return result, nil
case db.Snowflake:
extractor := &SnowSensitiveFieldExtractor{
- currentDatabase: currentDatabase,
- schemaInfo: schemaInfo,
+ CurrentDatabase: currentDatabase,
+ SchemaInfo: schemaInfo,
}
result, err := extractor.extractSnowsqlSensitiveFields(statement)
if err != nil {
@@ -105,10 +105,10 @@ func extractSensitiveField(dbType db.Type, statement string, currentDatabase str
return result, nil
case db.MSSQL:
extractor := &TSQLSensitiveFieldExtractor{
- currentDatabase: currentDatabase,
- schemaInfo: schemaInfo,
+ CurrentDatabase: currentDatabase,
+ SchemaInfo: schemaInfo,
}
- result, err := extractor.extractTSqlSensitiveFields(statement)
+ result, err := extractor.ExtractTSqlSensitiveFields(statement)
if err != nil {
return nil, err
}
diff --git a/backend/plugin/db/util/mask_sensitive_data_mysql.go b/backend/plugin/db/util/mask_sensitive_data_mysql.go
index d20e0d6da5..0804c6e141 100644
--- a/backend/plugin/db/util/mask_sensitive_data_mysql.go
+++ b/backend/plugin/db/util/mask_sensitive_data_mysql.go
@@ -26,7 +26,7 @@ type MySQLSensitiveFieldExtractor struct {
fromFieldList []base.FieldInfo
}
-func (extractor *MySQLSensitiveFieldExtractor) extractMySQLSensitiveField(statement string) ([]db.SensitiveField, error) {
+func (extractor *MySQLSensitiveFieldExtractor) ExtractMySQLSensitiveField(statement string) ([]db.SensitiveField, error) {
list, err := mysqlparser.ParseMySQL(statement)
if err != nil {
return nil, err
diff --git a/backend/plugin/db/util/mask_sensitive_data_psql.go b/backend/plugin/db/util/mask_sensitive_data_psql.go
index d6c7d71389..8490212478 100644
--- a/backend/plugin/db/util/mask_sensitive_data_psql.go
+++ b/backend/plugin/db/util/mask_sensitive_data_psql.go
@@ -45,7 +45,7 @@ type PGSensitiveFieldExtractor struct {
fromFieldList []base.FieldInfo
}
-func (extractor *PGSensitiveFieldExtractor) extractPostgreSQLSensitiveField(statement string) ([]db.SensitiveField, error) {
+func (extractor *PGSensitiveFieldExtractor) ExtractPostgreSQLSensitiveField(statement string) ([]db.SensitiveField, error) {
res, err := pgquery.Parse(statement)
if err != nil {
return nil, err
diff --git a/backend/plugin/db/util/mask_sensitive_data_snowsql.go b/backend/plugin/db/util/mask_sensitive_data_snowsql.go
index 61027e007d..001f87c526 100644
--- a/backend/plugin/db/util/mask_sensitive_data_snowsql.go
+++ b/backend/plugin/db/util/mask_sensitive_data_snowsql.go
@@ -18,8 +18,8 @@ import (
type SnowSensitiveFieldExtractor struct {
// For Oracle, we need to know the current database to determine if the table is in the current schema.
- currentDatabase string
- schemaInfo *db.SensitiveSchemaInfo
+ CurrentDatabase string
+ SchemaInfo *db.SensitiveSchemaInfo
cteOuterSchemaInfo []db.TableSchema
// SELECT statement specific field.
@@ -366,7 +366,7 @@ func (extractor *SnowSensitiveFieldExtractor) evalSnowSQLExprMaskingLevel(ctx an
}
return fieldInfo.Name, fieldInfo.MaskingLevel, nil
case *parser.Object_nameContext:
- normalizedDatabaseName, normalizedSchemaName, normalizedTableName := normalizedObjectName(ctx, extractor.currentDatabase, "PUBLIC")
+ normalizedDatabaseName, normalizedSchemaName, normalizedTableName := normalizedObjectName(ctx, extractor.CurrentDatabase, "PUBLIC")
fieldInfo, err := extractor.snowflakeGetField(normalizedDatabaseName, normalizedSchemaName, normalizedTableName, "")
if err != nil {
return "", storepb.MaskingLevel_MASKING_LEVEL_UNSPECIFIED, errors.Wrapf(err, "failed to check whether the object %q is sensitive near line %d", normalizedTableName, ctx.GetStart().GetLine())
@@ -935,7 +935,7 @@ func (extractor *SnowSensitiveFieldExtractor) extractSnowsqlSensitiveFieldsObjec
var result []base.FieldInfo
if objectName := ctx.Object_name(); objectName != nil {
- normalizedDatabaseName, tableSchema, err := extractor.snowsqlFindTableSchema(objectName, extractor.currentDatabase, "PUBLIC")
+ normalizedDatabaseName, tableSchema, err := extractor.snowsqlFindTableSchema(objectName, extractor.CurrentDatabase, "PUBLIC")
if err != nil {
return nil, err
}
@@ -1084,7 +1084,7 @@ func (extractor *SnowSensitiveFieldExtractor) snowsqlFindTableSchema(objectName
}
}
normalizedDatabaseName, normalizedSchemaName, normalizedTableName = normalizedObjectName(objectName, normalizedFallbackDatabaseName, normalizedFallbackSchemaName)
- for _, databaseSchema := range extractor.schemaInfo.DatabaseList {
+ for _, databaseSchema := range extractor.SchemaInfo.DatabaseList {
if normalizedDatabaseName != "" && normalizedDatabaseName != databaseSchema.Name {
continue
}
diff --git a/backend/plugin/db/util/mask_sensitive_data_tidb.go b/backend/plugin/db/util/mask_sensitive_data_tidb.go
index 5e69aac68c..698a5e35e3 100644
--- a/backend/plugin/db/util/mask_sensitive_data_tidb.go
+++ b/backend/plugin/db/util/mask_sensitive_data_tidb.go
@@ -27,7 +27,7 @@ type TiDBSensitiveFieldExtractor struct {
fromFieldList []base.FieldInfo
}
-func (extractor *TiDBSensitiveFieldExtractor) extractTiDBSensitiveField(statement string) ([]db.SensitiveField, error) {
+func (extractor *TiDBSensitiveFieldExtractor) ExtractTiDBSensitiveField(statement string) ([]db.SensitiveField, error) {
p := parser.New()
// To support MySQL8 window function syntax.
@@ -613,7 +613,7 @@ func (extractor *TiDBSensitiveFieldExtractor) buildTableSchemaForView(viewName s
currentDatabase: extractor.currentDatabase,
schemaInfo: extractor.schemaInfo,
}
- fields, err := newExtractor.extractTiDBSensitiveField(definition)
+ fields, err := newExtractor.ExtractTiDBSensitiveField(definition)
if err != nil {
return db.TableSchema{}, err
}
diff --git a/backend/plugin/db/util/mask_sensitive_data_tsql.go b/backend/plugin/db/util/mask_sensitive_data_tsql.go
index 6a0c422ce7..fd3195da6b 100644
--- a/backend/plugin/db/util/mask_sensitive_data_tsql.go
+++ b/backend/plugin/db/util/mask_sensitive_data_tsql.go
@@ -18,15 +18,15 @@ import (
type TSQLSensitiveFieldExtractor struct {
// For Oracle, we need to know the current database to determine if the table is in the current schema.
- currentDatabase string
- schemaInfo *db.SensitiveSchemaInfo
+ CurrentDatabase string
+ SchemaInfo *db.SensitiveSchemaInfo
cteOuterSchemaInfo []db.TableSchema
// SELECT statement specific field.
fromFieldList []base.FieldInfo
}
-func (extractor *TSQLSensitiveFieldExtractor) extractTSqlSensitiveFields(sql string) ([]db.SensitiveField, error) {
+func (extractor *TSQLSensitiveFieldExtractor) ExtractTSqlSensitiveFields(sql string) ([]db.SensitiveField, error) {
tree, err := tsqlparser.ParseTSQL(sql)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse snowsql")
@@ -419,7 +419,7 @@ func (extractor *TSQLSensitiveFieldExtractor) extractTSqlSensitiveFieldsFromTabl
var err error
// TODO(zp): handle other cases likes ROWSET_FUNCTION.
if ctx.Full_table_name() != nil {
- normalizedDatabaseName, tableSchema, err := extractor.tsqlFindTableSchema(ctx.Full_table_name(), "", extractor.currentDatabase, "dbo")
+ normalizedDatabaseName, tableSchema, err := extractor.tsqlFindTableSchema(ctx.Full_table_name(), "", extractor.CurrentDatabase, "dbo")
if err != nil {
return nil, err
}
@@ -558,7 +558,7 @@ func (extractor *TSQLSensitiveFieldExtractor) tsqlFindTableSchema(fullTableName
// TODO(zp): How do we handle the linked server?
return "", db.TableSchema{}, errors.Errorf("linked server is not supported yet, but found %q", fullTableName.GetText())
}
- for _, databaseSchema := range extractor.schemaInfo.DatabaseList {
+ for _, databaseSchema := range extractor.SchemaInfo.DatabaseList {
if normalizedDatabaseName != "" && !extractor.isIdentifierEqual(normalizedDatabaseName, databaseSchema.Name) {
continue
}
@@ -764,7 +764,7 @@ func (extractor *TSQLSensitiveFieldExtractor) tsqlIsFieldSensitive(normalizedDat
// isIdentifierEqual compares the identifier with the given normalized parts, returns true if they are equal.
// It will consider the case sensitivity based on the current database.
func (extractor *TSQLSensitiveFieldExtractor) isIdentifierEqual(a, b string) bool {
- if !extractor.schemaInfo.IgnoreCaseSensitive {
+ if !extractor.SchemaInfo.IgnoreCaseSensitive {
return a == b
}
if len(a) != len(b) {
@@ -1042,8 +1042,8 @@ func (extractor *TSQLSensitiveFieldExtractor) evalExpressionElemMaskingLevel(ctx
case *parser.SubqueryContext:
// For subquery, we clone the current extractor, reset the from list, but keep the cte, and then extract the sensitive fields from the subquery
cloneExtractor := &TSQLSensitiveFieldExtractor{
- currentDatabase: extractor.currentDatabase,
- schemaInfo: extractor.schemaInfo,
+ CurrentDatabase: extractor.CurrentDatabase,
+ SchemaInfo: extractor.SchemaInfo,
cteOuterSchemaInfo: extractor.cteOuterSchemaInfo,
}
fieldInfo, err := cloneExtractor.extractTSqlSensitiveFieldsFromSubquery(ctx)