mongo

package
v2.3.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

README

Mongo Package Documentation

The mongo package encompasses the parser and mapping logic required to read MongoDB wire messages and capture or stub the outputs. Utilized by the hooks package, it assists in redirecting outgoing calls for the purpose of recording or stubbing the outputs.

Documentation

Overview

Package mongo provides functionality for working with MongoDB outgoing calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsIsMasterDoc

func IsIsMasterDoc(doc bsoncore.Document) bool

func IsIsMasterValueTruthy

func IsIsMasterValueTruthy(val bsoncore.Value) bool

func IsWrite

func IsWrite(command Command) bool

func NewMongo

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

Types

type Command

type Command string
const (
	Unknown           Command = "unknown"
	AbortTransaction  Command = "abortTransaction"
	Aggregate         Command = "aggregate"
	CommitTransaction Command = "commandTransaction"
	Count             Command = "count"
	CreateIndexes     Command = "createIndexes"
	Delete            Command = "delete"
	Distinct          Command = "distinct"
	Drop              Command = "drop"
	DropDatabase      Command = "dropDatabase"
	DropIndexes       Command = "dropIndexes"
	EndSessions       Command = "endSessions"
	Find              Command = "find"
	FindAndModify     Command = "findAndModify"
	GetMore           Command = "getMore"
	Insert            Command = "insert"
	IsMaster          Command = "isMaster"
	Ismaster          Command = "ismaster"
	ListCollections   Command = "listCollections"
	ListIndexes       Command = "listIndexes"
	ListDatabases     Command = "listDatabases"
	MapReduce         Command = "mapReduce"
	Update            Command = "tools"
)

constants for all the commands that can be proxied

func CommandAndCollection

func CommandAndCollection(msg bsoncore.Document) (Command, string)

type Message

type Message struct {
	Wm []byte
	Op Operation
}

type Mongo

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

func (*Mongo) MatchType

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

MatchType determines if the outgoing network call is Mongo by comparing the message format with that of a mongo wire message.

func (*Mongo) MockOutgoing

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

MockOutgoing reads the outgoing mongo requests of the client connection and mocks the responses from the yaml file. The database connection is keep-alive

func (*Mongo) RecordOutgoing

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

RecordOutgoing records the outgoing mongo messages of the client connection into the yaml file. The database connection is keep-alive so, this function will be called during the connection establishment.

type Operation

type Operation interface {
	fmt.Stringer
	OpCode() wiremessage.OpCode
	Encode(responseTo, requestID int32) []byte
	IsIsMaster() bool
	IsIsAdminDB() bool
	CursorID() (cursorID int64, ok bool)
	RequestID() int32
	Error() error
	Unacknowledged() bool
	CommandAndCollection() (Command, string)
	TransactionDetails() *TransactionDetails
}

func Decode

func Decode(wm []byte, logger *zap.Logger) (Operation, models.MongoHeader, interface{}, error)

Decode decodes the wire message binary into the operation and the mongo message.

see https://github.com/mongodb/mongo-go-driver/blob/v1.7.2/x/mongo/driver/operation.go#L1361-L1426

type TransactionDetails

type TransactionDetails struct {
	LsID               []byte
	TxnNumber          int64
	IsStartTransaction bool
}

Jump to

Keyboard shortcuts

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