-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin: add audit plugin extension point (#9136)
- Loading branch information
Showing
22 changed files
with
521 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# The Plugin Framework | ||
|
||
https://github.com/pingcap/tidb/blob/master/docs/design/2018-12-10-plugin-framework.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package plugin | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/parser/auth" | ||
"github.com/pingcap/tidb/sessionctx/variable" | ||
) | ||
|
||
// GeneralEvent presents TiDB generate event. | ||
type GeneralEvent byte | ||
|
||
const ( | ||
// Log presents log event. | ||
Log GeneralEvent = iota | ||
// Error presents error event. | ||
Error | ||
// Result presents result event. | ||
Result | ||
// Status presents status event. | ||
Status | ||
) | ||
|
||
// ConnectionEvent presents TiDB connection event. | ||
type ConnectionEvent byte | ||
|
||
const ( | ||
// Connected presents new connection establish event(finish auth). | ||
Connected ConnectionEvent = iota | ||
// Disconnect presents disconnect event. | ||
Disconnect | ||
// ChangeUser presents change user. | ||
ChangeUser | ||
// PreAuth presents event before start auth. | ||
PreAuth | ||
) | ||
|
||
func (c ConnectionEvent) String() string { | ||
switch c { | ||
case Connected: | ||
return "Connected" | ||
case Disconnect: | ||
return "Disconnect" | ||
case ChangeUser: | ||
return "ChangeUser" | ||
case PreAuth: | ||
return "PreAuth" | ||
} | ||
return "" | ||
} | ||
|
||
// ParseEvent presents events happen around parser. | ||
type ParseEvent byte | ||
|
||
const ( | ||
// PreParse presents event before parse. | ||
PreParse ParseEvent = 1 + iota | ||
// PostParse presents event after parse. | ||
PostParse | ||
) | ||
|
||
// AuditManifest presents a sub-manifest that every audit plugin must provide. | ||
type AuditManifest struct { | ||
Manifest | ||
// OnConnectionEvent will be called when TiDB receive or disconnect from client. | ||
// return error will ignore and close current connection. | ||
OnConnectionEvent func(ctx context.Context, identity *auth.UserIdentity, event ConnectionEvent, info *variable.ConnectionInfo) error | ||
// OnGeneralEvent will be called during TiDB execution. | ||
OnGeneralEvent func(ctx context.Context, sctx *variable.SessionVars, event GeneralEvent, cmd string) | ||
// OnGlobalVariableEvent will be called when Change GlobalVariable. | ||
OnGlobalVariableEvent func(ctx context.Context, sctx *variable.SessionVars, varName, varValue string) | ||
// OnParseEvent will be called around parse logic. | ||
OnParseEvent func(ctx context.Context, sctx *variable.SessionVars, event ParseEvent) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.