destinations

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 36 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package destinations holds the Destinations (C-11.FR-18): Mattermost channels, Telegram channels, channels of a Bridge and Slack channels reached through a Connection, and outgoing webhooks. This package reads every type with its health and Routes and exports muster_destination_info, and deletes them (C-11.FR-14); the type capabilities add creating and editing them (C-13 to C-15, C-22, C-24). Secrets are read only as their status.

Index

Constants

View Source
const (
	ActionDeleted       = "destination.deleted"
	ResourceDestination = "destination"
	Hint                = "destination"
)

The Audit log action and resource type, and the live hint, of Destinations (C-03.FR-14).

View Source
const (
	SourceAlertGroup = "alert_group"
	SourceExample    = "example"
)

The kinds of the source of a test or a preview (TestSource).

View Source
const (
	TypeMattermost = "mattermost"
	TypeTelegram   = "telegram"
	TypeWebhook    = "webhook"
	TypeBridge     = "bridge"
	TypeSlack      = "slack"
)

The Destination types.

View Source
const (
	ActionCreated = "destination.created"
	ActionUpdated = "destination.updated"
)

The Audit log actions of saved Destinations (C-03.FR-14).

View Source
const (
	CodeRequired          = "required"
	CodeInvalidFormat     = "invalid_format"
	CodeTooLong           = "too_long"
	CodeUnknownID         = "unknown_id"
	CodeUnsupported       = "unsupported"
	CodeCheckNotSupported = "check_not_supported"
	CodeCheckFailed       = "destination_check_failed"
)

The codes of FieldError.

View Source
const ActionTested = "destination.tested"

The Audit log action of a Destination test (C-16.FR-5).

Variables

View Source
var (
	// ErrNameTaken is a name another Destination that is not deleted has.
	ErrNameTaken = errors.New("another destination has this name")
	// ErrUnknownConnection is a connection_id that names no Connection of the type: missing, deleted or of the other
	// messenger.
	ErrUnknownConnection = errors.New("no such connection of this type")
)
View Source
var ErrNoTester = errors.New("this build has no test of destinations of this type")

ErrNoTester is a test or a preview of a Destination whose type has no Tester in this build: the API answers 501.

View Source
var ErrNotFound = errors.New("no such destination")

ErrNotFound is a Destination that does not exist in the Organization or is deleted.

View Source
var ErrVersionMismatch = errors.New("the destination changed since it was read")

ErrVersionMismatch is an If-Match that names another version of the Destination.

Functions

This section is empty.

Types

type BridgeChannelCheck

type BridgeChannelCheck struct {
	Connection  string
	Destination *int64
	ChannelID   string
}

BridgeChannelCheck is the Destination check of a Bridge channel through the Connection Connection (public_id): of the saved Destination Destination (its id) when it exists, so that its limiter applies, else of the Connection alone.

type BridgeChannelChecked

type BridgeChannelChecked struct {
	ConnectionID int64
	Check        bridge.ChannelCheck
}

BridgeChannelChecked is the result of a BridgeChannelCheck: the id of the Connection and the check.

type BridgeChecker

type BridgeChecker interface {
	CheckBridgeChannel(ctx context.Context, c BridgeChannelCheck) (BridgeChannelChecked, error)
}

BridgeChecker runs the Destination check of a Bridge channel on the interactive path (C-22.FR-3), declared by its consumer next to TelegramChecker; *connections.Service implements it. A Connection that is not a Bridge Connection that is not deleted is ErrUnknownConnection; no limiter token within the budget is a *delivery.LimitedError.

type BridgeInput

type BridgeInput struct {
	Connection string
	ChannelID  string
}

BridgeInput are the fields of a Bridge Destination (C-22.FR-3): its Connection by public_id and its channel id as its messenger names it.

type ChannelCheck

type ChannelCheck struct {
	Connection  string
	Destination *int64
	TeamID      string
	ChannelID   string
}

ChannelCheck is the Destination check of a Mattermost channel through the Connection Connection (public_id): of the saved Destination Destination (its id) when it exists, so that its limiter applies, else of the Connection alone.

