mysql

package
v2.1.0-alpha2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

MySQL Package Documentation

The mysqlparser package encompasses the parser and mapping logic required to read MySql binary messages and capture and test the outputs. Utilized by the hooks package, it assists in redirecting outgoing calls for the purpose of recording or testing the outputs.

SSL Support

Please note that SSL is currently not supported in the MySQL package. To use the package without SSL, you can include the following parameters in your database URL like the following example:

jdbc:mysql://localhost:3306/db_name?useSSL=false&allowPublicKeyRetrieval=true

The following MySQL packet types are handled in the parser:

COM_PING: A ping command sent to the server to check if it's alive and responsive.

COM_STMT_EXECUTE: Executes a prepared statement that was prepared using the COM_STMT_PREPARE command.

COM_STMT_FETCH: Fetches rows from a statement which produced a result set. Used with cursors in server-side prepared statements.

COM_STMT_PREPARE: Prepares a SQL statement for execution.

COM_STMT_CLOSE: Closes a prepared statement, freeing up server resources associated with it.

COM_CHANGE_USER: Changes the user of the current connection and resets the connection state.

MySQLOK: A packet indicating a successful operation. It is usually received after commands like INSERT, UPDATE, DELETE, etc.

MySQLErr: An error packet sent from the server to the client, indicating an error occurred with the last command sent.

RESULT_SET_PACKET: Contains the actual result set data returned by a query. It's a series of packets containing rows and columns of data.

MySQLHandshakeV10: The initial handshake packet sent from the server to the client when a connection is established, containing authentication and connection details.

HANDSHAKE_RESPONSE: The response packet sent by the client in reply to MySQLHandshakeV10, containing client authentication data.

MySQLQuery: Contains a SQL query that is to be executed on the server.

AUTH_SWITCH_REQUEST: Sent by the server to request an authentication method switch during the connection process.

AUTH_SWITCH_RESPONSE: Sent by the client to respond to the AUTH_SWITCH_REQUEST, containing authentication data.

MySQLEOF: An EOF (End Of File) packet that marks the end of a result set or the end of the fields list.

AUTH_MORE_DATA: Sent by the server if it needs more data for authentication (used in plugins).

COM_STMT_SEND_LONG_DATA: Sends data for a column in a row to be inserted/updated in a table using a prepared statement.

COM_STMT_RESET: Resets the data of a prepared statement which was accumulated with COM_STMT_SEND_LONG_DATA commands.

COM_QUIT: Sent by the client to close the connection to the server gracefully.

Documentation

Overview

Package mysql provides integration with MySQL outgoing.

Index

Constants

View Source
const (
	CLIENT_PLUGIN_AUTH                = 0x00080000
	CLIENT_CONNECT_WITH_DB            = 0x00000008
	CLIENT_CONNECT_ATTRS              = 0x00100000
	CLIENT_ZSTD_COMPRESSION_ALGORITHM = 0x00010000
)

constants for capability flags

Variables

This section is empty.

Functions

func NewMySQL

func NewMySQL(logger *zap.Logger) integrations.Integrations

func ReadLengthEncodedIntegers

func ReadLengthEncodedIntegers(data []byte, offset int) (uint64, int)

func Uint24

func Uint24(data []byte) uint32

Types

type AuthSwitchRequestPacket

type AuthSwitchRequestPacket struct {
	StatusTag      byte   `json:"status_tag,omitempty" yaml:"status_tag,omitempty"`
	PluginName     string `json:"plugin_name,omitempty" yaml:"plugin_name,omitempty"`
	PluginAuthData string `json:"plugin_authdata,omitempty" yaml:"plugin_authdata,omitempty"`
}

type AuthSwitchResponsePacket

type AuthSwitchResponsePacket struct {
	AuthResponseData string `json:"auth_response_data,omitempty" yaml:"auth_response_data,omitempty"`
}

type BoundParameter

type BoundParameter struct {
	Type     byte   `json:"type,omitempty" yaml:"type,omitempty,flow"`
	Unsigned byte   `json:"unsigned,omitempty" yaml:"unsigned,omitempty,flow"`
	Value    []byte `json:"value,omitempty" yaml:"value,omitempty,flow"`
}

type COM_STMT_RESET

type COM_STMT_RESET struct {
	StatementID uint32 `json:"statement_id,omitempty" yaml:"statement_id,omitempty,flow"`
}

type COM_STMT_SEND_LONG_DATA

type COM_STMT_SEND_LONG_DATA struct {
	StatementID uint32 `json:"statement_id,omitempty" yaml:"statement_id,omitempty,flow"`
	ParameterID uint16 `json:"parameter_id,omitempty" yaml:"parameter_id,omitempty,flow"`
	Data        string `json:"data,omitempty" yaml:"data,omitempty,flow"`
}

