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 func not supported error (#15480)
rebelice4cb632836f34
diff --git a/backend/api/v1/query_result_masker.go b/backend/api/v1/query_result_masker.goindex 5cae9ea30f..5282b27ad4 100644--- a/backend/api/v1/query_result_masker.go+++ b/backend/api/v1/query_result_masker.go@@ -52,8 +52,11 @@ func (s *QueryResultMasker) MaskResults(ctx context.Context, spans []*base.Queryif strings.HasPrefix(strings.TrimSpace(results[i].Statement), "EXPLAIN") {continue}+ if results[i].Error == "" && spans[i].FunctionNotSupportedError != nil {+ return errors.Errorf("masking error: %v", spans[i].FunctionNotSupportedError)+ }if results[i].Error == "" && spans[i].NotFoundError != nil {- return errors.Errorf("query span error: %v", spans[i].NotFoundError)+ return errors.Errorf("masking error: %v", spans[i].NotFoundError)}// Skip masking for error result.if results[i].Error != "" && len(results[i].Rows) == 0 {diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex 0c1a74e893..6950c38cb0 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -510,8 +510,13 @@ func queryRetry(}// The second query span should not tolerate any error, but we should retail the original error from database if possible.for i, result := range results {- if i < len(spans) && result.Error == "" && spans[i].NotFoundError != nil {- return nil, nil, duration, status.Errorf(codes.Internal, "failed to get query span: %v", spans[i].NotFoundError)+ if i < len(spans) && result.Error == "" {+ if spans[i].FunctionNotSupportedError != nil {+ return nil, nil, duration, status.Errorf(codes.Internal, "failed to mask data: %v", spans[i].FunctionNotSupportedError)+ }+ if spans[i].NotFoundError != nil {+ return nil, nil, duration, status.Errorf(codes.Internal, "failed to mask data: %v", spans[i].NotFoundError)+ }}}diff --git a/backend/plugin/parser/base/span.go b/backend/plugin/parser/base/span.goindex 6ed3c872ac..e1b6ea022c 100644--- a/backend/plugin/parser/base/span.go+++ b/backend/plugin/parser/base/span.go@@ -62,8 +62,9 @@ type QuerySpan struct {SourceColumns SourceColumnSet// PredicateColumns are the source columns contributing to the span.// PredicateColumns here are the source columns for the where conditions.- PredicateColumns SourceColumnSet- NotFoundError error+ PredicateColumns SourceColumnSet+ NotFoundError error+ FunctionNotSupportedError error}// QuerySpanResult is the result column of a query span.diff --git a/backend/plugin/parser/errors/resources.go b/backend/plugin/parser/errors/resources.goindex ff865272f1..c93194e03f 100644--- a/backend/plugin/parser/errors/resources.go+++ b/backend/plugin/parser/errors/resources.go@@ -88,3 +88,25 @@ func (e *TypeNotSupportedError) Error() string {func (e *TypeNotSupportedError) Unwrap() error {return e.Err}++type FunctionNotSupportedError struct {+ Err error+ Function string+ Definition string+}++func (e *FunctionNotSupportedError) Error() string {+ parts := []string{+ fmt.Sprintf("function is not supported with data masking: %s", e.Function),+ }++ if e.Err != nil {+ parts = append(parts, fmt.Sprintf("err: %s", e.Err.Error()))+ }++ if e.Definition != "" {+ parts = append(parts, fmt.Sprintf("definition: %s", e.Definition))+ }++ return strings.Join(parts, ", ")+}diff --git a/backend/plugin/parser/pg/query_span_extractor.go b/backend/plugin/parser/pg/query_span_extractor.goindex b37f772014..6724e8f551 100644--- a/backend/plugin/parser/pg/query_span_extractor.go+++ b/backend/plugin/parser/pg/query_span_extractor.go@@ -148,6 +148,21 @@ func (q *querySpanExtractor) getQuerySpan(ctx context.Context, stmt string) (*batableSource, err := q.extractTableSourceFromNode(ast.Stmt)if err != nil {+ var functionNotSupported *parsererror.FunctionNotSupportedError+ if errors.As(err, &functionNotSupported) {+ // Sadly, getAccessTables() returns nil for resources not found.+ if len(accessTables) == 0 {+ accessTables[base.ColumnResource{+ Database: q.defaultDatabase,+ }] = true+ }+ return &base.QuerySpan{+ Type: base.Select,+ SourceColumns: accessTables,+ Results: []base.QuerySpanResult{},+ NotFoundError: functionNotSupported,+ }, nil+ }var resourceNotFound *parsererror.ResourceNotFoundErrorif errors.As(err, &resourceNotFound) {// Sadly, getAccessTables() returns nil for resources not found.@@ -529,9 +544,13 @@ func (q *querySpanExtractor) findFunctionDefine(schemaName, funcName string, arg}function := candidates[0]- columns, err := q.getColumnsForFunction(fmt.Sprintf("%s.%s", schemaName, funcName), function.Definition)+ functionName := fmt.Sprintf("%s.%s", schemaName, funcName)+ columns, err := q.getColumnsForFunction(functionName, function.Definition)if err != nil {- return nil, err+ return nil, &parsererror.FunctionNotSupportedError{+ Err: err,+ Function: functionName,+ }}return &base.PseudoTable{Columns: columns,