type ChannelChecked

type ChannelChecked struct {
	ConnectionID int64
	Check        mattermost.Check
}

ChannelChecked is the result of a ChannelCheck: the id of the Connection and the check.

type CheckFailedError

type CheckFailedError struct {
	Items []CheckItem
}

CheckFailedError is a save that its Destination check refused: nothing was saved. Items are the failing checks.

func (*CheckFailedError) Error

func (e *CheckFailedError) Error() string

type CheckItem

type CheckItem struct {
	Name          string
	OK            bool
	Message       string
	Code          string
	MissingScopes []string
	Pointer       string
}

CheckItem is one step of a Destination check with its result: when it failed, its message, in English, its code, which clients translate (DestinationCheckItem.code), with missing_scope the scopes the bot token lacks, which clients name in their own words (D396), and, on a save, the field it concerns.

type CheckResult

type CheckResult struct {
	OK     bool
	Items  []CheckItem
	Health Health
	Run    string
}

CheckResult is the result of checkDestination: whether every check passed, each check, the health after it, and the check run its requests share in the Request log (C-23.FR-5).

type Destination

type Destination struct {
	ID         int64
	PublicID   string
	Type       string
	Name       string
	Connection *string

	MattermostTeamID      *string
	MattermostChannelID   *string
	MattermostTeamName    *string
	MattermostChannelName *string

	TelegramChannelID            *string
	TelegramChannelChatID        *string
	TelegramDiscussionGroupID    *string
	TelegramChannelTitle         *string
	TelegramDiscussionGroupTitle *string

	BridgeChannelID   *string
	BridgeChannelName *string

	SlackChannelID   *string
	SlackChannelName *string

	WebhookMode    *string
	EventsConfig   json.RawMessage
	TemplateConfig json.RawMessage
	Proxy          Proxy
	SigningSecret  SigningSecret

	// SigningSecretOnce is the first Signing secret of an outgoing webhook, set only by Create, which returns it once.
	SigningSecretOnce logging.Secret

	Mentions          json.RawMessage
	LimiterLimit      int64
	LimiterPerSeconds int64
	Health            Health
	Routes            []RouteRef
	TemplateError     *TemplateError
	CreatedAt         time.Time
	Version           int64
}

Destination is a Destination of any type as read. The fields of the other types are empty: Mattermost has its team and channel, Telegram its channel and the discussion group a Destination check found, a Bridge and Slack their channel id and the channel's name their Destination check read, an outgoing webhook its mode, request templates, proxy and Signing secret. Mentions, EventsConfig and TemplateConfig are the stored JSON.

type FieldError

type FieldError struct {
	Pointer string
	Code    string
	Detail  string
	Line    int
	Column  int
}

FieldError is a field of a request that is not valid, at a JSON pointer of the request body, with a stable code of the validation-failed problem and, for a request template, the 1-based line and column of its error when known.

func (*FieldError) Error

func (e *FieldError) Error() string

type Health

type Health struct {
	State  string
	Since  *time.Time
	Reason *string
}

Health is the health of a Destination: healthy, or broken since a time with a reason.

type Healthy

type Healthy func(ctx context.Context, destinationID int64) error

Healthy ends the Broken state of the Destination destinationID after a successful Destination check started by a person (C-13.FR-10): delivery's MarkHealthy.

type Input

type Input struct {
	Type       string
	Name       string
	Mentions   mentions.Settings
	Limiter    Limiter
	Mattermost *MattermostInput
	Telegram   *TelegramInput
	Webhook    *WebhookInput
	Bridge     *BridgeInput
	Slack      *SlackInput
}

Input is what createDestination and updateDestination write: the common fields and those of its type.

type Limiter

type Limiter struct {
	Limit      int64 `json:"limit"`
	PerSeconds int64 `json:"per_seconds"`
}

Limiter is a rate limit of Limit calls per PerSeconds.

type ListFilter

type ListFilter struct {
	Type   *string
	Health *string
	Route  *string
	After  *int64
	Limit  int
}