type CapabilityFlags

type CapabilityFlags uint32

type ColumnDefinition

type ColumnDefinition struct {
	PacketHeader PacketHeader `yaml:"packet_header"`
	Catalog      string       `yaml:"catalog"`
	Schema       string       `yaml:"schema"`
	Table        string       `yaml:"table"`
	OrgTable     string       `yaml:"org_table"`
	Name         string       `yaml:"name"`
	OrgName      string       `yaml:"org_name"`
	NextLength   uint64       `yaml:"next_length"`
	CharacterSet uint16       `yaml:"character_set"`
	ColumnLength uint32       `yaml:"column_length"`
	ColumnType   byte         `yaml:"column_type"`
	Flags        uint16       `yaml:"flags"`
	Decimals     byte         `yaml:"decimals"`
	DefaultValue string       `yaml:"string"`
}

type ComChangeUserPacket

type ComChangeUserPacket struct {
	User         string `json:"user,omitempty" yaml:"user,omitempty,flow"`
	Auth         string `json:"auth,omitempty" yaml:"auth,omitempty,flow"`
	Db           string `json:"db,omitempty" yaml:"db,omitempty,flow"`
	CharacterSet uint8  `json:"character_set,omitempty" yaml:"character_set,omitempty,flow"`
	AuthPlugin   string `json:"auth_plugin,omitempty" yaml:"auth_plugin,omitempty,flow"`
}

type ComInitDbPacket

type ComInitDbPacket struct {
	Status byte   `json:"status,omitempty" yaml:"status,omitempty"`
	DbName string `json:"db_name,omitempty" yaml:"db_name,omitempty"`
}

type ComPingPacket

type ComPingPacket struct {
}

type ComStmtCloseAndPrepare

type ComStmtCloseAndPrepare struct {
	StmtClose   ComStmtClosePacket    `json:"stmt_close,omitempty" yaml:"stmt_close,omitempty"`
	StmtPrepare ComStmtPreparePacket1 `json:"stmt_prepare,omitempty" yaml:"stmt_prepare,omitempty"`
}

type ComStmtClosePacket

type ComStmtClosePacket struct {
	Status      byte   `json:"status,omitempty" yaml:"status,omitempty"`
	StatementID uint32 `json:"statement_id,omitempty" yaml:"statement_id,omitempty"`
}

type ComStmtExecute

type ComStmtExecute struct {
	StatementID    uint32           `json:"statement_id,omitempty" yaml:"statement_id,omitempty,flow"`
	Flags          byte             `json:"flags,omitempty" yaml:"flags,omitempty,flow"`
	IterationCount uint32           `json:"iteration_count,omitempty" yaml:"iteration_count,omitempty,flow"`
	NullBitmap     string           `json:"null_bitmap,omitempty" yaml:"null_bitmap,omitempty,flow"`
	ParamCount     uint16           `json:"param_count,omitempty" yaml:"param_count,omitempty,flow"`
	Parameters     []BoundParameter `json:"parameters,omitempty" yaml:"parameters,omitempty,flow"`
}

type ComStmtFetchPacket

type ComStmtFetchPacket struct {
	StatementID uint32 `json:"statement_id,omitempty" yaml:"statement_id,omitempty"`
	RowCount    uint32 `json:"row_count,omitempty" yaml:"row_count,omitempty"`
	Info        string `json:"info,omitempty" yaml:"info,omitempty"`
}

type ComStmtPreparePacket

type ComStmtPreparePacket struct {
	Query string `json:"query,omitempty" yaml:"query,omitempty,flow"`
}

type ComStmtPreparePacket1

type ComStmtPreparePacket1 struct {
	Header []byte `json:"header,omitempty" yaml:"header,omitempty"`
	Query  string `json:"query,omitempty" yaml:"query,omitempty"`
}

type CustomPacket

type CustomPacket struct {
	Header  CustomPacketHeader `yaml:"header"`
	Payload []byte             `yaml:"payload"`
}

func (*CustomPacket) Encode

func (p *CustomPacket) Encode() ([]byte, error)

type CustomPacketHeader

type CustomPacketHeader struct {
	PayloadLength uint32 `yaml:"payload_length"` // MySQL packet payload length
	SequenceID    uint8  `yaml:"sequence_id"`    // MySQL packet sequence ID
}

func DecodeMySQLPacket

func DecodeMySQLPacket(logger *zap.Logger, packet CustomPacket) (string, CustomPacketHeader, interface{}, error)

type EOFPacket

