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
- func Catalogue() map[string]Op
- func CheckPeek(tier config.Tier, q QueueInfo, seen, headroom int) ([]string, *refusal.Error)
- func EffectiveDeliveryLimit(q QueueInfo) (limit int, ok bool)
- func MaxDeliveryCount(msgs []mgmt.Message) int
- func QueueType(ctx context.Context, m Mgmt, vhost, name string) (map[string]any, string, error)
- func ResolveVHost(p config.Profile, arg string) (string, error)
- func SafeName(what, s string) error
- func StripUserinfo(s string) string
- type Args
- type Deps
- type List
- type Mgmt
- type Op
- type QueueInfo
- type Seen
- type StreamInfo
Constants ¶
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.
const ( ProtoMgmt = "management" ProtoStream = "stream" // stream protocol, or AMQP for reads )
Protocols an operation needs.
const CodeDeliveryLimit refusal.Code = "E_DELIVERY_LIMIT"
CodeDeliveryLimit refuses a quorum queue peek too close to the queue's delivery limit.
const DefaultQuorumDeliveryLimit = 20
DefaultQuorumDeliveryLimit is RabbitMQ 4.x's delivery limit of a quorum queue that sets none (3.x has no default).
const MaxNameLen = 255
MaxNameLen bounds a queue, exchange or consumer name (RabbitMQ: 255 bytes).
Variables ¶
This section is empty.
Functions ¶
func CheckPeek ¶
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 ¶
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 ¶
MaxDeliveryCount is the highest x-delivery-count among peeked messages.
func ResolveVHost ¶
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
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 ¶
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.