ListFilter selects the Destinations of a page: of a type, a health and a Route (its public_id) when set, after the id After, at most Limit.

type MattermostChecker

type MattermostChecker interface {
	CheckChannel(ctx context.Context, c ChannelCheck) (ChannelChecked, error)
}

MattermostChecker runs the Destination check of a Mattermost channel on the interactive path (C-13.FR-2, FR-10), declared by its consumer; *connections.Service implements it. A Connection that is not a Mattermost one that is not deleted is ErrUnknownConnection; no limiter token within the budget is a *delivery.LimitedError.

type MattermostInput

type MattermostInput struct {
	Connection string
	TeamID     string
	ChannelID  string
}

MattermostInput are the fields of a Mattermost Destination: its Connection by public_id, its team and its channel.

type MentionValidator

type MentionValidator interface {
	Validate(ctx context.Context, destinationType string, set mentions.Settings) error
}

MentionValidator validates the Mention settings of a Destination type (C-12.FR-8), declared by its consumer; *mentions.Service implements it.

type Page

type Page struct {
	Destinations []Destination
	Next         *int64
}

Page is a page of Destinations; Next is the cursor after its last one, nil on the last page.

type Probe

type Probe func(ctx context.Context, destinationID int64) error

Probe makes the probe of the Destination destinationID due at once when it is Broken, after a person saved it: delivery's ProbeNow.

type Proxy

type Proxy struct {
	Enabled           bool       `json:"enabled"`
	Type              *string    `json:"type,omitempty"`
	Address           *string    `json:"address,omitempty"`
	Username          *string    `json:"username,omitempty"`
	PasswordSet       bool       `json:"-"`
	PasswordUpdatedAt *time.Time `json:"-"`
}

Proxy is the proxy of an outgoing webhook as stored, without its password; PasswordSet and PasswordUpdatedAt are the password's status.

type Ref

type Ref struct {
	PublicID string
	Name     string
	Type     string
	Health   Health
}

Ref names a Destination with its type and health (DestinationRef).

type Renamed

type Renamed func(ctx context.Context, tx dbgen.DBTX, publicID, name string) error

Renamed is the hook that delivery runs in the transaction tx that renamed the Destination publicID to name: every Internal alert about it takes the new name, as the same firing.

type Requester

type Requester struct {
	Actor     audit.Actor
	Transport audit.Transport
	Address   netip.Addr
}

Requester is who asks for a change and how: the actor and the Transport of the Audit log entry, and the client address.

type Retire

type Retire func(ctx context.Context, tx dbgen.DBTX, destinationID int64) error

Retire is the hook that delivery runs in the transaction tx that deleted the Destination destinationID: the final edits of its open Root messages, and the wipe of its secrets once none is pending (C-11.FR-14).

type RouteRef

type RouteRef struct {
	PublicID string
	Name     string
}

RouteRef names a Route of a Destination.

type Routes

type Routes func(ctx context.Context, tx dbgen.DBTX, destinationID int64) error

Routes is the hook that routing runs in the transaction tx that deletes the Destination destinationID, before it leaves its Routes: each of them gets a new version and its hint, and its membership lock, so that no Alert Group of it is rendered for the Destination meanwhile.

type Samples

type Samples interface {
	TestSample(ctx context.Context, publicID string) (*messages.Source, error)
	TestExample(ctx context.Context) (*messages.Source, error)
}

Samples read the Alert Group a test or a preview renders, declared by their consumer; *messages.Renderer implements them. An unknown Alert Group is messages.ErrNotFound.

type Service

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

Service reads the Destinations of an Organization and deletes them.

func New

func New(orgID int64, store Store) *Service

New returns the Service of the Organization orgID.

func (*Service) Check

func (s *Service) Check(ctx context.Context, publicID string) (CheckResult, error)