type EOFPacket struct {
	Header      byte   `json:"header,omitempty" yaml:"header,omitempty,flow"`
	Warnings    uint16 `json:"warnings,omitempty" yaml:"warnings,omitempty,flow"`
	StatusFlags uint16 `json:"status_flags,omitempty" yaml:"status_flags,omitempty,flow"`
}

type ERRPacket

type ERRPacket struct {
	Header         byte   `json:"header,omitempty" yaml:"header,omitempty,flow"`
	ErrorCode      uint16 `json:"error_code,omitempty" yaml:"error_code,omitempty,flow"`
	SQLStateMarker string `json:"sql_state_marker,omitempty" yaml:"sql_state_marker,omitempty,flow"`
	SQLState       string `json:"sql_state,omitempty" yaml:"sql_state,omitempty,flow"`
	ErrorMessage   string `json:"error_message,omitempty" yaml:"error_message,omitempty,flow"`
}

type HandshakeResponse

type HandshakeResponse struct {
	CapabilityFlags      uint32            `json:"capability_flags,omitempty" yaml:"capability_flags,omitempty,flow"`
	MaxPacketSize        uint32            `json:"max_packet_size,omitempty" yaml:"max_packet_size,omitempty,flow"`
	CharacterSet         uint8             `json:"character_set,omitempty" yaml:"character_set,omitempty,flow"`
	Reserved             int               `json:"reserved,omitempty" yaml:"reserved,omitempty,flow"`
	Username             string            `json:"username,omitempty" yaml:"username,omitempty,flow"`
	AuthData             string            `json:"auth_data,omitempty" yaml:"auth_data,omitempty,flow"`
	Database             string            `json:"database,omitempty" yaml:"database,omitempty,flow"`
	AuthPluginName       string            `json:"auth_plugin_name,omitempty" yaml:"auth_plugin_name,omitempty,flow"`
	ConnectAttributes    map[string]string `json:"connect_attributes,omitempty" yaml:"connect_attributes,omitempty,flow"`
	ZstdCompressionLevel byte              `json:"zstdcompressionlevel,omitempty" yaml:"zstdcompressionlevel,omitempty,flow"`
}

type HandshakeResponseOk

type HandshakeResponseOk struct {
	PacketIndicator string        `json:"packet_indicator,omitempty" yaml:"packet_indicator,omitempty,flow"`
	PluginDetails   PluginDetails `json:"plugin_details,omitempty" yaml:"plugin_details,omitempty,flow"`
	RemainingBytes  string        `json:"remaining_bytes,omitempty" yaml:"remaining_bytes,omitempty,flow"`
}

type HandshakeV10Packet

type HandshakeV10Packet struct {
	ProtocolVersion uint8  `json:"protocol_version,omitempty" yaml:"protocol_version,omitempty,flow"`
	ServerVersion   string `json:"server_version,omitempty" yaml:"server_version,omitempty,flow"`
	ConnectionID    uint32 `json:"connection_id,omitempty" yaml:"connection_id,omitempty,flow"`
	AuthPluginData  string `json:"auth_plugin_data,omitempty" yaml:"auth_plugin_data,omitempty,flow"`
	CapabilityFlags uint32 `json:"capability_flags,omitempty" yaml:"capability_flags,omitempty,flow"`
	CharacterSet    uint8  `json:"character_set,omitempty" yaml:"character_set,omitempty,flow"`
	StatusFlags     uint16 `json:"status_flags,omitempty" yaml:"status_flags,omitempty,flow"`
	AuthPluginName  string `json:"auth_plugin_name,omitempty" yaml:"auth_plugin_name,omitempty,flow"`
}

func (*HandshakeV10Packet) GetAuthMethod

func (packet *HandshakeV10Packet) GetAuthMethod() string

func (*HandshakeV10Packet) ShouldUseSSL

func (packet *HandshakeV10Packet) ShouldUseSSL() bool

type MySQL

type MySQL struct {
	// contains filtered or unexported fields
}

func (*MySQL) MatchType

func (m *MySQL) MatchType(_ context.Context, _ []byte) bool

func (*MySQL) MockOutgoing

func (m *MySQL) MockOutgoing(ctx context.Context, src net.Conn, dstCfg *integrations.ConditionalDstCfg, mockDb integrations.MockMemDb, opts models.OutgoingOptions) error

func (*MySQL) RecordOutgoing

func (m *MySQL) RecordOutgoing(ctx context.Context, src net.Conn, dst net.Conn, mocks chan<- *models.Mock, opts models.OutgoingOptions) error

type NextAuthPacket

type NextAuthPacket struct {
	PluginData byte `json:"plugin_data,omitempty" yaml:"plugin_data,omitempty"`
}

type OKPacket

