Help us shape the future of Go! Take the 2026 Go Developer Survey

ops

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package ops is lockmq's operation catalogue: an allowlist of what a client may ask, each operation with its tier, protocol and whether it needs the human's approval, and the field allowlists that filter what the broker answers before it reaches a client.

Index

Constants

View Source
const (
	CodeVHostNotServed        refusal.Code = "E_VHOST_NOT_SERVED"
	CodeProtocolNotConfigured refusal.Code = "E_PROTOCOL_NOT_CONFIGURED"
	CodeBadArgs               refusal.Code = "E_BAD_ARGS"
	CodeWrongQueueType        refusal.Code = "E_WRONG_QUEUE_TYPE"
	CodeTier                  refusal.Code = "E_TIER"
	CodeUnsafeName            refusal.Code = "E_UNSAFE_NAME"
	CodeUnmaskOff             refusal.Code = "E_UNMASK_OFF"
	// CodeStale: in hub mode, the queue's properties (or the request)
	// changed between the approval and the run; nothing was read.
	CodeStale refusal.Code = "E_STALE"
)

Refusal codes of the catalogue. Never rename one: they are part of the client protocol.

View Source
const (
	ProtoMgmt   = "management"
	ProtoStream = "stream" // stream protocol, or AMQP for reads
)

Protocols an operation needs.

View Source
const CodeDeliveryLimit refusal.Code = "E_DELIVERY_LIMIT"

CodeDeliveryLimit refuses a quorum queue peek too close to the queue's delivery limit.

View Source
const DefaultQuorumDeliveryLimit = 20

DefaultQuorumDeliveryLimit is RabbitMQ 4.x's delivery limit of a quorum queue that sets none (3.x has no default).

View Source
const MaxNameLen = 255

MaxNameLen bounds a queue, exchange or consumer name (RabbitMQ: 255 bytes).

Variables

This section is empty.

Functions

func Catalogue

func Catalogue() map[string]Op

Catalogue returns the operations of design §5.2; nothing else exists.

func CheckPeek

func CheckPeek(tier config.Tier, q QueueInfo, seen, headroom int) ([]string, *refusal.Error)

CheckPeek decides a peek of q on a profile of tier tier: a refusal, or the warnings of the approval screen. seen is Seen.Max (-1: first peek). The refusals: a tier below peek, a stream (use read) or a type that is neither classic nor quorum, and on a quorum queue a delivery limit at or under headroom, or within headroom of the highest count seen.

func EffectiveDeliveryLimit

func EffectiveDeliveryLimit(q QueueInfo) (limit int, ok bool)

EffectiveDeliveryLimit is the delivery limit of a quorum queue: the lowest of its x-delivery-limit argument, its policy's and its operator policy's delivery-limit; RabbitMQ 4.x's default 20 when none is set. A negative limit (4.x) disables it. ok is false for a queue without one.

func MaxDeliveryCount

func MaxDeliveryCount(msgs []mgmt.Message) int

MaxDeliveryCount is the highest x-delivery-count among peeked messages.

func QueueType

func QueueType(ctx context.Context, m Mgmt, vhost, name string) (map[string]any, string, error)

QueueType reads the type of a queue ("classic", "quorum", "stream").

func ResolveVHost

func ResolveVHost(p config.Profile, arg string) (string, error)

ResolveVHost returns the vhost an operation acts on: the argument when the profile serves it, else the profile's only vhost, else "/" for a profile that serves every vhost.

func SafeName added in v0.2.0

func SafeName(what, s string) error

SafeName refuses, before any I/O, a name that would be a "." or ".." segment of a management API path (mgmt.DotSegment): such a path could reach an endpoint outside the allowlist.

func StripUserinfo

func StripUserinfo(s string) string

StripUserinfo removes the user and password of every URI in s ("amqps://u:p@h:5671/v" → "amqps://h:5671/v").

Types

type Args

type Args struct {
	VHost    string `json:"vhost,omitempty"`
	Target   string `json:"target,omitempty"`
	Filter   string `json:"filter,omitempty"`
	Sort     string `json:"sort,omitempty"`
	From     string `json:"from,omitempty"`
	Consumer string `json:"consumer,omitempty"`
	Page     int    `json:"page,omitempty"`
	Count    int    `json:"count,omitempty"`
}

Args are an operation's arguments, as a client sends them.

type Deps

type Deps struct {
	Mgmt    Mgmt
	Stream  StreamInfo
	Profile config.Profile
}

Deps are the broker clients and the profile an operation runs with. Stream is nil when the profile has no stream_url.

type List

type List struct {
	Items    any `json:"items"`
	Page     int `json:"page,omitempty"`
	PageSize int `json:"page_size,omitempty"`
	Total    int `json:"total,omitempty"`
}

List is a page of a list operation.

type Mgmt

type Mgmt interface {
	Get(ctx context.Context, p mgmt.Path, q url.Values, into any) error
	GetPageQ(ctx context.Context, p mgmt.Path, page, size int, columns []string, extra url.Values, into any) (int, error)
	PeekRequeue(ctx context.Context, vhost, queue string, count, truncate int) ([]mgmt.Message, error)
}

Mgmt is what the catalogue uses of the management client.

type Op

type Op struct {
	Name string
	// Tier is the lowest profile tier that allows it.
	Tier     config.Tier
	Protocol string
	// Prompt: the human approves every run (message content).
	Prompt bool
	Run    func(ctx context.Context, d Deps, a Args) (any, error)
}

Op is one operation of the catalogue.

type QueueInfo

type QueueInfo struct {
	Name, VHost, Type string
	Arguments         map[string]any
	// PolicyDefinition is the queue's effective policy definition;
	// OperatorPolicyDefinition the definition of its operator policy.
	PolicyDefinition         map[string]any
	OperatorPolicyDefinition map[string]any
	MessagesReady            int
	MessagesUnacked          int
	Consumers                int
	// BrokerMajor is the broker's major version (3, 4).
	BrokerMajor int
}

QueueInfo is what the peek guard reads of a queue.

func QueueInfoFrom

func QueueInfoFrom(q map[string]any, version string, operator map[string]any) QueueInfo

QueueInfoFrom reads a management API queue object; version is the broker's rabbitmq_version, operator the definition of the queue's operator policy (nil if none).

type Seen

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

Seen keeps, per queue and for one console session, the highest x-delivery-count earlier peeks saw. Memory only.

func (*Seen) Max

func (s *Seen) Max(vhost, queue string) int

Max is the highest delivery count seen on the queue, -1 before its first peek.

func (*Seen) Note

func (s *Seen) Note(vhost, queue string, maxCount int)

Note records the highest delivery count of one peek.

type StreamInfo

type StreamInfo interface {
	Stats(ctx context.Context, vhost, stream string) (first, last int64, err error)
	QueryOffset(ctx context.Context, vhost, stream, consumerRef string) (int64, error)
}

StreamInfo is the stream protocol's metadata side (package stream).

Jump to

Keyboard shortcuts

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