sql writer
This commit is contained in:
74
pkg/writers/pgsql/audit.go
Normal file
74
pkg/writers/pgsql/audit.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package pgsql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// AuditConfig defines audit configuration for tables
|
||||
type AuditConfig struct {
|
||||
// EnabledTables maps table names (schema.table or just table) to audit settings
|
||||
EnabledTables map[string]*TableAuditConfig
|
||||
// AuditSchema is where audit tables are created (default: same as table schema)
|
||||
AuditSchema string
|
||||
// UserFunction is the function to get current user (default: current_user)
|
||||
UserFunction string
|
||||
}
|
||||
|
||||
// TableAuditConfig defines audit settings for a specific table
|
||||
type TableAuditConfig struct {
|
||||
// TableName is the name of the table to audit
|
||||
TableName string
|
||||
// SchemaName is the schema of the table
|
||||
SchemaName string
|
||||
// TablePrefix for compatibility with old audit system
|
||||
TablePrefix string
|
||||
// AuditInsert tracks INSERT operations
|
||||
AuditInsert bool
|
||||
// AuditUpdate tracks UPDATE operations
|
||||
AuditUpdate bool
|
||||
// AuditDelete tracks DELETE operations
|
||||
AuditDelete bool
|
||||
// ExcludedColumns are columns to skip from audit
|
||||
ExcludedColumns []string
|
||||
// EncryptedColumns are columns to hide in audit (show as ***)
|
||||
EncryptedColumns []string
|
||||
}
|
||||
|
||||
// NewAuditConfig creates a default audit configuration
|
||||
func NewAuditConfig() *AuditConfig {
|
||||
return &AuditConfig{
|
||||
EnabledTables: make(map[string]*TableAuditConfig),
|
||||
AuditSchema: "public",
|
||||
UserFunction: "current_user",
|
||||
}
|
||||
}
|
||||
|
||||
// EnableTableAudit enables audit for a specific table
|
||||
func (ac *AuditConfig) EnableTableAudit(schemaName, tableName string) *TableAuditConfig {
|
||||
key := fmt.Sprintf("%s.%s", schemaName, tableName)
|
||||
config := &TableAuditConfig{
|
||||
TableName: tableName,
|
||||
SchemaName: schemaName,
|
||||
TablePrefix: "",
|
||||
AuditInsert: true,
|
||||
AuditUpdate: true,
|
||||
AuditDelete: true,
|
||||
ExcludedColumns: []string{"updatecnt", "prefix"},
|
||||
EncryptedColumns: []string{},
|
||||
}
|
||||
ac.EnabledTables[key] = config
|
||||
return config
|
||||
}
|
||||
|
||||
// IsTableAudited checks if a table is configured for auditing
|
||||
func (ac *AuditConfig) IsTableAudited(schemaName, tableName string) bool {
|
||||
key := fmt.Sprintf("%s.%s", schemaName, tableName)
|
||||
_, exists := ac.EnabledTables[key]
|
||||
return exists
|
||||
}
|
||||
|
||||
// GetTableConfig returns the audit config for a specific table
|
||||
func (ac *AuditConfig) GetTableConfig(schemaName, tableName string) *TableAuditConfig {
|
||||
key := fmt.Sprintf("%s.%s", schemaName, tableName)
|
||||
return ac.EnabledTables[key]
|
||||
}
|
||||
Reference in New Issue
Block a user