provider

package
v0.19.1237 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package provider defines the interface an inbound event provider implements: creation-time defaults, envelope decoding, request verification, protocol handshakes, and rejection behavior. Base supplies the complete default behavior so plain providers are declarative data and protocol-heavy providers override only what differs.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflictingAuthConfig = errors.New("conflicting auth_config")

ErrConflictingAuthConfig is returned by ApplyDefaults when the caller supplies auth config that contradicts the provider defaults.

View Source
var ErrUnsupportedEnvelope = errors.New("trigger envelope is not implemented")

ErrUnsupportedEnvelope is returned by Decoder for envelope types the provider does not implement.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Header          string   `json:"header,omitempty"`
	Prefix          string   `json:"prefix,omitempty"`
	Encoding        string   `json:"encoding,omitempty"`
	Algorithm       string   `json:"algorithm,omitempty"`
	Username        string   `json:"username,omitempty"`
	Issuer          string   `json:"issuer,omitempty"`
	Audience        []string `json:"audience,omitempty"`
	TopicARN        string   `json:"topic_arn,omitempty"`
	ExpectedEmail   string   `json:"expected_email,omitempty"`
	ExpectedSubject string   `json:"expected_subject,omitempty"`
}

AuthConfig configures how inbound requests authenticate.

func ApplyDefaults

func ApplyDefaults(defaults Defaults, provided AuthConfig) (AuthConfig, error)

ApplyDefaults resolves a caller-supplied auth config against provider defaults: caller fields are adopted, unset basic fields are defaulted, and any remaining difference is a conflict.

type AuthType

type AuthType string
const (
	AuthNone         AuthType = "none"
	AuthHMAC         AuthType = "hmac"
	AuthAPIKey       AuthType = "api_key"
	AuthBasic        AuthType = "basic"
	AuthBearerJWT    AuthType = "bearer_jwt"
	AuthSNSSignature AuthType = "sns_signature"
)

type Base

type Base struct {
	ProviderName     string
	ProviderDefaults Defaults
}

Base is the default Provider implementation: config-driven decoding and verification, no handshake, and accept-and-record rejection.

func (Base) Decoder

func (b Base) Decoder(envelopeType EnvelopeType) (envelope.Decoder, error)

func (Base) Defaults

func (b Base) Defaults() Defaults

func (Base) Handshake

func (b Base) Handshake(*envelope.Event) (*Handshake, error)

func (Base) Name

func (b Base) Name() string

func (Base) RejectStatus

func (b Base) RejectStatus(error) int

func (Base) Verifier

func (b Base) Verifier(auth AuthType, cfg AuthConfig) signature.Verifier

type CallerField

type CallerField string

CallerField names an AuthConfig field the caller supplies at creation time instead of the provider defaults.

const (
	CallerFieldAudience        CallerField = "audience"
	CallerFieldExpectedEmail   CallerField = "expected_email"
	CallerFieldExpectedSubject CallerField = "expected_subject"
	CallerFieldTopicARN        CallerField = "topic_arn"
)

type Defaults

type Defaults struct {
	Auth         AuthType
	Envelope     EnvelopeType
	AuthConfig   AuthConfig
	TypeFrom     envelope.FieldSelector
	IDFrom       envelope.FieldSelector
	CallerFields []CallerField
	// NativeProtocol marks providers that speak their own webhook protocol:
	// the envelope decoder is fixed and field selectors do not apply.
	NativeProtocol bool
	// CallerSecret marks providers whose signing secret is issued by the
	// external provider and supplied by the caller at creation time. Such
	// secrets are write-only: they cannot be revealed, rotated, or revoked
	// independently of the trigger.
	CallerSecret bool
}

Defaults is the declarative creation-time configuration a provider preset applies to a trigger.

type EnvelopeType

type EnvelopeType string
const (
	EnvelopeNone        EnvelopeType = "none"
	EnvelopePubSubPush  EnvelopeType = "pubsub_push"
	EnvelopeCloudEvents EnvelopeType = "cloudevents"
	EnvelopeSNS         EnvelopeType = "sns"
)

type Handshake

type Handshake struct {
	Status int
	Body   map[string]string
}

Handshake is a provider protocol response that ends request processing without persisting an event, such as Slack URL verification or Azure Event Grid subscription validation.

type Provider

type Provider interface {
	Name() string
	Defaults() Defaults
	// Decoder returns the envelope decoder for the trigger's configured
	// envelope type. Native-protocol providers ignore the envelope type.
	Decoder(envelopeType EnvelopeType) (envelope.Decoder, error)
	// Verifier returns the shared-secret verifier for the trigger's auth
	// mechanism, or nil for mechanisms that do not verify against managed
	// secrets (none, bearer_jwt, sns_signature).
	Verifier(auth AuthType, cfg AuthConfig) signature.Verifier
	// Handshake inspects a decoded event and returns a non-nil response when
	// the request is a protocol handshake rather than an event delivery.
	Handshake(event *envelope.Event) (*Handshake, error)
	// RejectStatus returns the HTTP status for an envelope decode failure.
	// http.StatusAccepted means record the rejection and acknowledge the
	// delivery; other statuses surface the error to the sender.
	RejectStatus(err error) int
}

Provider implements one inbound event source. All methods are complete on Base; providers embed Base and override only protocol-specific behavior.

Jump to

Keyboard shortcuts

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