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 ¶
- type Adapter
- type Authorization
- type ConfigLister
- type CredentialStore
- type Service
- func (s *Service) BeginAuthorization(ctx context.Context, id string, mode api.AuthorizationMode, callback string, ...) (Authorization, error)
- func (s *Service) Channels(ctx context.Context, id, query string) ([]api.NotifyChannel, error)
- func (s *Service) CompleteManual(ctx context.Context, id string, credential secret.Value) error
- func (s *Service) CompleteWebAuthorization(ctx context.Context, state, code string) (string, error)
- func (s *Service) Get(ctx context.Context, id string) (Adapter, error)
- func (s *Service) List(ctx context.Context) ([]Adapter, error)
- func (s *Service) Notify(ctx context.Context, id string) (api.NotifyAdapter, bool)
- func (s *Service) Usable(ctx context.Context) ([]Adapter, error)
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.
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) CompleteManual ¶
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 ¶
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 ¶
Get builds one adapter, and only that one: the dispatcher asks on every delivery.
func (*Service) List ¶
List builds every enabled notification adapter, ordered by name. One that cannot be built is listed with its Problem rather than left out.