Check runs the Destination check of the Destination publicID from checkDestination (C-13.FR-10, C-14.FR-14, C-22.FR-3, C-24.FR-3) on the interactive path, limited by the Destination: each check with its result. A passing check of a Broken Destination ends its Broken state. A Bridge or Slack Destination's check keeps no channel name it reads: a save does. A type without a Destination check here is a *FieldError check_not_supported. Its requests are recorded as the kind destination_check with the Destination under one check run, which the result names (C-23.FR-2, FR-5).

func (*Service) Create

func (s *Service) Create(ctx context.Context, r Requester, in Input) (Destination, error)

Create creates a Mattermost Destination (C-13.FR-2, FR-3, C-11.FR-18) once its Destination check passed on the interactive path; the check reads the names of its team and channel, which the Destination keeps. A Telegram Destination is created the same way from its channel alone, keeping the discussion group its check found (C-14.FR-2), and a Bridge or Slack Destination from its channel id, keeping the channel's name its check read (C-22.FR-3, C-24.FR-3). An outgoing webhook in the events mode has no check: it is created with its first Signing secret (C-15.FR-1, FR-5). It is recorded as destination.created.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, r Requester, publicID string, version *int64) error

Delete deletes the Destination publicID (C-11.FR-14); a non-nil version must be its current one. In one transaction it is marked deleted — it leaves every list and reads as missing, the row stays for history — it leaves every Route, each of which gets a new version and its hint through the Routes hook, delivery gives its open Root messages their final edit through the Retire hook, which also ends the waiting events of an outgoing webhook as Not delivered, and the Audit log entry destination.deleted is written. Its secrets are wiped once the final edits are done and no call of it is in flight. A deleted or unknown Destination is ErrNotFound.

func (*Service) Get

func (s *Service) Get(ctx context.Context, publicID string) (Destination, error)

Get reads the Destination publicID; a deleted or unknown one is ErrNotFound.

func (*Service) InfoChanged

func (s *Service) InfoChanged()

InfoChanged asks RunInfo to refresh muster_destination_info: a hint said a Destination changed, maybe on another replica. It never blocks.

func (*Service) List

func (s *Service) List(ctx context.Context, f ListFilter) (Page, error)

List reads a page of the Destinations that are not deleted, in id order, with their Routes.

func (*Service) Preview

func (s *Service) Preview(ctx context.Context, publicID string, src Source) ([]delivery.PreviewItem, error)

