destwebhook

package
v0.6.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultEncoding  = "hex"
	DefaultAlgorithm = "hmac-sha256"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Base64Encoder

type Base64Encoder struct{}

func (Base64Encoder) Encode

func (e Base64Encoder) Encode(b []byte) string

type HeaderFormatter

type HeaderFormatter interface {
	Format(content HeaderPayload) string
}

type HeaderFormatterImpl

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

func NewHeaderFormatter

func NewHeaderFormatter(templateStr string) *HeaderFormatterImpl

func (*HeaderFormatterImpl) Format

func (f *HeaderFormatterImpl) Format(content HeaderPayload) string

type HeaderPayload

type HeaderPayload struct {
	EventID    string
	Topic      string
	Timestamp  time.Time
	Signatures []string
}

type HexEncoder

type HexEncoder struct{}

func (HexEncoder) Encode

func (e HexEncoder) Encode(b []byte) string

type HmacAlgo

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

func NewHmacMD5

func NewHmacMD5() *HmacAlgo

func NewHmacSHA1

func NewHmacSHA1() *HmacAlgo

func NewHmacSHA256

func NewHmacSHA256() *HmacAlgo

func (*HmacAlgo) Name

func (h *HmacAlgo) Name() string

func (*HmacAlgo) Sign

func (h *HmacAlgo) Sign(key string, content string, encoder SignatureEncoder) string

func (*HmacAlgo) Verify

func (h *HmacAlgo) Verify(key string, content string, signature string, encoder SignatureEncoder) bool

type Option

type Option func(*WebhookDestination)

Option is a functional option for configuring WebhookDestination

func WithDisableDefaultEventIDHeader

func WithDisableDefaultEventIDHeader(disable bool) Option

Add these options after the existing Option definitions

func WithDisableDefaultSignatureHeader

func WithDisableDefaultSignatureHeader(disable bool) Option

func WithDisableDefaultTimestampHeader

func WithDisableDefaultTimestampHeader(disable bool) Option

func WithDisableDefaultTopicHeader

func WithDisableDefaultTopicHeader(disable bool) Option

func WithHeaderPrefix

func WithHeaderPrefix(prefix string) Option

WithHeaderPrefix sets a custom prefix for webhook request headers

func WithSignatureAlgorithm

func WithSignatureAlgorithm(algorithm string) Option

func WithSignatureContentTemplate

func WithSignatureContentTemplate(template string) Option

func WithSignatureEncoding

func WithSignatureEncoding(encoding string) Option

func WithSignatureHeaderTemplate

func WithSignatureHeaderTemplate(template string) Option

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent sets the user agent for the webhook request

type SignatureEncoder

type SignatureEncoder interface {
	Encode([]byte) string
}

func GetEncoder

func GetEncoder(encoding string) SignatureEncoder

GetEncoder returns the appropriate SignatureEncoder for the given encoding

type SignatureFormatter

type SignatureFormatter interface {
	Format(content SignaturePayload) string
}

type SignatureFormatterImpl

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

func NewSignatureFormatter

func NewSignatureFormatter(templateStr string) *SignatureFormatterImpl

func (*SignatureFormatterImpl) Format

func (f *SignatureFormatterImpl) Format(content SignaturePayload) string

type SignatureManager

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

func NewSignatureManager

func NewSignatureManager(secrets []WebhookSecret, opts ...SignatureManagerOption) *SignatureManager

func (*SignatureManager) GenerateSignatureHeader

func (sm *SignatureManager) GenerateSignatureHeader(content SignaturePayload) string

func (*SignatureManager) GenerateSignatures

func (sm *SignatureManager) GenerateSignatures(content SignaturePayload) []string

func (*SignatureManager) VerifySignature

func (sm *SignatureManager) VerifySignature(signature, key string, content SignaturePayload) bool

type SignatureManagerOption

type SignatureManagerOption func(*SignatureManager)

func WithEncoder

func WithEncoder(encoder SignatureEncoder) SignatureManagerOption

func WithHeaderFormatter

func WithHeaderFormatter(formatter HeaderFormatter) SignatureManagerOption

func WithSignatureFormatter

func WithSignatureFormatter(formatter SignatureFormatter) SignatureManagerOption

type SignaturePayload

type SignaturePayload struct {
	EventID   string
	Topic     string
	Timestamp time.Time
	Body      string
}

type SigningAlgorithm

type SigningAlgorithm interface {
	Sign(key string, content string, encoder SignatureEncoder) string
	Verify(key string, content string, signature string, encoder SignatureEncoder) bool
	Name() string
}

func GetAlgorithm

func GetAlgorithm(algorithm string) SigningAlgorithm

GetAlgorithm returns the appropriate SigningAlgorithm for the given algorithm name

type WebhookDestination

type WebhookDestination struct {
	*destregistry.BaseProvider
	// contains filtered or unexported fields
}

func New

func New(loader metadata.MetadataLoader, basePublisherOpts []destregistry.BasePublisherOption, opts ...Option) (*WebhookDestination, error)

func (*WebhookDestination) ComputeTarget

func (d *WebhookDestination) ComputeTarget(destination *models.Destination) destregistry.DestinationTarget

func (*WebhookDestination) CreatePublisher

func (d *WebhookDestination) CreatePublisher(ctx context.Context, destination *models.Destination) (destregistry.Publisher, error)

func (*WebhookDestination) GetSignatureAlgorithm

func (d *WebhookDestination) GetSignatureAlgorithm() string

func (*WebhookDestination) GetSignatureEncoding

func (d *WebhookDestination) GetSignatureEncoding() string

func (*WebhookDestination) ObfuscateDestination

func (d *WebhookDestination) ObfuscateDestination(destination *models.Destination) *models.Destination

ObfuscateDestination overrides the base implementation to handle webhook secrets

func (*WebhookDestination) Preprocess

func (d *WebhookDestination) Preprocess(newDestination *models.Destination, originalDestination *models.Destination, opts *destregistry.PreprocessDestinationOpts) error

Preprocess sets a default secret if one isn't provided and handles secret rotation

func (*WebhookDestination) Validate

func (d *WebhookDestination) Validate(ctx context.Context, destination *models.Destination) error

type WebhookDestinationConfig

type WebhookDestinationConfig struct {
	URL string
}

type WebhookDestinationCredentials

type WebhookDestinationCredentials struct {
	Secret                  string    `json:"secret"`
	PreviousSecret          string    `json:"previous_secret,omitempty"`
	PreviousSecretInvalidAt time.Time `json:"previous_secret_invalid_at,omitempty"`
}

type WebhookPublisher

type WebhookPublisher struct {
	*destregistry.BasePublisher
	// contains filtered or unexported fields
}

func (*WebhookPublisher) Close

func (p *WebhookPublisher) Close() error

func (*WebhookPublisher) Format

func (p *WebhookPublisher) Format(ctx context.Context, event *models.Event) (*http.Request, error)

Format is a helper function to format the event data into an HTTP request.

func (*WebhookPublisher) Publish

func (p *WebhookPublisher) Publish(ctx context.Context, event *models.Event) (*destregistry.Delivery, error)

type WebhookSecret

type WebhookSecret struct {
	Key       string     `json:"key"`
	CreatedAt time.Time  `json:"created_at"`
	InvalidAt *time.Time `json:"invalid_at,omitempty"`
}

Jump to

Keyboard shortcuts

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