rdev/internal/port/webhook.go
jordan 72d16929ca feat: Implement hexagonal architecture with services, webhooks, queue, and telemetry
Major refactoring to hexagonal (ports & adapters) architecture:

- Add service layer (apikey_service, project_service) for business logic
- Add webhook system with dispatcher and delivery tracking
- Add command queue with priority-based processing
- Add rate limiting with sliding window algorithm
- Add audit logging for command execution
- Add OpenTelemetry integration (traces, metrics, spans)
- Add circuit breaker for fault tolerance
- Add cached repository wrapper for performance
- Add comprehensive validation package
- Add Kubernetes client integration for pod management
- Add database migrations (allowed_ips, audit_log, rate_limiting, queue, webhooks)
- Add network policy and PodDisruptionBudget for k8s
- Remove legacy executor and projects/registry packages
- Untrack secrets.yaml (now managed via envault)
- Add coverage.out to .gitignore
- Add e2e test infrastructure with docker-compose
- Add comprehensive documentation (API, architecture, operations, plans)
- Add golangci-lint config and pre-commit hook

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 19:57:46 -07:00

51 lines
1.9 KiB
Go

package port
import (
"context"
"github.com/orchard9/rdev/internal/domain"
)
// WebhookRepository defines operations for webhook storage.
type WebhookRepository interface {
// Create creates a new webhook subscription.
Create(ctx context.Context, webhook *domain.Webhook) error
// Update updates an existing webhook.
Update(ctx context.Context, webhook *domain.Webhook) error
// Delete deletes a webhook by ID.
Delete(ctx context.Context, id domain.WebhookID) error
// GetByID retrieves a webhook by ID.
GetByID(ctx context.Context, id domain.WebhookID) (*domain.Webhook, error)
// ListByProject returns all webhooks for a project.
ListByProject(ctx context.Context, projectID string) ([]*domain.Webhook, error)
// ListEnabledByProjectAndEvent returns enabled webhooks that subscribe to a specific event type.
ListEnabledByProjectAndEvent(ctx context.Context, projectID string, eventType domain.WebhookEventType) ([]*domain.Webhook, error)
// RecordDelivery records a webhook delivery attempt.
RecordDelivery(ctx context.Context, delivery *domain.WebhookDelivery) error
// GetDeliveries returns delivery history for a webhook.
GetDeliveries(ctx context.Context, webhookID domain.WebhookID, filters *domain.WebhookDeliveryFilters) ([]*domain.WebhookDelivery, error)
// CleanupOldDeliveries removes delivery records older than the specified number of days.
CleanupOldDeliveries(ctx context.Context, olderThanDays int) (int64, error)
}
// WebhookDispatcher defines operations for dispatching webhook events.
type WebhookDispatcher interface {
// Dispatch sends an event to all subscribed webhooks for a project.
// This is a non-blocking operation - deliveries happen in the background.
Dispatch(ctx context.Context, projectID string, event *domain.WebhookEvent) error
// Start starts the background dispatcher workers.
Start() error
// Stop gracefully shuts down the dispatcher.
Stop()
}