webhook

package
v2.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: BSD-3-Clause Imports: 33 Imported by: 0

Documentation

Overview

Package webhook owns inbound webhook targets: the tokens that authenticate them, the actions they trigger, and the HTTP surface that manages them.

Index

Constants

View Source
const (
	WebhookTargetTypeContainer = "container"
	WebhookTargetTypeProject   = "project"
	WebhookTargetTypeUpdater   = "updater"
	WebhookTargetTypeGitOps    = "gitops"

	WebhookActionTypeUpdate   = "update"
	WebhookActionTypeStart    = "start"
	WebhookActionTypeStop     = "stop"
	WebhookActionTypeRestart  = "restart"
	WebhookActionTypeRedeploy = "redeploy"
	WebhookActionTypeUp       = "up"
	WebhookActionTypeDown     = "down"
	WebhookActionTypeRun      = "run"
	WebhookActionTypeSync     = "sync"
)
View Source
const (
	ErrWebhookNotFound      = errors.Sentinel("webhook not found")
	ErrWebhookInvalid       = errors.Sentinel("invalid webhook token")
	ErrWebhookDisabled      = errors.Sentinel("webhook is disabled")
	ErrWebhookInvalidType   = errors.Sentinel("invalid webhook target type")
	ErrWebhookInvalidAction = errors.Sentinel("invalid webhook action type")
	ErrWebhookMissingTarget = errors.Sentinel("target ID is required for container, project, and gitops webhook types")
)

Variables

This section is empty.

Functions

func RegisterWebhooks

func RegisterWebhooks(api huma.API, webhookService *WebhookService)

RegisterWebhooks registers the authenticated CRUD routes for webhook management.

Types

type CreateWebhookInput

type CreateWebhookInput struct {
	EnvironmentID string               `path:"id" doc:"Environment ID"`
	Body          *webhook.CreateInput `required:"true"`
}

type CreateWebhookOutput

type CreateWebhookOutput struct {
	Body base.ApiResponse[webhook.Created]
}

type DeleteWebhookInput

type DeleteWebhookInput struct {
	EnvironmentID string `path:"id" doc:"Environment ID"`
	WebhookID     string `path:"webhookId" doc:"Webhook ID"`
}

type DeleteWebhookOutput

type DeleteWebhookOutput struct {
	Body base.ApiResponse[any]
}

type Dependencies

type Dependencies struct {
	DB          *database.DB
	Container   *container.ContainerService
	Updater     *updater.UpdaterService
	Project     *project.ProjectService
	GitOpsSync  *gitops.GitOpsSyncService
	Event       *event.EventService
	Environment *environment.EnvironmentService
}

Dependencies are the collaborators the webhook domain needs.

type ListWebhooksInput

type ListWebhooksInput struct {
	EnvironmentID string `path:"id" doc:"Environment ID"`
}

type ListWebhooksOutput

type ListWebhooksOutput struct {
	Body base.ApiResponse[[]webhook.Summary]
}

type Module

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

Module wires the webhook domain and mounts its routes.

func New

func New(deps Dependencies) *Module

New builds the webhook domain from its dependencies.

func (*Module) RegisterRoutes

func (m *Module) RegisterRoutes(api huma.API)

RegisterRoutes mounts the webhook endpoints. A nil module still registers, so OpenAPI spec generation can discover the routes without a service graph.

func (*Module) Service

func (m *Module) Service() *WebhookService

Service exposes the webhook service to collaborators that trigger webhooks outside the HTTP surface.

type UpdateWebhookInput

type UpdateWebhookInput struct {
	EnvironmentID string               `path:"id" doc:"Environment ID"`
	WebhookID     string               `path:"webhookId" doc:"Webhook ID"`
	Body          *webhook.UpdateInput `required:"true"`
}

type UpdateWebhookOutput

type UpdateWebhookOutput struct {
	Body base.ApiResponse[any]
}

type Webhook added in v2.8.1

