Documentation
¶
Index ¶
- Variables
- func AllDrivers() []string
- func AllRules() []*model.Rule
- func InitPlugins(pluginDir string) error
- func Register(name string, h handler, rs []*model.Rule)
- func ServePlugin(driver Driver, base BaseDriver, initDriver func(cfg *Config))
- type AuditResult
- type BaseDriver
- type Config
- type Driver
- type ErrDriverNotSupported
- type Node
Constants ¶
This section is empty.
Variables ¶
var ErrNodesCountExceedOne = errors.New("after parse, nodes count exceed one")
Functions ¶
func AllDrivers ¶
func AllDrivers() []string
func InitPlugins ¶
InitPlugins init plugins at plugins directory. It should be called on host process.
func Register ¶
Register like sql.Register.
Register makes a database driver available by the provided driver name. Driver's initialize handler and audit rules register by Register.
func ServePlugin ¶
func ServePlugin(driver Driver, base BaseDriver, initDriver func(cfg *Config))
ServePlugin start plugin process service. It should be called on plugin process. initDriver is a closure which should hold the pointer to driver.
Types ¶
type AuditResult ¶
type AuditResult struct {
// contains filtered or unexported fields
}
func NewInspectResults ¶
func NewInspectResults() *AuditResult
func (*AuditResult) Add ¶
func (rs *AuditResult) Add(level, message string, args ...interface{})
func (*AuditResult) Level ¶
func (rs *AuditResult) Level() string
Level find highest Level in result
func (*AuditResult) Message ¶
func (rs *AuditResult) Message() string
type BaseDriver ¶
type BaseDriver interface {
// Name returns plugin name.
Name() string
// Rules returns all rules that plugin supported.
Rules() []*model.Rule
}
BaseDriver is the interface that all SQLe plugins must support.
type Driver ¶
type Driver interface {
Close(ctx context.Context)
Ping(ctx context.Context) error
Exec(ctx context.Context, query string) (driver.Result, error)
Tx(ctx context.Context, queries ...string) ([]driver.Result, error)
// Schemas export all supported schemas.
//
// For example, performance_schema/performance_schema... which in MySQL is not allowed for auditing.
Schemas(ctx context.Context) ([]string, error)
// Parse parse sqlText to Node array.
//
// sqlText may be single SQL or batch SQLs.
Parse(ctx context.Context, sqlText string) ([]Node, error)
// Audit sql with rules. sql is single SQL text.
//
// Multi Audit call may be in one context.
// For example:
// driver, _ := NewDriver(..., ..., ...)
// driver.Audit(..., "CREATE TABLE t1(id int)")
// driver.Audit(..., "SELECT * FROM t1 WHERE id = 1")
// ...
// driver should keep SQL context during it's lifecycle.
Audit(ctx context.Context, sql string) (*AuditResult, error)
// GenRollbackSQL generate sql's rollback SQL.
GenRollbackSQL(ctx context.Context, sql string) (string, string, error)
}
Driver is a interface that must be implemented by a database.
It's implementation maybe on the same process or over gRPC(by go-plugin).
Driver is responsible for two primary things: 1. privode handle to communicate with database 2. audit SQL with rules
type ErrDriverNotSupported ¶
type ErrDriverNotSupported struct {
DriverTyp string
}
func (*ErrDriverNotSupported) Error ¶
func (e *ErrDriverNotSupported) Error() string