connections

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 35 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 connections holds the Connections of C-13.FR-1, FR-6, C-14.FR-1, C-22.FR-1 and C-24.FR-1: a messenger server, bot or bridge that Destinations post through. A Mattermost Connection has a name, the server URL, a bot token (encrypted, write-only), a proxy and its limiter; a Telegram Connection has a name, a bot token, the Bot API base URL, a proxy, its limiter and its update mode, long polling or webhook; a Bridge Connection has a name, the bridge's base URL, a token, its event delivery mode, poll or push, a push secret in push mode, a proxy, its limiter and the last info its check read; a Slack Connection has a name, a bot token, the event mode, socket or http, an app-level token in socket mode and a Slack signing secret in http mode, a proxy and its limiter, and what its check learned. The package checks a Connection — the token of a Mattermost one, the steps with the dry probe of a Telegram one, the info of a Bridge, the tokens and scopes of a Slack one (slack.go) — lists the channels a Mattermost bot sees, and runs the Destination check of a Mattermost channel for the Destination write path, each on the interactive path (C-11.FR-2); it also checks a draft of a Connection before it is saved, storing nothing (C-13.FR-14, draft.go). It sets and deletes the webhook of a Telegram Connection when its update mode changes, and serves the Telegram Connections to the Leader's poller and to the webhook endpoint. A Connection used by a Destination that is not deleted cannot be deleted; deleting one wipes its secrets and abandons the final edits still pending for its deleted Destinations (C-11.FR-14). Every change is recorded in the Audit log and announced with the live hint connection.

Index

Constants

View Source
const (
	EventDeliveryPoll = bridge.EventDeliveryPoll
	EventDeliveryPush = bridge.EventDeliveryPush
)

The event delivery modes of a Bridge Connection (C-22.FR-1); connection.bridge.event_delivery is poll.

View Source
const (
	BridgeDefaultLimit      = 10
	BridgeDefaultPerSeconds = 1
)

The default limiter of a Bridge Connection (connection.bridge.limiter): 10 requests per second.

View Source
const (
	StepInfo          = "info"
	StepEventDelivery = "event_delivery"
)

The steps of the check of a Bridge Connection (C-22.FR-2).

View Source
const (
	TypeMattermost = "mattermost"
	TypeTelegram   = "telegram"
)

The Connection types; TypeBridge is in bridge.go.

View Source
const (
	ActionCreated      = "connection.created"
	ActionUpdated      = "connection.updated"
	ActionDeleted      = "connection.deleted"
	ResourceConnection = "connection"
	Hint               = "connection"
)

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

View Source
const (
	DefaultLimit      = 5
	DefaultPerSeconds = 1
)

The default limiter of a Mattermost Connection (connection.mattermost.limiter): 5 requests per second, half of the 10 that Mattermost's rate limit allows per client address when an admin turns it on (F-030).

View Source
const (
	TelegramDefaultLimit      = 15
	TelegramDefaultPerSeconds = 1
)

The default limiter of a Telegram Connection (connection.telegram.limiter): 15 messages per second (P-28).

View Source
const (
	ModeLongPolling = "long_polling"
	ModeWebhook     = "webhook"
)

The update modes of a Telegram Connection (C-14.FR-1); connection.telegram.update_mode is long polling.

View Source
const (
	CodeRequired      = "required"
	CodeInvalidFormat = "invalid_format"
	CodeTooLong       = "too_long"
	CodeTooShort      = "too_short"
	CodeUnsupported   = "unsupported"
	// CodeUnknownID is a connection_id of a draft that names no Connection of the draft's type.
	CodeUnknownID = "unknown_id"
	// CodeWebhookCallFailed is a save of a Telegram Connection whose setWebhook or deleteWebhook failed; nothing was
	// saved.
	CodeWebhookCallFailed = "webhook_call_failed"
)

The codes of FieldError.

View Source
const (
	FindingConnection  = "connection"
	FindingDestination = "destination"
)

The kinds of a Finding.

View Source
const (
	EventModeSocket = slack.EventModeSocket
	EventModeHTTP   = slack.EventModeHTTP
)

The event modes of a Slack Connection (C-24.FR-1); connection.slack.event_mode is socket.

View Source
const (
	SlackDefaultLimit      = 50
	SlackDefaultPerSeconds = 60
)

The default limiter of a Slack Connection (connection.slack.limiter, P-60): 50 Web API calls a minute.

View Source
const (
	StepScopes   = slack.StepScopes
	StepAppToken = slack.StepAppToken
)

The steps of the check of a Slack Connection (C-24.FR-2) besides StepToken.

View Source
const CallbackPath = mattermost.CallbackPath

CallbackPath is where Mattermost calls Muster for the button presses of a Connection, under MUSTER_INGEST_URL, with the Connection's public_id after it (C-13.FR-13).

View Source
const StepToken = "token"

The steps of the Connection check.

View Source
const TypeBridge = "bridge"

TypeBridge is the type of a Bridge Connection (C-22.FR-1): a bot of a messenger that a bridge speaks the Bridge protocol for.

View Source
const TypeSlack = "slack"

TypeSlack is the type of a Slack Connection (C-24.FR-1): the bot of a Slack app in one workspace, at Slack's fixed address.

View Source
const WarningAnotherClientConnected = "another_client_connected"

WarningAnotherClientConnected is the warning of a check of a Slack Connection in socket mode whose last hello counted another connection of its Slack app than the Leader's: another program, usually another Connection or installation on the same app, takes some of its presses (C-24.FR-2, F-102).

View Source
const WarningPressAnswersInThread = "press_answers_in_thread"

WarningPressAnswersInThread is the warning of a Connection whose bot may not make ephemeral messages: answers to button presses then show in the Thread of the Root message, not in the channel view (D284, F-063).

Variables

View Source
var (
	// ErrNotFound is a Connection that does not exist in the Organization or is deleted.
	ErrNotFound = errors.New("no such connection")
	// ErrNameTaken is a name another Connection that is not deleted has.
	ErrNameTaken = errors.New("another connection has this name")
	// ErrVersionMismatch is an If-Match that names another version of the Connection.
	ErrVersionMismatch = errors.New("the connection changed since it was read")
	// ErrInUse is the deletion of a Connection that a Destination that is not deleted uses (C-13.FR-6).
	ErrInUse = errors.New("destinations use the connection")
	// ErrNotMattermost is a Mattermost operation, such as the channel list, on a Telegram, Bridge or Slack Connection.
	ErrNotMattermost = errors.New("the connection is not a mattermost connection")
)

Functions

This section is empty.

Types

type Abandon

type Abandon func(ctx context.Context, tx dbgen.DBTX, connectionID int64) (func(context.Context), error)

Abandon is delivery's hook that the deletion of the Connection connectionID runs in its transaction tx: the final edits still pending for its deleted Destinations end as Not delivered. The returned function runs once tx committed.

type Channel

type Channel struct {
	mattermost.Channel
	TeamName string
}

Channel is a channel the bot of a Mattermost Connection is a member of, with its team.

type CheckResult

type CheckResult struct {
	OK      bool
	Steps   []Step
	BotName string
	// Warnings are hints that do not fail the check, such as WarningPressAnswersInThread.
	Warnings       []string
	WebhookSet     *bool
	PendingUpdates *int64
	Bridge         bool
	Info           json.RawMessage
	Slack          *SlackIdentity
	// Run is the check run its requests share in the Request log (C-23.FR-5).
	Run string
}

CheckResult is the result of a Connection check: its steps and the bot's username once the token works; for a Telegram Connection, once getWebhookInfo answered, whether a webhook is set and how many updates wait; for a Bridge, marked by Bridge, the info that its step info read, as the bridge sent it, nil when that step failed; for a Slack Connection, what the step token found, with the app of the step app_token, nil when token failed.

type Config

type Config struct {
	OrgID   int64
	Store   Store
	Keyring *keyring.Keyring
	Audit   *audit.Writer
	// Clocks: the business clock dates the rows, the real clock measures the latency of a check.
	Clocks clock.Clocks
	// Network is what the Mattermost, Telegram, Bridge and Slack clients need: the outbound address policy, the logger
	// and a resolver.
	Network mattermost.Network
	// SlackRoute is, under muster dev, where a Slack Connection's requests go instead of Slack by its bot token: the
	// fake Slack server for its published tokens; nil sends every request to Slack.
	SlackRoute slack.Route
	// TelegramRoute, MattermostRoute and BridgeRoute are, under muster dev, where a Connection's requests go instead of
	// its address, by that address and its token: the fake servers for realistic addresses with their published
	// tokens; nil sends every request to the Connection's address.
	TelegramRoute   telegram.Route
	MattermostRoute mattermost.Route
	BridgeRoute     bridge.Route
	// Interactive is the interactive path, which the checks and the channel list take their limiter tokens from.
	Interactive Interactive
	// IngestURL is MUSTER_INGEST_URL, the base of the callback address and of the webhook of a Telegram Connection.
	IngestURL *url.URL
	Abandon   Abandon
	Log       *logging.Logger
}

Config is what a Service needs.

type Connection

type Connection struct {
	ID                 int64
	PublicID           string
	Type               string
	Name               string
	ServerURL          string
	BotAPIBaseURL      string
	UpdateMode         string
	Warnings           []string
	BridgeBaseURL      string
	EventDelivery      string
	PushSecret         keyring.SecretStatus
	BridgeInfo         json.RawMessage
	BridgeInfoReadAt   *time.Time
	EventMode          string
	AppToken           keyring.SecretStatus
	SlackSigningSecret keyring.SecretStatus
	SlackTeamID        *string
	SlackTeamName      *string
	SlackAppID         *string
	SlackSocket        *SlackSocket
	BotToken           keyring.SecretStatus
	BotUsername        *string
	BotUserID          *string
	Proxy              proxyconf.Config
	ProxyPassword      keyring.SecretStatus
	Limiter            Limiter
	DestinationCount   int64
	CreatedAt          time.Time
	Version            int64
}

