sns

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package sns is doze-aws's ground-up, pure-Go SNS-compatible service: no LocalStack, no JVM. It speaks the SNS Query/XML protocol, persists topics and subscriptions to a bbolt store, supports message-attribute filter policies, raw message delivery, and topic tags, and fans published messages out to SQS queues (via the peers directory) and to http(s) webhooks with the subscription-confirmation handshake.

See docs/api-support/sns.md for the operation-by-operation support table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchPolicy

func MatchPolicy(policyJSON string, attrs map[string]string) bool

MatchPolicy reports whether a message carrying the given string attributes would satisfy a subscription's filter policy. Exported so the admin/CLI can show per-subscription routing without re-implementing the matcher. An empty policy matches everything.

Types

type Attr

type Attr = awsquery.MessageAttr

Attr is an SNS message attribute (String/Number use StringValue; Binary uses BinaryValue) — the Query codec's decoded shape, used directly.

type Options

type Options struct {
	// DataDir holds the bbolt store (sns.bolt). Required.
	DataDir string
	// Peers resolves sibling services; SQS-protocol subscriptions deliver
	// through it. Nil disables SQS delivery (with a log line per attempt).
	Peers peers.Directory
	// Logf receives log lines; nil discards.
	Logf func(format string, args ...any)
	// Clock overrides time.Now in tests.
	Clock func() time.Time
}

Options configures the service.

type Server

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

Server is the SNS service: an http.Handler speaking the Query/XML protocol, and an io.Closer that closes the store.

func New

func New(opts Options) (*Server, error)

New opens the bbolt store under DataDir.

func (*Server) Close

func (s *Server) Close() error

Close closes the bbolt DB.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Store

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

Store is the bbolt-backed SNS state.

func (*Store) ConfirmByToken

func (s *Store) ConfirmByToken(token string) (*Subscription, error)

ConfirmByToken confirms a pending http(s) subscription given its token.

func (*Store) CreateTopic

func (s *Store) CreateTopic(name string, attrs, tags map[string]string) (*Topic, error)

func (*Store) DeleteTopic

func (s *Store) DeleteTopic(arn string) error

func (*Store) GetSubscription

func (s *Store) GetSubscription(arn string) (*Subscription, error)

GetSubscription returns one subscription by ARN.

func (*Store) GetTopic

func (s *Store) GetTopic(arn string) (*Topic, error)

GetTopic returns a topic by ARN.

func (*Store) ListSubscriptions

func (s *Store) ListSubscriptions(topicFilter string) ([]Subscription, error)

func (*Store) ListTopics

func (s *Store) ListTopics() ([]Topic, error)

func (*Store) SetSubscriptionAttribute

func (s *Store) SetSubscriptionAttribute(arn, name, value string) error

func (*Store) Subscribe

func (s *Store) Subscribe(topicARN, protocol, endpoint string, attrs map[string]string) (*Subscription, error)

Subscribe creates a subscription. SQS subscriptions are auto-confirmed; http(s) ones start pending with a confirmation token until ConfirmSubscription.

func (*Store) TopicExists

func (s *Store) TopicExists(arn string) bool

TopicExists reports whether a topic ARN is known.

func (*Store) Unsubscribe

func (s *Store) Unsubscribe(arn string) error

func (*Store) UpdateTopic

func (s *Store) UpdateTopic(arn string, fn func(*Topic)) error

UpdateTopic applies fn to a topic and persists the result.

type Subscription

type Subscription struct {
	ARN          string `json:"arn"`
	TopicARN     string `json:"topic_arn"`
	Protocol     string `json:"protocol"` // sqs | http | https
	Endpoint     string `json:"endpoint"` // queue ARN/URL, or webhook URL
	RawDelivery  bool   `json:"raw_delivery"`
	FilterPolicy string `json:"filter_policy,omitempty"` // JSON
	Confirmed    bool   `json:"confirmed"`
	Token        string `json:"token,omitempty"` // pending-confirmation token
	// Extra round-trips subscription attributes with no local behavior
	// (FilterPolicyScope, RedrivePolicy, DeliveryPolicy, ...).
	Extra map[string]string `json:"extra,omitempty"`
}

Subscription is one subscription to a topic.

type Topic

type Topic struct {
	ARN  string `json:"arn"`
	Name string `json:"name"`
	// Attrs round-trips SetTopicAttributes/CreateTopic attributes
	// (DisplayName, Policy, ...). Locally most have no behavior; they are
	// stored and returned faithfully.
	Attrs map[string]string `json:"attrs,omitempty"`
	Tags  map[string]string `json:"tags,omitempty"`
	// DataProtectionPolicy round-trips Put/GetDataProtectionPolicy.
	DataProtectionPolicy string `json:"data_protection_policy,omitempty"`
}

Topic is a declared/created SNS topic.

Jump to

Keyboard shortcuts

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