Documentation ¶
Index ¶
- Variables
- func Register(name string, options ...Option) error
- func RegisterFactory(name string, factory func() ([]Option, error)) error
- func Reset()
- func Setup() error
- type AccessCheckFunc
- type BootstrapContext
- type ConnEventInfo
- type ConnEventTp
- type Extensions
- type FunctionContext
- type FunctionDef
- type Manifest
- type Option
- func WithBootstrap(fn func(BootstrapContext) error) Option
- func WithBootstrapSQL(sqlList ...string) Option
- func WithClose(fn func()) Option
- func WithCustomAccessCheck(fn AccessCheckFunc) Option
- func WithCustomDynPrivs(privs []string) Option
- func WithCustomFunctions(funcs []*FunctionDef) Option
- func WithCustomSysVariables(vars []*variable.SysVar) Option
- func WithSessionHandlerFactory(factory func() *SessionHandler) Option
- type SessionExtensions
- type SessionHandler
- type SessionPool
- type StmtEventInfo
- type StmtEventTp
Constants ¶
This section is empty.
Variables ¶
var RegisterDynamicPrivilege func(string) error
RegisterDynamicPrivilege is used to resolve dependency cycle
var RegisterExtensionFunc func(*FunctionDef) error
RegisterExtensionFunc is to avoid dependency cycle
var RemoveDynamicPrivilege func(string) bool
RemoveDynamicPrivilege is used to resolve dependency cycle
var RemoveExtensionFunc func(string)
RemoveExtensionFunc is to avoid dependency cycle
Functions ¶
func RegisterFactory ¶
RegisterFactory registers a new extension with a factory
Types ¶
type AccessCheckFunc ¶
type AccessCheckFunc func(db, tbl, column string, priv mysql.PrivilegeType, sem bool) []string
AccessCheckFunc is a function that returns a dynamic privilege list for db/tbl/column access
type BootstrapContext ¶
type BootstrapContext interface { context.Context // ExecuteSQL is used to execute a sql ExecuteSQL(ctx context.Context, sql string) ([]chunk.Row, error) // EtcdClient returns the etcd client EtcdClient() *clientv3.Client // SessionPool returns the session pool of domain SessionPool() SessionPool }
BootstrapContext is the context used by extension in bootstrap
type ConnEventInfo ¶
type ConnEventInfo struct { *variable.ConnectionInfo ActiveRoles []*auth.RoleIdentity Error error }
ConnEventInfo is the connection info for the event
type ConnEventTp ¶
type ConnEventTp uint8
ConnEventTp is the type of the connection event
const ( // ConnConnected means connection connected, but not handshake yet ConnConnected ConnEventTp = iota // ConnHandshakeAccepted means connection is accepted after handshake ConnHandshakeAccepted // ConnHandshakeRejected means connections is rejected after handshake ConnHandshakeRejected // ConnReset means the connection is reset ConnReset // ConnDisconnected means the connection is disconnected ConnDisconnected )
type Extensions ¶
type Extensions struct {
// contains filtered or unexported fields
}
Extensions contains all extensions that have already setup
func GetExtensions ¶
func GetExtensions() (*Extensions, error)
GetExtensions returns all extensions after setup
func (*Extensions) Bootstrap ¶
func (es *Extensions) Bootstrap(ctx BootstrapContext) error
Bootstrap bootstraps all extensions
func (*Extensions) GetAccessCheckFuncs ¶
func (es *Extensions) GetAccessCheckFuncs() (funcs []AccessCheckFunc)
GetAccessCheckFuncs returns spec functions of the custom access check
func (*Extensions) Manifests ¶
func (es *Extensions) Manifests() []*Manifest
Manifests returns a extension manifests
func (*Extensions) NewSessionExtensions ¶
func (es *Extensions) NewSessionExtensions() *SessionExtensions
NewSessionExtensions creates a new ConnExtensions object
type FunctionContext ¶
type FunctionContext interface { context.Context User() *auth.UserIdentity ActiveRoles() []*auth.RoleIdentity CurrentDB() string ConnectionInfo() *variable.ConnectionInfo EvalArgs(row chunk.Row) ([]types.Datum, error) }
FunctionContext is an interface to provide context to the custom function
type FunctionDef ¶
type FunctionDef struct { // Name is the function's name Name string // EvalTp is the type of the return value EvalTp types.EvalType // ArgTps is the argument types ArgTps []types.EvalType // OptionalArgsLen is the length of the optional args OptionalArgsLen int // EvalStringFunc is the eval function when `EvalTp` is `types.ETString` EvalStringFunc func(ctx FunctionContext, row chunk.Row) (string, bool, error) // EvalIntFunc is the eval function when `EvalTp` is `types.ETInt` EvalIntFunc func(ctx FunctionContext, row chunk.Row) (int64, bool, error) // RequireDynamicPrivileges is a function to return a list of dynamic privileges to check. RequireDynamicPrivileges func(sem bool) []string }
FunctionDef is the definition for the custom function
func (*FunctionDef) Validate ¶
func (def *FunctionDef) Validate() error
Validate validates the function definition
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
Manifest is an extension's manifest
type Option ¶
type Option func(m *Manifest)
Option represents an option to initialize an extension
func WithBootstrap ¶
func WithBootstrap(fn func(BootstrapContext) error) Option
WithBootstrap specifies the bootstrap func of an extension
func WithBootstrapSQL ¶
WithBootstrapSQL the bootstrap SQL list
func WithClose ¶
func WithClose(fn func()) Option
WithClose specifies the close function of an extension. It will be invoked when `extension.Reset` is called
func WithCustomAccessCheck ¶
func WithCustomAccessCheck(fn AccessCheckFunc) Option
WithCustomAccessCheck specifies the custom db/tbl/column dynamic privilege check
func WithCustomDynPrivs ¶
WithCustomDynPrivs specifies dynamic privileges of an extension
func WithCustomFunctions ¶
func WithCustomFunctions(funcs []*FunctionDef) Option
WithCustomFunctions specifies custom functions
func WithCustomSysVariables ¶
WithCustomSysVariables specifies custom variables of an extension
func WithSessionHandlerFactory ¶
func WithSessionHandlerFactory(factory func() *SessionHandler) Option
WithSessionHandlerFactory specifies a factory function to handle session
type SessionExtensions ¶
type SessionExtensions struct {
// contains filtered or unexported fields
}
SessionExtensions is the extensions
func (*SessionExtensions) HasStmtEventListeners ¶
func (es *SessionExtensions) HasStmtEventListeners() bool
HasStmtEventListeners returns a bool that indicates if any stmt event listener exists
func (*SessionExtensions) OnConnectionEvent ¶
func (es *SessionExtensions) OnConnectionEvent(tp ConnEventTp, event *ConnEventInfo)
OnConnectionEvent will be called when a connection event happens
func (*SessionExtensions) OnStmtEvent ¶
func (es *SessionExtensions) OnStmtEvent(tp StmtEventTp, event StmtEventInfo)
OnStmtEvent will be called when a stmt event happens
type SessionHandler ¶
type SessionHandler struct { OnConnectionEvent func(ConnEventTp, *ConnEventInfo) OnStmtEvent func(StmtEventTp, StmtEventInfo) }
SessionHandler is used to listen session events
type SessionPool ¶
SessionPool is the pool for session
type StmtEventInfo ¶
type StmtEventInfo interface { // User returns the user of the session User() *auth.UserIdentity // ActiveRoles returns the active roles of the user ActiveRoles() []*auth.RoleIdentity // CurrentDB returns the current database CurrentDB() string // ConnectionInfo returns the connection info of the current session ConnectionInfo() *variable.ConnectionInfo // StmtNode returns the parsed ast of the statement // When parse error, this method will return a nil value StmtNode() ast.StmtNode // ExecuteStmtNode will return the `ast.ExecuteStmt` node when the current statement is EXECUTE, // otherwise a nil value will be returned ExecuteStmtNode() *ast.ExecuteStmt // ExecutePreparedStmt will return the prepared stmt node for the EXECUTE statement. // If the current statement is not EXECUTE or prepared statement is not found, a nil value will be returned ExecutePreparedStmt() ast.StmtNode // PreparedParams will return the params for the EXECUTE statement PreparedParams() []types.Datum // OriginalText will return the text of the statement. // Notice that for the EXECUTE statement, the prepared statement text will be used as the return value OriginalText() string // SQLDigest will return the normalized and redact text of the `OriginalText()` SQLDigest() (normalized string, digest *parser.Digest) // AffectedRows will return the affected rows of the current statement AffectedRows() uint64 // RelatedTables will return the related tables of the current statement RelatedTables() []stmtctx.TableEntry // GetError will return the error when the current statement is failed GetError() error }
StmtEventInfo is the information of stmt event
type StmtEventTp ¶
type StmtEventTp uint8
StmtEventTp is the type of the statement event
const ( // StmtError means the stmt is failed StmtError StmtEventTp = iota // StmtSuccess means the stmt is successfully executed StmtSuccess )