pluginkit

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package pluginkit is the shared scaffolding for first-party notification channel plugins. It speaks only the public plugin contract (pluginpb).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(raw string, allowHTTP bool) (*url.URL, error)

BaseURL validates an operator-supplied service address: https only unless allowHTTP, a host, and no embedded credentials.

func Main

func Main(p Plugin)

Main serves p on the unix socket named by PLUGIN_SOCKET until SIGTERM.

func NewServer

func NewServer(p Plugin) *grpc.Server

NewServer returns the gRPC server for p, ready to Serve on a listener.

func ParseConfig

func ParseConfig(raw json.RawMessage, into any) error

ParseConfig decodes the plugin-wide config strictly.

func Redact

func Redact(s string, secrets ...string) string

Redact replaces every non-empty secret in s.

func RetryAfter

func RetryAfter(header string, body []byte) time.Duration

RetryAfter reads a Retry-After header in seconds, or a JSON retry_after_ms.

func Snippet

func Snippet(body []byte) string

Snippet is a short, single-line excerpt of a response body.

func Text

func Text(ev *pluginpb.Event) string

Text renders an event as a short plain-text message.

func Truncate

func Truncate(s string, n int) string

Truncate cuts s to at most n runes, marking the cut.

Types

type Accept

type Accept func(body []byte) (ok bool, detail string)

Accept judges a 2xx response whose body may still report failure.

type Call

type Call struct {
	Event  *pluginpb.Event
	Config json.RawMessage
	Secret string
}

Call is one delivery request: the event, the plugin-wide config and the per-call credential, which a plugin must never store or log.

type DNSCall

type DNSCall struct {
	Config json.RawMessage
	Secret string
	Zone   string
	Record *pluginpb.DnsRecord
}

DNSCall is the config and per-call credential every DNS operation receives. The secret must never be stored or logged by the plugin.

type DNSOutcome

type DNSOutcome struct {
	OK        bool
	Retryable bool
	Detail    string
}

DNSOutcome is the plugin's verdict on one DNS operation.

type DNSProvider

type DNSProvider struct {
	ListZones   func(ctx context.Context, c DNSCall) ([]string, DNSOutcome)
	ListRecords func(ctx context.Context, c DNSCall) ([]*pluginpb.DnsRecord, DNSOutcome)
	Upsert      func(ctx context.Context, c DNSCall) DNSOutcome
	Delete      func(ctx context.Context, c DNSCall) DNSOutcome
	Verify      func(ctx context.Context, c DNSCall) (bool, DNSOutcome)
}

DNSProvider implements the dns_provider contract for one DNS service.

type HTTP

type HTTP struct {
	Client  *http.Client
	Retries int
	Backoff time.Duration
	Sleep   func(ctx context.Context, d time.Duration) error
}

HTTP delivers one request with bounded retries and maps failures to Results.

func (HTTP) Deliver

func (h HTTP) Deliver(ctx context.Context, build func() (*http.Request, error), accept Accept, secrets ...string) Result

Deliver sends the request built by build, retrying network errors, 5xx and short 429s. Every detail it returns has secrets redacted.

type Plugin

type Plugin struct {
	Name         string
	Version      string
	ConfigSchema string
	Send         func(ctx context.Context, c Call) Result
	// DNS makes this a dns_provider plugin. Send is then unused.
	DNS *DNSProvider
}

Plugin describes one channel and how it delivers.

type Result

type Result struct {
	Delivered bool
	Retryable bool
	Detail    string
}

Result is the plugin's answer to a Call.

func Invalid

func Invalid(err error) Result

Invalid is a permanent failure caused by operator configuration.

Directories

Path Synopsis
Package pluginkittest holds the checks every first-party plugin test shares.
Package pluginkittest holds the checks every first-party plugin test shares.

Jump to

Keyboard shortcuts

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