package database import "time" // TargetType represents the type of delivery target type TargetType string // Target type values. const ( TargetTypeHTTP TargetType = "http" TargetTypeDatabase TargetType = "database" TargetTypeLog TargetType = "log" TargetTypeSlack TargetType = "slack" ) // Target represents a delivery target for a webhook. Its settings // are the fields from URL to ArchiveRotation; each type uses some of // them, and the ones a type does not use stay empty. type Target struct { BaseModel WebhookID string `gorm:"type:uuid;not null" json:"webhookId"` Name string `gorm:"not null" json:"name"` Type TargetType `gorm:"not null" json:"type"` Active bool `gorm:"default:true" json:"active"` // URL is where an http or slack target sends each event. // // json:"-" because the URL is the target's credential: a Slack // incoming-webhook URL, or an http destination whose path segments // are the secret. delivery.TargetView is the masking barrier for // the HTML path; this tag is the barrier for any handler that // marshals the model itself. URL string `json:"-"` // Headers is an http target's extra request headers, name to // value, stored as JSON text. json:"-" for the same reason as URL: // a header value is routinely an authorization token. Headers map[string]string `gorm:"serializer:json" json:"-"` // TimeoutSeconds is an http target's per-request timeout; 0 uses // the delivery engine's shared client timeout. TimeoutSeconds int `json:"timeoutSeconds,omitempty"` // ForwardQuery passes each event's query string on to an http // target, appended to URL. Off, URL is sent exactly as stored. ForwardQuery bool `json:"forwardQuery,omitempty"` // ArchiveExpiry is how long a database target keeps each archived // event; 0 keeps them forever. ArchiveExpiry time.Duration `json:"archiveExpiry,omitempty"` // ArchiveRotation is how often a database target starts a new // archive file: none, monthly, daily or hourly. ArchiveRotation string `json:"archiveRotation,omitempty"` // MaxAttempts is how many times an HTTP or Slack target attempts // each delivery in all, at least 1. 1 is a single attempt with no // circuit breaker; above 1, a failed attempt is retried with // backoff behind the breaker. The table's check constraint refuses // a target saved with less than 1, whatever its type. MaxAttempts int `gorm:"not null;check:max_attempts >= 1" json:"maxAttempts,omitempty"` // Relations. No model marshals the record it belongs to: // Webhook.Targets leads back here, and the JSON could loop. Webhook Webhook `json:"-"` Deliveries []Delivery `json:"deliveries,omitempty"` }