github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/plugin/audit.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package plugin 15 16 import ( 17 "context" 18 19 "github.com/whtcorpsinc/milevadb/stochastikctx/variable" 20 ) 21 22 // GeneralEvent presents MilevaDB generate event. 23 type GeneralEvent byte 24 25 const ( 26 // Log presents log event. 27 Log GeneralEvent = iota 28 // Error presents error event. 29 Error 30 // Result presents result event. 31 Result 32 // Status presents status event. 33 Status 34 ) 35 36 // ConnectionEvent presents MilevaDB connection event. 37 type ConnectionEvent byte 38 39 const ( 40 // Connected presents new connection establish event(finish auth). 41 Connected ConnectionEvent = iota 42 // Disconnect presents disconnect event. 43 Disconnect 44 // ChangeUser presents change user. 45 ChangeUser 46 // PreAuth presents event before start auth. 47 PreAuth 48 // Reject presents event reject connection event. 49 Reject 50 ) 51 52 func (c ConnectionEvent) String() string { 53 switch c { 54 case Connected: 55 return "Connected" 56 case Disconnect: 57 return "Disconnect" 58 case ChangeUser: 59 return "ChangeUser" 60 case PreAuth: 61 return "PreAuth" 62 case Reject: 63 return "Reject" 64 } 65 return "" 66 } 67 68 // ParseEvent presents events happen around BerolinaSQL. 69 type ParseEvent byte 70 71 const ( 72 // PreParse presents event before parse. 73 PreParse ParseEvent = 1 + iota 74 // PostParse presents event after parse. 75 PostParse 76 ) 77 78 // AuditManifest presents a sub-manifest that every audit plugin must provide. 79 type AuditManifest struct { 80 Manifest 81 // OnConnectionEvent will be called when MilevaDB receive or disconnect from client. 82 // return error will ignore and close current connection. 83 OnConnectionEvent func(ctx context.Context, event ConnectionEvent, info *variable.ConnectionInfo) error 84 // OnGeneralEvent will be called during MilevaDB execution. 85 OnGeneralEvent func(ctx context.Context, sctx *variable.StochastikVars, event GeneralEvent, cmd string) 86 // OnGlobalVariableEvent will be called when Change GlobalVariable. 87 OnGlobalVariableEvent func(ctx context.Context, sctx *variable.StochastikVars, varName, varValue string) 88 // OnParseEvent will be called around parse logic. 89 OnParseEvent func(ctx context.Context, sctx *variable.StochastikVars, event ParseEvent) error 90 } 91 92 type ( 93 // RejectReasonCtxValue will be used in OnConnectionEvent to pass RejectReason to plugin. 94 RejectReasonCtxValue struct{} 95 ) 96 97 type execStartTimeCtxKeyType struct{} 98 99 // InterDircStartTimeCtxKey indicates stmt start execution time. 100 var InterDircStartTimeCtxKey = execStartTimeCtxKeyType{}