type OKPacket struct {
	AffectedRows uint64 `json:"affected_rows,omitempty" yaml:"affected_rows,omitempty,flow"`
	LastInsertID uint64 `json:"last_insert_id,omitempty" yaml:"last_insert_id,omitempty,flow"`
	StatusFlags  uint16 `json:"status_flags,omitempty" yaml:"status_flags,omitempty,flow"`
	Warnings     uint16 `json:"warnings,omitempty" yaml:"warnings,omitempty,flow"`
	Info         string `json:"info,omitempty" yaml:"info,omitempty,flow"`
}

type PacketHeader

type PacketHeader struct {
	PacketLength     uint8 `yaml:"packet_length"`
	PacketSequenceID uint8 `yaml:"packet_sequence_id"`
}

type PacketType2

type PacketType2 struct {
	Field1 byte `json:"field1,omitempty" yaml:"field1,omitempty,flow"`
	Field2 byte `json:"field2,omitempty" yaml:"field2,omitempty,flow"`
	Field3 byte `json:"field3,omitempty" yaml:"field3,omitempty,flow"`
}

type PasswordData

type PasswordData struct {
	PayloadLength uint32 `json:"payload_length,omitempty" yaml:"payload_length,omitempty,flow"`
	SequenceID    byte   `json:"sequence_id,omitempty" yaml:"sequence_id,omitempty,flow"`
	Payload       []byte `json:"payload,omitempty" yaml:"payload,omitempty,flow"`
}

type PluginDetails

type PluginDetails struct {
	Type    string `yaml:"type"`
	Message string `yaml:"message"`
}

type QueryPacket

type QueryPacket struct {
	Command byte   `json:"command,omitempty" yaml:"command,omitempty,flow"`
	Query   string `json:"query,omitempty" yaml:"query,omitempty,flow"`
}

type ResultSet

type ResultSet struct {
	Columns             []*ColumnDefinition `json:"columns,omitempty" yaml:"columns,omitempty,flow"`
	Rows                []*Row              `json:"rows,omitempty" yaml:"rows,omitempty,flow"`
	EOFPresent          bool                `json:"eofPresent,omitempty" yaml:"eofPresent,omitempty,flow"`
	PaddingPresent      bool                `json:"paddingPresent,omitempty" yaml:"paddingPresent,omitempty,flow"`
	EOFPresentFinal     bool                `json:"eofPresentFinal,omitempty" yaml:"eofPresentFinal,omitempty,flow"`
	PaddingPresentFinal bool                `json:"paddingPresentFinal,omitempty" yaml:"paddingPresentFinal,omitempty,flow"`
	OptionalPadding     bool                `json:"optionalPadding,omitempty" yaml:"optionalPadding,omitempty,flow"`
	OptionalEOFBytes    string              `json:"optionalEOFBytes,omitempty" yaml:"optionalEOFBytes,omitempty,flow"`
	EOFAfterColumns     string              `json:"eofAfterColumns,omitempty" yaml:"eofAfterColumns,omitempty,flow"`
}

type Row

type Row struct {
	Header  RowHeader             `json:"header,omitempty" yaml:"header,omitempty,flow"`
	Columns []RowColumnDefinition `json:"columns,omitempty" yaml:"row_column_definition,omitempty,flow"`
}

type RowColumnDefinition

type RowColumnDefinition struct {
	Type  models.FieldType `json:"type,omitempty" yaml:"type,omitempty,flow"`
	Name  string           `json:"name,omitempty" yaml:"name,omitempty,flow"`
	Value interface{}      `json:"value,omitempty" yaml:"value,omitempty,flow"`
}

type RowDataPacket

type RowDataPacket struct {
	Data []byte `yaml:"data"`
}

type RowHeader

type RowHeader struct {
	PacketLength int   `json:"packet_length,omitempty" yaml:"packet_length,omitempty,flow"`
	SequenceID   uint8 `json:"sequence_id,omitempty" yaml:"sequence_id,omitempty,flow"`
}

type StmtPrepareOk

type StmtPrepareOk struct {
	Status       byte               `json:"status,omitempty" yaml:"status,omitempty,flow"`
	StatementID  uint32             `json:"statement_id,omitempty" yaml:"statement_id,omitempty,flow"`
	NumColumns   uint16             `json:"num_columns,omitempty" yaml:"num_columns,omitempty,flow"`
	NumParams    uint16             `json:"num_params,omitempty" yaml:"num_params,omitempty,flow"`
	WarningCount uint16             `json:"warning_count,omitempty" yaml:"warning_count,omitempty,flow"`
	ColumnDefs   []ColumnDefinition `json:"column_definitions,omitempty" yaml:"column_definitions,omitempty,flow"`
	ParamDefs    []ColumnDefinition `json:"param_definitions,omitempty" yaml:"param_definitions,omitempty,flow"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL