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

notifyconn

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package notifyconn is the install's notification adapters as core uses them (R-373, R-374): built from their rows each time one is used, connected to their provider when they need it, and asked which channels a subscription can post to.

A stored notification adapter is built from its adapter_configs row and its sealed credentials on every use rather than once at startup, like a source connection (core/sourceconn) and an image registry (core/imageregistry). So adding one needs no restart, and connecting Slack — whose bot token arrives after the adapter is saved — takes effect on every replica at once. One the configuration file declares is built at startup and is read-only (R-271).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Kind string `json:"kind"`

	Capabilities api.NotifyCapabilities `json:"capabilities"`

	// Declared says the configuration file declares it, so it is changed
	// there and not connected from here.
	Declared bool `json:"declared,omitempty"`

	// Problem is why it cannot send — its settings or credentials were
	// refused — or empty.
	Problem string `json:"problem,omitempty"`
	// contains filtered or unexported fields
}

Adapter is one notification adapter, built.

func (Adapter) Usable

func (a Adapter) Usable() bool

Usable says the adapter can send now: built, and connected when it is one that connects. One that takes no authorization is ready once configured.

type Authorization

type Authorization struct {
	Mode         api.AuthorizationMode `json:"mode"`
	AuthorizeURL string                `json:"authorize_url"`
}

Authorization is a connection started, as a person is shown it: where to send the browser — the provider's approval screen, or its page for setting the integration up by hand.

type ConfigLister

type ConfigLister interface {
	List(ctx context.Context) ([]state.AdapterConfig, error)
}

ConfigLister reads configured adapters (state.Adapters).

type CredentialStore

type CredentialStore interface {
	Resolve(ctx context.Context, adapterID string) (map[string]secret.Value, error)
	Put(ctx context.Context, adapterID, field string, v secret.Value) error
	Delete(ctx context.Context, adapterID, field string) error
}

CredentialStore reads and writes sealed credentials (state.AdapterCredentials).

type Service

type Service struct {
	Configs     ConfigLister
	Credentials CredentialStore

	// Authorizations holds connections in progress
	// (state.NewNotifyAuthorizations).
	Authorizations CredentialStore

	// New returns an unconfigured adapter of a kind, or nil.
	New func(kind string) api.NotifyAdapter

	// Declared are the adapters the configuration file declares, built at
	// startup. A row with the same ID is the declared one's record.
	Declared *api.Registry

	Clock clock.Clock
}

Service is the install's notification adapters.

func (*Service) BeginAuthorization

func (s *Service) BeginAuthorization(ctx context.Context, id string, mode api.AuthorizationMode, callback string, grant secret.Value) (Authorization, error)

BeginAuthorization starts connecting an adapter. In web mode grant is the credential the person gave (a Slack configuration token), used for this call only, and callback is where the provider returns the browser; in manual mode the answer is a link to set the integration up by hand.

func (*Service) Channels

func (s *Service) Channels(ctx context.Context, id, query string) ([]api.NotifyChannel, error)

Channels lists the channels a subscription to the adapter can post to.

func (*Service) CompleteManual

func (s *Service) CompleteManual(ctx context.Context, id string, credential secret.Value) error

CompleteManual finishes connecting an adapter by hand: the credential the provider gave (a Slack bot token) is checked by the adapter and stored.

func (*Service) CompleteWebAuthorization

func (s *Service) CompleteWebAuthorization(ctx context.Context, state, code string) (string, error)

CompleteWebAuthorization finishes a connection from the provider's callback. state names the adapter and must match the one it was started with; the provider's answer is stored as the adapter's credentials.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (Adapter, error)

Get builds one adapter, and only that one: the dispatcher asks on every delivery.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]Adapter, error)

List builds every enabled notification adapter, ordered by name. One that cannot be built is listed with its Problem rather than left out.

func (*Service) Notify

func (s *Service) Notify(ctx context.Context, id string) (api.NotifyAdapter, bool)

Notify is the adapter to send through, if it exists and can send — what the subscription service and the dispatcher deliver with.

func (*Service) Usable

func (s *Service) Usable(ctx context.Context) ([]Adapter, error)

Usable lists the adapters that can send now.

Jump to

Keyboard shortcuts

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