type Webhook struct {
	database.BaseModel

	Name            string     `json:"name" gorm:"column:name;not null"`
	TokenHash       string     `json:"-" gorm:"column:token_hash;not null;uniqueIndex"`
	TokenPrefix     string     `json:"tokenPrefix" gorm:"column:token_prefix;not null"`
	TargetType      string     `json:"targetType" gorm:"column:target_type;not null"`
	ActionType      string     `json:"actionType" gorm:"column:action_type;not null;default:''"`
	TargetID        string     `json:"targetId" gorm:"column:target_id;not null"`
	TargetRef       string     `json:"-" gorm:"column:target_ref;not null;default:''"`
	EnvironmentID   string     `json:"environmentId" gorm:"column:environment_id;not null;default:''"`
	Enabled         bool       `json:"enabled" gorm:"column:enabled;not null;default:true"`
	LastTriggeredAt *time.Time `json:"lastTriggeredAt,omitempty" gorm:"column:last_triggered_at"`
}

func (Webhook) TableName added in v2.8.1

func (Webhook) TableName() string

type WebhookHandler

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

func (*WebhookHandler) CreateWebhook

func (h *WebhookHandler) CreateWebhook(ctx context.Context, input *CreateWebhookInput) (*CreateWebhookOutput, error)

CreateWebhook creates a new webhook and returns the raw token (shown once only).

func (*WebhookHandler) DeleteWebhook

func (h *WebhookHandler) DeleteWebhook(ctx context.Context, input *DeleteWebhookInput) (*DeleteWebhookOutput, error)

DeleteWebhook removes a webhook.

func (*WebhookHandler) ListWebhooks

func (h *WebhookHandler) ListWebhooks(ctx context.Context, input *ListWebhooksInput) (*ListWebhooksOutput, error)

ListWebhooks returns all webhooks for an environment (tokens are masked).

func (*WebhookHandler) UpdateWebhook

func (h *WebhookHandler) UpdateWebhook(ctx context.Context, input *UpdateWebhookInput) (*UpdateWebhookOutput, error)

UpdateWebhook updates a webhook's enabled state.

type WebhookService

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

func NewWebhookService

func NewWebhookService(db *database.DB, containerService *container.ContainerService, updaterService *updater.UpdaterService, projectService *project.ProjectService, gitOpsSyncService *gitops.GitOpsSyncService, eventService *event.EventService, environmentService *environment.EnvironmentService) *WebhookService

func (*WebhookService) CreateWebhook

func (s *WebhookService) CreateWebhook(ctx context.Context, name, targetType, actionType, targetID, environmentID string, actor common.User) (*Webhook, string, error)

CreateWebhook creates a new webhook targeting a stack, the environment-wide updater, or a gitops sync. It returns the webhook record with the raw token populated (only available at creation time).

func (*WebhookService) DeleteWebhook

func (s *WebhookService) DeleteWebhook(ctx context.Context, id, environmentID string, actor common.User) error

DeleteWebhook removes a webhook by ID, scoped to an environment.

func (*WebhookService) DrainActions

func (s *WebhookService) DrainActions(ctx context.Context) error

DrainActions blocks until all accepted background webhook actions finish or ctx expires, so shutdown does not silently drop acknowledged work.

func (*WebhookService) GetWebhookByID

func (s *WebhookService) GetWebhookByID(ctx context.Context, id, environmentID string) (*Webhook, error)

GetWebhookByID returns a single webhook by ID, scoped to an environment.

func (*WebhookService) ListWebhookSummaries

func (s *WebhookService) ListWebhookSummaries(ctx context.Context, environmentID string) ([]webhooktypes.Summary, error)

func (*WebhookService) ListWebhooks

func (s *WebhookService) ListWebhooks(ctx context.Context, environmentID string) ([]Webhook, error)

ListWebhooks returns all webhooks for an environment.

func (*WebhookService) TriggerByToken

func (s *WebhookService) TriggerByToken(ctx context.Context, rawToken string) error

TriggerByToken looks up a webhook by its raw token, validates it, and starts the configured action in the background so the HTTP caller gets an immediate acknowledgement instead of holding the connection for the full action duration (#3469). The action outcome is recorded in the event log.

func (*WebhookService) UpdateWebhook

func (s *WebhookService) UpdateWebhook(ctx context.Context, id, environmentID string, enabled bool, actor common.User) (*Webhook, error)

UpdateWebhook updates the enabled state of a webhook, scoped to an environment.

Jump to

Keyboard shortcuts

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