Preview renders, without sending anything, what the Destination publicID would receive for the source src (C-16.FR-4): the Root message of a Mattermost (Markdown, with the attachment as the request's body) or a Telegram (HTML) Destination, the envelope of a Bridge Destination or the body of chat.postMessage of a Slack Destination (as JSON), or the requests of an outgoing webhook — the event body in the events mode and "create", "update", "open thread" and "reply in thread" in the template mode — with every Secret masked. It takes no limiter token and records nothing.

func (*Service) RefreshInfo

func (s *Service) RefreshInfo(ctx context.Context) error

RefreshInfo sets muster_destination_info to the Destinations that are not deleted: a series per Destination with its current name; the series of a renamed or deleted one is removed. Each Destination also gets its counter series.

func (*Service) RouteRefs

func (s *Service) RouteRefs(ctx context.Context, routeIDs []int64) (map[int64][]Ref, error)

RouteRefs are the Destinations that are not deleted of each of the Routes routeIDs, by name, with their health (C-08.FR-1).

func (*Service) RunInfo

func (s *Service) RunInfo(ctx context.Context, ticks <-chan time.Time)

RunInfo keeps muster_destination_info current until ctx ends: it refreshes it at once, after InfoChanged and at every tick, which also repairs a refresh that failed.

func (*Service) SetWriter

func (s *Service) SetWriter(c WriterConfig)

SetWriter fills what the changes of Destinations need, before any change.

func (*Service) Test

func (s *Service) Test(ctx context.Context, r Requester, publicID string, src Source) (TestResult, error)

Test runs the Destination test of the Destination publicID from s (C-16.FR-1 to FR-3, FR-5, FR-7): one test message to a messenger, or the test event and the "create" request of an outgoing webhook, through the interactive path. A step that found no limiter token in time is limited and sent nothing; the operation still succeeds. When every step succeeded on a Broken Destination its Broken state ends, as after a successful probe; a failed test changes nothing. Every test is recorded in the Audit log as destination.tested, with the source and each step's class, and logged as destination_tested; its requests are recorded as the kind test with the Destination under one check run, which the result names (C-23.FR-2, FR-5).

func (*Service) Update

func (s *Service) Update(ctx context.Context, r Requester, publicID string, version *int64, in Input) (Destination,
	error)

Update replaces the configured fields of the Destination publicID (C-13.FR-2, FR-3, C-14.FR-2, C-22.FR-3, C-24.FR-3); a non-nil version must be its current one (If-Match). Saving runs the Destination check as Create does, limited by the Destination; a passing check of a Broken Destination ends its Broken state (C-13.FR-10, C-14.FR-14). An update that changes nothing writes nothing.

type SigningSecret

type SigningSecret struct {
	Set                 bool
	UpdatedAt           *time.Time
	PreviousActiveSince *time.Time
}

SigningSecret is the status of the Signing secret of an outgoing webhook.

type SlackChannelCheck

type SlackChannelCheck struct {
	Connection  string
	Destination *int64
	ChannelID   string
}

SlackChannelCheck is the Destination check of a Slack channel through the Connection Connection (public_id): of the saved Destination Destination (its id) when it exists, so that its limiter applies, else of the Connection alone.

type SlackChannelChecked

type SlackChannelChecked struct {
	ConnectionID int64
	Check        slack.ChannelCheck
}

SlackChannelChecked is the result of a SlackChannelCheck: the id of the Connection and the check.

type SlackChecker

type SlackChecker interface {
	CheckSlackChannel(ctx context.Context, c SlackChannelCheck) (SlackChannelChecked, error)
}

SlackChecker runs the Destination check of a Slack channel on the interactive path (C-24.FR-3), declared by its consumer next to BridgeChecker; *connections.Service implements it. A Connection that is not a Slack Connection that is not deleted is ErrUnknownConnection; no limiter token within the budget is a *delivery.LimitedError.

type SlackInput

type SlackInput struct {
	Connection string
	ChannelID  string
}

SlackInput are the fields of a Slack Destination (C-24.FR-3): its Connection by public_id and its channel id, C… or G…, as entered.

type Source

type Source struct {
	Kind         string
	AlertGroupID string
}

Source is the source of a test or a preview (TestSource): a recent Alert Group of one of the Destination's Routes, by its public_id, or the built-in example.

type Store

type Store interface {
	ListDestinations(ctx context.Context, arg dbgen.ListDestinationsParams) ([]dbgen.ListDestinationsRow, error)
	GetDestination(ctx context.Context, arg dbgen.GetDestinationParams) (dbgen.GetDestinationRow, error)
	ListDestinationRoutes(ctx context.Context, arg dbgen.ListDestinationRoutesParams) (
		[]dbgen.ListDestinationRoutesRow, error)
	ListRouteDestinationRefs(ctx context.Context, arg dbgen.ListRouteDestinationRefsParams) (
		[]dbgen.ListRouteDestinationRefsRow, error)
	ListDestinationInfo(ctx context.Context, orgID int64) ([]dbgen.ListDestinationInfoRow, error)
}

Store are the queries of the package.

func NewStore

func NewStore(pool *pgxpool.Pool) Store

NewStore is the Store over the main pool.

type TelegramChannelCheck

type TelegramChannelCheck struct {
	Connection  string
	Destination *int64
	ChannelID   string
}

TelegramChannelCheck is the Destination check of a Telegram channel through the Connection Connection (public_id): of the saved Destination Destination (its id) when it exists, so that its limiter applies, else of the Connection alone.

type TelegramChannelChecked

type TelegramChannelChecked struct {
	ConnectionID int64
	Check        telegram.DestinationCheck
}

TelegramChannelChecked is the result of a TelegramChannelCheck: the id of the Connection and the check.

type TelegramChecker

type TelegramChecker interface {
	CheckTelegramChannel(ctx context.Context, c TelegramChannelCheck) (TelegramChannelChecked, error)
}

TelegramChecker runs the Destination check of a Telegram channel on the interactive path (C-14.FR-2, FR-14), declared by its consumer next to MattermostChecker; *connections.Service implements it. A Connection that is not a Telegram one that is not deleted is ErrUnknownConnection; no limiter token within the budget is a *delivery.LimitedError.

type TelegramInput

type TelegramInput struct {
	Connection string
	ChannelID  string
}

TelegramInput are the fields of a Telegram Destination (C-14.FR-2): its Connection by public_id and its channel, a chat id or an @username, as entered; its discussion group is found by its Destination check.

type TemplateError

type TemplateError struct {
	Since time.Time
	Error string
}

TemplateError is the template error state of an outgoing webhook request template.

type TestResult

type TestResult struct {
	Steps  []delivery.TestStep
	Health Health
	Run    string
}

TestResult is the result of testDestination: each step, the health after the test, and the check run its requests share in the Request log (C-23.FR-5).

type Tester

type Tester interface {
	Test(ctx context.Context, in delivery.TestInput) ([]delivery.TestStep, error)
	Preview(ctx context.Context, in delivery.TestInput) ([]delivery.PreviewItem, error)
}

Tester runs the test of one Destination type through the interactive path and renders its preview without sending anything (C-16), declared by its consumer; *mattermost.Tester, *telegram.Tester, *bridge.Tester, *slack.Tester and *webhooks.Tester implement it. An error is a failure of Muster itself, never of the Destination, whose failures are the steps' classes.

type TxQueries

type TxQueries interface {
	LockDestination(ctx context.Context, arg dbgen.LockDestinationParams) (dbgen.LockDestinationRow, error)
	MarkDestinationDeleted(ctx context.Context, arg dbgen.MarkDestinationDeletedParams) error
	DeleteDestinationRoutes(ctx context.Context, arg dbgen.DeleteDestinationRoutesParams) error

	audit.Store
	Notify(ctx context.Context, h db.Hint) error
	// DB is the transaction the queries run in, which the Retire hook writes through.
	DB() dbgen.DBTX
	// contains filtered or unexported methods
}

TxQueries are the queries of a change of a Destination, with the insert of the Audit log and the live hint, in one transaction.

type WebhookInput

type WebhookInput struct {
	Mode     string
	Events   *webhooks.EventsConfig
	Template *webhooks.TemplateConfig
	Proxy    proxyconf.Input
}

WebhookInput are the fields of an outgoing webhook Destination (C-15.FR-1): its mode, the request of the events mode, the requests of the template mode and its proxy. Only the requests of the mode are stored: the events request in the modes events and both, the request templates in the modes template and both.

type Writer

type Writer interface {
	InTx(ctx context.Context, f func(TxQueries) error) error
}

Writer runs the queries of a change in one transaction.

func NewWriter

func NewWriter(pool *pgxpool.Pool) Writer

NewWriter is the Writer over the main pool.

type WriterConfig

type WriterConfig struct {
	Writer     Writer
	Audit      *audit.Writer
	Business   clock.Clock
	Routes     Routes
	Retire     Retire
	Renamed    Renamed
	Mentions   MentionValidator
	Mattermost MattermostChecker
	Telegram   TelegramChecker
	Bridge     BridgeChecker
	Slack      SlackChecker
	Healthy    Healthy
	Probe      Probe
	Keyring    *keyring.Keyring
	Templates  *templates.Sandbox
	Samples    Samples
	Testers    map[string]Tester
	Log        *logging.Logger
}

WriterConfig is what the changes of Destinations need: the Writer, the Audit log, the business clock that dates the changes, routing's Routes hook and delivery's Retire and Renamed hooks; and for the saves, the validation of Mention settings, the Destination checks of the Mattermost, Telegram, Bridge and Slack types, delivery's end of a Broken state and its probe at once, and for outgoing webhooks the Keyring that encrypts their secrets and the template sandbox that checks their request. Destination tests and previews (C-16) read their sources through Samples, run through the Tester of each type and log through Log.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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