webhook

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSecretID    = "1"
	SignatureHeader    = "X-Signature"
	EndpointRetryCount = 3
)

Variables

View Source
var (
	ErrNotFound      = errors.New("webhook doesn't exist")
	ErrInvalidDetail = errors.New("invalid webhook details")
	ErrConflict      = errors.New("webhook already exist")
	ErrInvalidUUID   = errors.New("invalid syntax of uuid")
	ErrDisabled      = errors.New("webhook is disabled")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	EncryptionKey string `yaml:"encryption_key" mapstructure:"encryption_key" default:"hash-secret-should-be-32-chars--"`
}

type Endpoint

type Endpoint struct {
	ID string
	// Description is the description of the webhook
	Description string
	// URL is the URL of the webhook
	URL string
	// SubscribedEvents is the list of events that the webhook is subscribed to
	SubscribedEvents []string
	// Headers is the headers to be sent with the webhook
	Headers map[string]string
	// Secrets is the list of secrets to sign the payload
	Secrets []Secret
	// State is the state of the webhook
	State State

	// Metadata is the metadata of the webhook
	Metadata metadata.Metadata
	// CreatedAt is the creation time of the webhook
	CreatedAt time.Time
	// UpdatedAt is the update time of the webhook
	UpdatedAt time.Time
}

type EndpointFilter

type EndpointFilter struct {
	State State
}

type EndpointRepository

type EndpointRepository interface {
	Create(ctx context.Context, endpoint Endpoint) (Endpoint, error)
	UpdateByID(ctx context.Context, endpoint Endpoint) (Endpoint, error)
	Delete(ctx context.Context, id string) error
	List(ctx context.Context, filter EndpointFilter) ([]Endpoint, error)
}

type Event

type Event struct {
	ID        string
	Action    string
	Data      metadata.Metadata
	CreatedAt time.Time
}

type Secret

type Secret struct {
	ID string
	// Value store the secret value in hex
	Value string
}

type Service

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

func NewService

func NewService(eRepo EndpointRepository) *Service

func (Service) CreateEndpoint

func (s Service) CreateEndpoint(ctx context.Context, endpoint Endpoint) (Endpoint, error)

func (Service) DeleteEndpoint

func (s Service) DeleteEndpoint(ctx context.Context, id string) error

func (Service) ListEndpoints

func (s Service) ListEndpoints(ctx context.Context, filter EndpointFilter) ([]Endpoint, error)

func (Service) Publish

func (s Service) Publish(ctx context.Context, evt Event) error

func (Service) UpdateEndpoint

func (s Service) UpdateEndpoint(ctx context.Context, endpoint Endpoint) (Endpoint, error)

type State

type State string
const (
	Enabled  State = "enabled"
	Disabled State = "disabled"
)

Jump to

Keyboard shortcuts

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