Documentation
¶
Overview ¶
Package webhook implements project- and organization-scoped webhook activation and delivery.
Index ¶
- Constants
- Variables
- func NewHTTPClient(allowPrivate bool, resolver Resolver, configuredDialer Dialer) *http.Client
- func RefusedAddress(address netip.Addr) bool
- func SetHeaders(request *http.Request, secret, operation, eventID string, body []byte)
- func Signature(secret string, body []byte) string
- func Subscribed(events []string, operation string) bool
- type Actor
- type Create
- type Delivery
- type Dialer
- type DispatchRepository
- type Dispatcher
- type Envelope
- type OutboxEvent
- type Project
- type Record
- type Repository
- type Resolver
- type Service
- func (s *Service) Create(ctx context.Context, organizationID, projectID string, write Create) (*Record, error)
- func (s *Service) Delete(ctx context.Context, organizationID, projectID, webhookID string) error
- func (s *Service) Deliveries(ctx context.Context, organizationID, projectID, webhookID string) ([]Delivery, error)
- func (s *Service) Get(ctx context.Context, organizationID, projectID, webhookID string) (*Record, error)
- func (s *Service) List(ctx context.Context, organizationID, projectID string) ([]Record, error)
- func (s *Service) Update(ctx context.Context, organizationID, projectID, webhookID string, write Update) (*Record, error)
- func (s *Service) Verify(ctx context.Context, organizationID, projectID, webhookID string) (*Record, error)
- type Target
- type Update
Constants ¶
View Source
const ( OperationVersionCreated = "version.created" OperationVersionCompleted = "version.completed" OperationVersionRevoked = "version.revoked" OperationVersionRevocationScheduled = "version.revocation_scheduled" OperationVersionRestored = "version.restored" OperationVersionDeleted = "version.deleted" OperationChannelCreated = "channel.created" OperationChannelDeleted = "channel.deleted" OperationChannelAssigned = "channel.assigned" OperationBucketCreated = "bucket.created" OperationBucketDeleted = "bucket.deleted" OperationVerification = "webhook.verification" OperationPluginUpdateAvailable = "plugin.update_available" StatePending = "pending" StateActive = "active" DeliveryPending = "pending" DeliveryRetrying = "retrying" DeliveryDelivered = "delivered" DeliveryFailed = "failed" DeliveryRefused = "refused" MaxAttempts = 5 )
View Source
const ( SignatureHeader = "X-Dufflebag-Signature" EventHeader = "X-Dufflebag-Event" DeliveryHeader = "X-Dufflebag-Delivery" )
Variables ¶
View Source
var ( ErrNotFound = errors.New("webhook not found") ErrInvalid = errors.New("invalid webhook") )
View Source
var ErrPrivateAddress = errors.New("webhook target resolves to a private or local address")
View Source
var Operations = []string{ OperationVersionCreated, OperationVersionCompleted, OperationVersionRevoked, OperationVersionRevocationScheduled, OperationVersionRestored, OperationVersionDeleted, OperationChannelCreated, OperationChannelDeleted, OperationChannelAssigned, OperationBucketCreated, OperationBucketDeleted, }
View Source
var OrganizationOperations = []string{OperationPluginUpdateAvailable}
OrganizationOperations are the events an organization webhook can receive.
Functions ¶
func NewHTTPClient ¶
func RefusedAddress ¶
func SetHeaders ¶
func Subscribed ¶
Types ¶
type DispatchRepository ¶
type DispatchRepository interface {
ListWebhookProjects(context.Context) ([]Project, error)
GetNextWebhookOutboxEvent(context.Context, Project, time.Time) (*OutboxEvent, error)
ListWebhookEventDeliveries(context.Context, Project, string) ([]Delivery, error)
GetWebhook(context.Context, string, string, string) (*Record, error)
RecordWebhookDeliveryAttempt(context.Context, Delivery) error
ScheduleWebhookOutboxEvent(context.Context, Project, string, time.Time) error
DeleteWebhookOutboxEvent(context.Context, Project, string) error
}
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func NewDispatcher ¶
func (*Dispatcher) DispatchAll ¶
func (d *Dispatcher) DispatchAll(ctx context.Context) error
func (*Dispatcher) DispatchProject ¶
func (d *Dispatcher) DispatchProject(ctx context.Context, project Project) error
func (*Dispatcher) Run ¶
func (d *Dispatcher) Run(ctx context.Context)
func (*Dispatcher) Started ¶
func (d *Dispatcher) Started() <-chan struct{}
type Envelope ¶
type Envelope struct {
EventID string `json:"event_id"`
OccurredAt time.Time `json:"occurred_at"`
OrganizationID string `json:"organization_id"`
ProjectID string `json:"project_id,omitempty"`
Operation string `json:"operation"`
Target Target `json:"target"`
Actor Actor `json:"actor"`
Payload json.RawMessage `json:"payload"`
}
type OutboxEvent ¶
type Repository ¶
type Repository interface {
CreateWebhook(context.Context, Record) (*Record, error)
GetWebhook(context.Context, string, string, string) (*Record, error)
ListWebhooks(context.Context, string, string) ([]Record, error)
UpdateWebhook(context.Context, Record) (*Record, error)
DeleteWebhook(context.Context, string, string, string) error
RecordWebhookVerification(context.Context, Record, string, string, *int, *string, time.Time) (*Record, error)
ListWebhookDeliveries(context.Context, string, string, string) ([]Delivery, error)
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) Deliveries ¶
Click to show internal directories.
Click to hide internal directories.