Connection is a Connection as the API reads it; its secrets show only their status. ServerURL is a Mattermost Connection's; BotAPIBaseURL, UpdateMode and Warnings are a Telegram Connection's; BridgeBaseURL, EventDelivery, PushSecret, BridgeInfo — the last info its check read, as the bridge sent it, nil before — and BridgeInfoReadAt are a Bridge Connection's; EventMode, AppToken, SlackSigningSecret, what its last passing check learned — SlackTeamID, SlackTeamName and SlackAppID, nil before — and SlackSocket — what the last hello of its Socket Mode connection counted, nil in http mode and before the first hello after a save — are a Slack Connection's.

type Demo

type Demo struct {
	Type      string
	Name      string
	Was       string
	ServerURL string
	BaseURL   string
	BotToken  logging.Secret
	AppToken  logging.Secret
}

Demo is a demo Connection of `muster dev`: a Mattermost Connection to the fake server, or, with the type telegram, a Telegram one to the fake Bot API in the long-polling mode, or, with the type bridge, a Bridge to the fake bridge (BaseURL) in poll mode, or, with the type slack, a Slack Connection in socket mode with the fake Slack server's bot token and app-level token (AppToken), such as "Example Slack", whose requests the route of `muster dev` sends to the fake server. Was is the name an earlier version gave it, such as "Dev Slack".

type DoctorQueries

type DoctorQueries interface {
	ListConnections(ctx context.Context, arg dbgen.ListConnectionsParams) ([]dbgen.ListConnectionsRow, error)
	ListMattermostDestinations(ctx context.Context, orgID int64) ([]dbgen.ListMattermostDestinationsRow, error)
	ListTelegramDestinations(ctx context.Context, orgID int64) ([]dbgen.ListTelegramDestinationsRow, error)
	ListBridgeDestinations(ctx context.Context, orgID int64) ([]dbgen.ListBridgeDestinationsRow, error)
	ListSlackDestinations(ctx context.Context, orgID int64) ([]dbgen.ListSlackDestinationsRow, error)
}

DoctorQueries are the reads of muster doctor's checks; *dbgen.Queries implements them.

type Draft

type Draft struct {
	Type          string
	ServerURL     string
	BotAPIBaseURL string
	UpdateMode    string
	BridgeBaseURL string
	EventDelivery string
	EventMode     string
	BotToken      keyring.SecretInput
	AppToken      keyring.SecretInput
	Proxy         *proxyconf.Input
	ConnectionID  *string
}

Draft is a Connection as its form holds it before it is saved (C-13.FR-14): its type and address — the server URL of a Mattermost one, the Bot API base URL and update mode of a Telegram one, the base URL and event delivery mode of a Bridge, the event mode of a Slack one, whose address is Slack's —, the bot token typed in the form, Keep when none is, and for Slack the app-level token, its proxy, nil for no proxy on a new Connection and for the saved one on a saved Connection, and ConnectionID, the public_id of the saved Connection the form edits, nil for a new one.

type FieldError

type FieldError struct {
	Pointer string
	Code    string
	Detail  string
}

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.

func (*FieldError) Error

func (e *FieldError) Error() string

type Finding

type Finding struct {
	Kind    string
	Name    string
	Message string
	Warning string
}

Finding is the outcome of muster doctor's check of a Connection or a Destination: its kind, its name, when the check failed, the message of the step that failed, and when it passed with a hint, the hint.

func (Finding) OK

func (f Finding) OK() bool

OK reports whether the check passed.

type Input

type Input struct {
	Type               string
	Name               string
	ServerURL          string
	BotAPIBaseURL      string
	UpdateMode         string
	BridgeBaseURL      string
	EventDelivery      string
	PushSecret         keyring.SecretInput
	EventMode          string
	AppToken           keyring.SecretInput
	SlackSigningSecret keyring.SecretInput
	BotToken           keyring.SecretInput
	Proxy              proxyconf.Input
	Limiter            Limiter
}

Input is what createConnection and updateConnection write. An omitted bot token keeps the stored one on an update and is required on a creation. ServerURL is a Mattermost Connection's; BotAPIBaseURL and UpdateMode a Telegram one's; BridgeBaseURL, EventDelivery and PushSecret a Bridge Connection's, whose omitted push secret keeps the stored one; EventMode, AppToken and SlackSigningSecret a Slack Connection's, whose omitted secrets keep the stored ones.

type Interactive

type Interactive interface {
	Do(ctx context.Context, s delivery.Subject, op delivery.Op) (delivery.Outcome, error)
}

Interactive is the interactive path, declared by its consumer; *delivery.Interactive implements it.

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
	After *int64
	Limit int
}

ListFilter selects a page of Connections, of a type when set, in the order they were created, after the id After.

type MessengerError

type MessengerError struct {
	Messenger string
	Text      string
}

MessengerError is a call to the messenger that failed for a reason other than its limiter, such as a channel list that the server refused: the messenger that refused it, Mattermost when it is empty, and its text, masked of secrets and untrusted.

func (*MessengerError) Error

func (e *MessengerError) Error() string

type Page

type Page struct {
	Connections []Connection
	Next        *int64
}

Page is a page of Connections; Next, the id to continue after, is nil on the last page.

type Queries

type Queries interface {
	ListConnections(ctx context.Context, arg dbgen.ListConnectionsParams) ([]dbgen.ListConnectionsRow, error)
	GetConnection(ctx context.Context, arg dbgen.GetConnectionParams) (dbgen.GetConnectionRow, error)
	LockConnection(ctx context.Context, arg dbgen.LockConnectionParams) (dbgen.LockConnectionRow, error)
	FindConnectionByName(ctx context.Context, arg dbgen.FindConnectionByNameParams) (int64, error)
	InsertConnection(ctx context.Context, arg dbgen.InsertConnectionParams) (int64, error)
	UpdateConnection(ctx context.Context, arg dbgen.UpdateConnectionParams) error
	RenameConnection(ctx context.Context, arg dbgen.RenameConnectionParams) error
	SetBotIdentity(ctx context.Context, arg dbgen.SetBotIdentityParams) error
	SetBridgeInfo(ctx context.Context, arg dbgen.SetBridgeInfoParams) (int64, error)
	SetSlackIdentity(ctx context.Context, arg dbgen.SetSlackIdentityParams) (int64, error)
	CountConnectionDestinations(ctx context.Context, arg dbgen.CountConnectionDestinationsParams) (int64, error)
	MarkConnectionDeleted(ctx context.Context, arg dbgen.MarkConnectionDeletedParams) error
	ListPollingConnections(ctx context.Context, orgID int64) ([]dbgen.ListPollingConnectionsRow, error)
	LockUpdates(ctx context.Context, arg dbgen.LockUpdatesParams) error
	GetUpdateOffset(ctx context.Context, arg dbgen.GetUpdateOffsetParams) (dbgen.GetUpdateOffsetRow, error)
	GetOutage(ctx context.Context) (dbgen.GetOutageRow, error)
	StoreUpdateOffset(ctx context.Context, arg dbgen.StoreUpdateOffsetParams) error
	LockDemo(ctx context.Context, key int64) error
	GetDestinationTarget(ctx context.Context, arg dbgen.GetDestinationTargetParams) (dbgen.GetDestinationTargetRow,
		error)
	GetTelegramDestinationTarget(ctx context.Context, arg dbgen.GetTelegramDestinationTargetParams) (
		dbgen.GetTelegramDestinationTargetRow, error)
	GetBridgeDestinationTarget(ctx context.Context, arg dbgen.GetBridgeDestinationTargetParams) (
		dbgen.GetBridgeDestinationTargetRow, error)
	GetSlackDestinationTarget(ctx context.Context, arg dbgen.GetSlackDestinationTargetParams) (
		dbgen.GetSlackDestinationTargetRow, error)

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

Queries are the queries of the package, with the insert of the Audit log and the live hint.

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 Service

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

Service holds the Connections of the Organization, and the clients the adapter posts through, built once per version of their Connection, and the info of the Bridge Connections.

func New

func New(cfg Config) *Service

New returns the Service of the Organization in cfg.

func (*Service) BridgeCallbackURL

func (s *Service) BridgeCallbackURL(publicID string) string

BridgeCallbackURL is where a bridge in push mode posts the events of the Connection publicID: MUSTER_INGEST_URL followed by /api/v1/callbacks/bridge/<public_id> (C-22.FR-1).

func (*Service) BridgeConn

func (s *Service) BridgeConn(ctx context.Context, publicID string) (bridge.Conn, error)

BridgeConn is the Bridge Connection publicID with its client, kept until the Connection changes, for the calls of an Account link by code (bridge.LinkConnections); a Connection that is unknown, deleted or not a Bridge Connection is bridge.ErrNoConnection.

func (*Service) BridgeInfo

func (s *Service) BridgeInfo(ctx context.Context, conn bridge.Conn, class outbound.Class) (bridge.Info, bridge.Result)

BridgeInfo is the info of the Bridge Connection conn for the Bridge delivery (bridge.Targets): Muster's copy, through the InfoCache, read again through conn's client in class when it is older than bridge.info_max_age.

func (*Service) BridgeTarget

func (s *Service) BridgeTarget(ctx context.Context, destinationID int64) (bridge.Target, error)

BridgeTarget is where the Bridge Destination destinationID posts, for the Bridge delivery (bridge.Targets): its channel id and its Connection with the protocol client, kept until the Connection changes. A deleted Destination still has one, for its final edit. A Destination that is unknown or not a Bridge one, or whose Connection is deleted or not a Bridge Connection, is bridge.ErrNoTarget.

func (*Service) CallbackURL

func (s *Service) CallbackURL(publicID string) string

CallbackURL is the read-only callback address of the Connection publicID: MUSTER_INGEST_URL followed by /api/v1/callbacks/mattermost/<public_id> (C-13.FR-13).

func (*Service) Channels

func (s *Service) Channels(ctx context.Context, publicID, teamID, q string) ([]Channel, error)

Channels lists the channels the bot of the Mattermost Connection publicID belongs to, team by team, through the interactive path: the bot's teams, the team teamID only when it is set, then the bot's channels of each, those whose name or display name contains q when it is set, case-insensitively. A Telegram, Bridge or Slack Connection is ErrNotMattermost; a refused call a *MessengerError.

func (*Service) Check

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

Check runs the Connection check of the Connection publicID on the interactive path, limited by the Connection. A Telegram Connection is checked in steps by checkTelegram, against the unsaved baseURL when it is set, a Bridge by checkBridge and a Slack Connection by checkSlack, which take no baseURL. A Mattermost one (C-13.FR-2), which takes no baseURL either, is checked with GET /api/v4/users/me with the bot token. A token that works records the bot's username and user id on the Connection; a 401 fails with "The bot token is not valid." and mattermost.CodeTokenInvalid, any other failure with the code of mattermost.Result.FailureCode. No limiter token within the budget is a *delivery.LimitedError. Once the token works, a read of the bot's roles tells whether it may make ephemeral posts; when it may not, the check passes with WarningPressAnswersInThread (D284, F-064); a failed read adds nothing. Its requests are recorded as the kind connection_check under one check run, which the result names (C-23.FR-2, FR-5).

func (*Service) CheckBridgeChannel

CheckBridgeChannel runs the Destination check of a Bridge Destination being saved or checked, for the Destination write path (C-22.FR-3): checkChannel through the Bridge Connection that the check names, on the interactive path, limited by the Destination when it exists and by the Connection otherwise, with a client built for the check. A Connection that is missing, deleted or not a Bridge Connection is destinations.ErrUnknownConnection.

func (*Service) CheckChannel

CheckChannel runs the Destination check of a Mattermost Destination being saved or checked, for the Destination write path (C-13.FR-2, FR-10): through the Mattermost Connection that ChannelCheck names, on the interactive path, limited by the Destination when it exists and by the Connection otherwise. A Connection that is missing, deleted or not a Mattermost one is destinations.ErrUnknownConnection.

func (*Service) CheckDraft

func (s *Service) CheckDraft(ctx context.Context, d Draft) (CheckResult, error)

CheckDraft runs the check of a draft Connection d on the interactive path without saving it (C-13.FR-14), with the steps and the codes of Check. It validates d as a save would — the address of its type, the connection_id, the proxy — and then decides the token: a bot token typed in d goes to the address of d; without one, the stored token of the Connection d edits is used only when d's address, normalized as a save normalizes it, and d's proxy route are the saved ones; otherwise only the dry probe of the type runs and the other steps are skipped. The address of a Slack draft is Slack's, so only its proxy can differ; its app-level token follows slackDraftRoute. A stored proxy password is used only with the saved route and no password in d. The clients are built for the check and never kept; their requests, the dry probe's included, are recorded as draft_check under the Connection the draft names, or without an owner, under one check run that the result names (C-23.FR-1, FR-5). A draft of a saved Connection takes its limiter tokens from that Connection, one of a new Connection takes none; no limiter token within the budget is a *delivery.LimitedError. It stores nothing: no bot, no info, no Audit log entry, no hint and no log event.

func (*Service) CheckSlackChannel

CheckSlackChannel runs the Destination check of a Slack Destination being saved or checked, for the Destination write path (C-24.FR-3): conversations.info through the Slack Connection that the check names, on the interactive path, limited by the Destination when it exists and by the Connection otherwise, with a client built for the check. The text of bot_not_in_channel names the bot by the name the Connection's last passing check stored, and by none before one. A Connection that is missing, deleted or not a Slack Connection is destinations.ErrUnknownConnection.

func (*Service) CheckTelegramChannel

CheckTelegramChannel runs the Destination check of a Telegram Destination being saved or checked, for the Destination write path (C-14.FR-2, FR-14): through the Telegram Connection that the check names, on the interactive path, limited by the Destination when it exists and by the Connection otherwise. A Connection that is missing, deleted or not a Telegram one is destinations.ErrUnknownConnection.

func (*Service) Connection

func (s *Service) Connection(ctx context.Context, publicID string) (mattermost.Connection, error)

Connection is the Mattermost Connection publicID with its client and the user id of its bot, for the callback of its button presses; a Connection that is unknown, deleted or not a Mattermost one is mattermost.ErrNoConnection.

func (*Service) Create

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

Create creates a Mattermost Connection (C-13.FR-1), a Telegram one (C-14.FR-1), a Bridge (C-22.FR-1) or a Slack one (C-24.FR-1). The bot token, the push secret of a Bridge and the app-level token and Slack signing secret of a Slack Connection are encrypted with the active key and never returned. A Telegram Connection created in the webhook mode gets a new secret token and its webhook is set before the creation commits; when setWebhook fails, nothing is created.

func (*Service) Delete

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

Delete deletes the Connection publicID (C-13.FR-6); a non-nil version must be its current one. While a Destination that is not deleted uses it the deletion is ErrInUse. Otherwise, in one transaction, it is marked deleted and its secrets are wiped, delivery abandons the final edits still pending for its deleted Destinations (C-11.FR-14), and the Audit log entry connection.deleted is written. A Telegram Connection in the webhook update mode then has its webhook removed as a best effort (unhook).

func (*Service) Doctor

func (s *Service) Doctor(ctx context.Context, q DoctorQueries, each time.Duration) ([]Finding, error)

Doctor runs the checks of muster doctor (C-02.FR-14) over the Connections and the Mattermost, Telegram, Bridge and Slack Destinations that are not deleted, read through q: the Connection check of a Mattermost Connection (GET /api/v4/users/me), the steps of a Telegram one (the dry probe, getMe, getWebhookInfo), of a Bridge one (getInfo, then whether the info it read offers the Connection's event delivery mode, C-22.FR-2) and of a Slack one (token, scopes and in socket mode app_token, C-24.FR-2), and the Destination checks of mattermost.CheckDestination, telegram.CheckDestination, bridge.CheckDestination (checkChannel, C-22.FR-3) and slack.CheckChannel (conversations.info, C-24.FR-3), each request made at once in the background client class, whose retries each check bounds by each. A Telegram, Bridge or Slack Connection that fails names the failing step with its message, and a Bridge or Slack Destination the item channel; a Slack Connection in socket mode that passes warns when the last hello of its Socket Mode connection counted another connection of its Slack app than the Leader's. It only reads: it records nothing of what it finds, not even a Bridge's info or a Slack workspace. It needs the Keyring and the Network of the Service only, and the Slack route under muster dev; without a Keyring every check fails, for the bot tokens cannot be opened.

func (*Service) EnsureDemo

func (s *Service) EnsureDemo(ctx context.Context, d Demo) error

EnsureDemo creates the demo Connection d unless a Connection that is not deleted has its name, as a start-up step of `muster dev` that replicas starting together run once. A Connection of d's type with its earlier name (Was), kept in a development database from an earlier version, is renamed instead, with its id and secrets; one of another type with that name is left alone and nothing is created.

func (*Service) Get

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

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

func (*Service) HandleEventOnce

func (s *Service) HandleEventOnce(ctx context.Context, connectionID int64, eventID string,
	f func(context.Context) error) (bool, error)

HandleEventOnce runs f for the event eventID of the Bridge Connection connectionID unless its id was recorded within bridge.event_dedup_window (bridge.Connections), in one transaction that holds the claim's advisory lock — of the class bridgeEventLockClass, keyed by the Connection and the event id — so that a second copy of the event waits for the first and then finds its id recorded; once f succeeded, the id is recorded at the business clock's now and the transaction commits. f runs its own transactions on other connections of the pool: the claim holds no row lock that the dispatcher takes. An error of f records nothing, so that the event comes again; a crash after f and before the commit repeats f once on redelivery, which the dispatcher's preconditions turn into a refusal or a no-op (ADR-0017).

func (*Service) HandleOnce

func (s *Service) HandleOnce(ctx context.Context, id, updateID int64, f func(context.Context) error) (bool, error)

HandleOnce runs f for the update updateID of the Telegram Connection id unless its stored offset is past it, and then raises the offset to updateID+1, all in one transaction under the Connection's update lock (telegram.Offsets): a transaction advisory lock of the class db.TelegramUpdateLockClass keyed by the Connection, so that a second poller of a frozen old Leader, or a webhook request with the same update, waits for it and then skips the update. The offset is read without a row lock, and the final GREATEST update is the only statement that touches the connections row: a handler runs while a save of the Connection holds the row during setWebhook, and only that final write waits for the save; the delivery worker reschedules an edit of a Root message of the Connection while the lock is held. A save that sets a new bot token while a handler runs forgets the offset, and the final write leaves it forgotten. A deleted Connection runs nothing. An error of f stores nothing, so that the update comes again.

func (*Service) Hooked

func (s *Service) Hooked(ctx context.Context, publicID string) (telegram.Conn, logging.Secret, error)

Hooked is the Telegram Connection publicID of a webhook request with its secret token (telegram.Hooks); a Telegram Connection not in the webhook mode or without a secret token is returned without a client or a secret token; one that is unknown, deleted or not a Telegram one is telegram.ErrNoWebhook.

func (*Service) List

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

List reads a page of the Connections that are not deleted, in id order.

func (*Service) Outage

func (s *Service) Outage(ctx context.Context) (telegram.Outage, error)

Outage reads when Muster was last known not to run, for the age of presses (telegram.Outages, C-14.FR-4): the Leader's alive mark and the latest downtime period it recorded.

func (*Service) Polling

func (s *Service) Polling(ctx context.Context) ([]telegram.Polled, error)

Polling lists the Telegram Connections in the long-polling mode for the Leader's poller (telegram.Source), each with its client, kept until the Connection changes, and its stored offset. A Connection whose secrets cannot be opened is left out, with telegram_poll_failed.

func (*Service) PollingConnections

func (s *Service) PollingConnections(ctx context.Context) ([]bridge.Polled, error)

PollingConnections lists the Bridge Connections in poll mode for the Leader's poller (bridge.Connections), each with its client, kept until the Connection changes, and its stored cursor. A Connection whose client cannot be built has the error instead of a client, and the poller logs it.

func (*Service) PruneEventsSeen

func (s *Service) PruneEventsSeen(ctx context.Context, now time.Time, limit int32) (int64, error)

PruneEventsSeen deletes at most limit records of Bridge event ids seen bridge.event_dedup_window before now, on the business clock, for short-lived pruning, and returns how many it deleted.

func (*Service) PushConnection

func (s *Service) PushConnection(ctx context.Context, publicID string) (bridge.Conn, string, error)

PushConnection is the Bridge Connection publicID for the push callback (bridge.Connections) with its event delivery mode, and in push mode its client, kept until the Connection changes, whose settings hold the push secret. A Connection in poll mode has no client: its secrets are never opened, so that the callback refuses it as it refuses an unknown one, whether they can be opened or not. A Connection that is unknown, deleted or not a Bridge Connection is bridge.ErrNoConnection.

func (*Service) RecordSocketHello

func (s *Service) RecordSocketHello(ctx context.Context, c slack.SocketConn, other int) error

RecordSocketHello records what a hello of the Socket Mode connection of the Slack Connection c counted (slack.SocketSource): when it came, at the business clock's now, and other, the connections of its app beyond those the Leader holds — unless the Connection changed since c was read, left socket mode or was deleted. When it recorded them it sends the live hint, so that the Connection's page shows them. It is not a change of the configuration: the version, the ETag and the Audit log stay as they were.

func (*Service) SlackCallbackURL

func (s *Service) SlackCallbackURL(publicID string) string

SlackCallbackURL is where Slack posts the button presses of the Slack Connection publicID in http mode: MUSTER_INGEST_URL followed by /api/v1/callbacks/slack/<public_id> (C-24.FR-1).

func (*Service) SlackChannels

func (s *Service) SlackChannels(ctx context.Context, publicID, q string) (slack.ChannelList, error)

SlackChannels lists the channels of the Slack Connection publicID for the channel picker (C-24.FR-3): those the bot is a member of, public and private, not archived, whose name contains q, read with conversations.list on the interactive path, limited by the Connection, at most five pages. A Slack 429 on a page, which holds the Connection's limiter, is a *delivery.LimitedError with its Retry-After, as no token within the budget is; a page that failed otherwise is a *MessengerError that names Slack. A deleted or unknown Connection is ErrNotFound; one of another type is errNotSlack.

func (*Service) SlackLinkConnection

func (s *Service) SlackLinkConnection(ctx context.Context, publicID string) (slack.Conn, error)

SlackLinkConnection is the Slack Connection publicID with its client, kept until the Connection changes, for the calls of an Account link (slack.LinkConnections) in either event mode; one that is unknown, deleted or not a Slack Connection is slack.ErrNoConnection.

func (*Service) SlackPressConnection

func (s *Service) SlackPressConnection(ctx context.Context, publicID string) (slack.Conn, logging.Secret, error)

SlackPressConnection is the Slack Connection publicID as the callback of its presses needs it (slack.Connections): its event mode, its client, kept until the Connection changes, and its Slack signing secret. A Slack Connection in socket mode, or in http mode without a stored secret, comes without its client and with an empty secret, which the callback refuses as it refuses a wrong signature, and records (C-23.FR-1); one that is unknown, deleted or not a Slack Connection is slack.ErrNoConnection.

func (*Service) SlackTarget

func (s *Service) SlackTarget(ctx context.Context, destinationID int64) (slack.Target, error)

SlackTarget is where the Slack Destination destinationID posts, for the Slack delivery (slack.Targets): its channel id and its Connection with the Web API client, kept until the Connection changes, and the workspace address and the bot's name the Connection's last passing check stored, read every time. A deleted Destination still has one, for its final edit. A Destination that is unknown or not a Slack one, or whose Connection is deleted or not a Slack Connection, is slack.ErrNoTarget.

func (*Service) SocketConnections

func (s *Service) SocketConnections(ctx context.Context) ([]slack.SocketConn, error)

SocketConnections lists the Slack Connections in socket mode that are not deleted, for the Leader's sockets (slack.SocketSource): each with its client, kept until the Connection changes, whose requests — apps.connections.open among them — go to the Request log of the Connection, and its version. A Connection whose client cannot be built has the error instead of a client, and the sockets log it.

func (*Service) StoreEventsCursor

func (s *Service) StoreEventsCursor(ctx context.Context, c bridge.Conn, cursor *string) error

StoreEventsCursor stores the cursor of the events of the Bridge Connection c, or drops it when cursor is nil (bridge.Connections); it stores nothing once the Connection changed since c was read, or was deleted. It is not a change of the configuration.

func (*Service) StoreInfo

func (s *Service) StoreInfo(ctx context.Context, conn bridge.Conn, i bridge.Info, at time.Time) error

StoreInfo stores the info i that a read of the Bridge Connection conn found at at, on the business clock, as the bridge sent it, and sends the Connection's live hint (bridge.InfoStore). It stores nothing for a Connection that changed since conn was read.

func (*Service) StoredInfo

func (s *Service) StoredInfo(ctx context.Context, conn bridge.Conn) (bridge.Stored, bool, error)

StoredInfo is the info that a read of the Bridge Connection conn stored, with when it was read (bridge.InfoStore); there is none for a Connection that is deleted or no longer at conn's version, or that was never read.

func (*Service) Target

func (s *Service) Target(ctx context.Context, destinationID int64) (mattermost.Target, error)

Target is where the Mattermost Destination destinationID posts, for the adapter: its team and channel and the client of its Connection, which is kept, with its outbound transports, until the Connection changes. A deleted Destination still has one, for its final edit. A Destination that is unknown, not a Mattermost one, or whose Connection is deleted is mattermost.ErrNoTarget.

func (*Service) TelegramConn

func (s *Service) TelegramConn(ctx context.Context, publicID string) (telegram.Conn, error)

TelegramConn is the Telegram Connection publicID with its client, for the bot's reads of an Account link (telegram.ConnLookup); a Connection that is unknown, deleted or not a Telegram one is ErrNotFound.

func (*Service) TelegramTarget

func (s *Service) TelegramTarget(ctx context.Context, destinationID int64) (telegram.Target, error)

TelegramTarget is where the Telegram Destination destinationID sends, for the adapter: its channel, the ids of the channel and of its discussion group that its Destination check learned, and the client of its Connection, kept until the Connection changes. A deleted Destination still has one, for its final edit. A Destination that is unknown, not a Telegram one, or whose Connection is deleted is telegram.ErrNoTarget.

func (*Service) Update

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

Update replaces the configured fields of the Connection publicID; a non-nil version must be its current one (If-Match). An omitted bot token, proxy password, push secret, app-level token or Slack signing secret keeps the stored one, except that a new server URL, Bot API base URL or bridge base URL needs the bot token again, so that the stored one never reaches another server; a new address or bot token forgets the bot that the last check found, a Bridge's info and events cursor, and the workspace and app that a Slack check found. An update that changes nothing writes nothing. A Telegram Connection that enters the webhook mode, or changes its base URL or bot token in it, gets a new secret token and setWebhook; one that leaves it gets deleteWebhook; both run before the update commits, and when they fail nothing is saved.

func (*Service) WebhookURL

func (s *Service) WebhookURL(publicID string) string

WebhookURL is where Telegram posts the updates of the Connection publicID in the webhook mode: MUSTER_INGEST_URL followed by /api/v1/callbacks/telegram/<public_id> (C-14.FR-1).

type SlackIdentity

type SlackIdentity struct {
	TeamID    string
	TeamName  string
	BotUserID string
	AppID     string
}

SlackIdentity is what a check of a Slack Connection found: the workspace and the bot's user id from the step token, and the app's id from the step app_token, empty without it.

type SlackSocket

type SlackSocket struct {
	HelloAt          time.Time
	OtherConnections int
}

SlackSocket is what the last hello of a Slack Connection's Socket Mode connection counted (C-24.FR-2, FR-9): when it came, on the business clock, and the connections of the app beyond those the Leader holds.

type Step

type Step struct {
	Name          string
	OK            bool
	Skipped       bool
	Latency       time.Duration
	Via           string
	Message       string
	Code          string
	MissingScopes []string
}

Step is a step of a Connection check: whether it passed or was skipped, its latency and path, and when it failed what answered, in English, with its code, which clients translate (ConnectionCheckStep.code), and with missing_scope the scopes the bot token lacks, which clients name in their own words (D396).

func (Step) Called

func (s Step) Called() bool

Called reports whether the step made a call, so that its Latency is that call's: not when it was skipped, nor for StepEventDelivery, which only reads the info that the step info read, nor for StepScopes, which reads the header of the answer of the step token.

type Store

type Store interface {
	Queries
	InTx(ctx context.Context, f func(Queries) error) error
}

Store runs the queries alone or in one transaction.

func NewStore

func NewStore(pool *pgxpool.Pool) Store

NewStore is the Store over the main pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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