Documentation
¶
Index ¶
- Constants
- func ArtifactPayload(eventType string, a Artifact) map[string]any
- func BundleCheckUpdatedPayload(c BundleCheckUpdate) map[string]any
- func BundlePromotedPayload(b BundlePromotion) map[string]any
- func Emit(ctx context.Context, p Publisher, repoID, eventType string, ...)
- func IsPayloadFormat(name string) bool
- func IsSubscribableEvent(name string) bool
- func PayloadFormats() []string
- func QuarantineChangedPayload(q QuarantineChange) map[string]any
- func RepositoryPayload(eventType, name, format, repoType string) map[string]any
- func ScanPayload(event string, s ScanCompleted) map[string]any
- func SubscribableEvents() []string
- func VulnerabilityNewPayload(v VulnerabilityDetected) map[string]any
- type Artifact
- type BundleCheckUpdate
- type BundlePromotion
- type Dispatcher
- func (d *Dispatcher) DeferDeliveries()
- func (d *Dispatcher) Dispatch(ctx context.Context, repoID, eventType string, payload map[string]any)
- func (d *Dispatcher) DispatchTo(ctx context.Context, wh *models.Webhook, eventType string, ...) error
- func (d *Dispatcher) SetBaseURL(baseURL string)
- func (d *Dispatcher) Start()
- func (d *Dispatcher) Stop()
- func (d *Dispatcher) WithPollInterval(interval time.Duration)
- type DispatcherStore
- type Publisher
- type QuarantineChange
- type ScanCompleted
- type ScanKind
- type VulnerabilityDetected
- type VulnerabilityFinding
Constants ¶
const ( EventArtifactUploaded = "artifact.uploaded" EventArtifactDeleted = "artifact.deleted" EventRepoCreated = "repository.created" EventRepoDeleted = "repository.deleted" // EventArtifactRestored and EventRepoRestored fire when an item leaves the // trash; EventArtifactPurged and EventRepoPurged when it is removed for // good (by an admin or the retention purge). The deleted events fire for // every delete, soft or hard. EventArtifactRestored = "artifact.restored" EventArtifactPurged = "artifact.purged" EventRepoRestored = "repository.restored" EventRepoPurged = "repository.purged" // EventBundlePromoted fires once a release bundle has been copied into the // target repository of a pipeline stage. It is delivered to the webhooks of // the target repository and the global ones. EventBundlePromoted = "bundle.promoted" // EventVulnerabilityNew fires when the OSV mirror's re-match finds a // stored package version affected by an advisory it was not known to be // affected by. It is delivered to the webhooks of the repository holding // the version and the global ones. EventVulnerabilityNew = "vulnerability.new" // EventScanCompleted fires when a vulnerability, license or secret scan of // an artifact reaches a final status. It is delivered to the webhooks of // the scanned repository and the global ones. EventScanCompleted = "scan.completed" // EventVulnerabilityFound fires when a vulnerability scan that completed // (or completed partially) found at least one advisory. Unlike // vulnerability.new, which reports advisories a re-match newly attributes // to a stored version, it reports the findings of one scan. EventVulnerabilityFound = "vulnerability.found" // EventQuarantineChanged fires when an artifact is quarantined or released // from quarantine, by a person or by a blocking license policy. EventQuarantineChanged = "quarantine.changed" // EventBundleCheckUpdated fires when an external check is reported against // a release bundle. It is delivered to the webhooks of the bundle's first // source repository and the global ones. EventBundleCheckUpdated = "bundle.check_updated" )
Event types.
const ( // DefaultTimeoutSeconds is the per-delivery timeout of a new webhook. DefaultTimeoutSeconds = 30 // MaxTimeoutSeconds is the largest accepted per-delivery timeout (the // dispatcher's HTTP clients enforce the same 30s ceiling). MaxTimeoutSeconds = 30 )
const ( // DefaultPollInterval is how often the retry loop claims due deliveries. DefaultPollInterval = 30 * time.Second )
const EventWebhookTest = "webhook.test"
EventWebhookTest is only ever sent directly to one webhook (see DispatchTo); it cannot be subscribed to.
Variables ¶
This section is empty.
Functions ¶
func ArtifactPayload ¶ added in v0.2.0
ArtifactPayload builds the JSON payload of an artifact.* event.
func BundleCheckUpdatedPayload ¶ added in v0.21.0
func BundleCheckUpdatedPayload(c BundleCheckUpdate) map[string]any
BundleCheckUpdatedPayload builds the JSON payload of a bundle.check_updated event.
func BundlePromotedPayload ¶ added in v0.8.0
func BundlePromotedPayload(b BundlePromotion) map[string]any
BundlePromotedPayload builds the JSON payload of a bundle.promoted event.
func Emit ¶ added in v0.2.0
Emit publishes an event through p, if any. The event is detached from the request's cancellation (a client hanging up right after a successful upload must not lose the event) but bounded by emitTimeout. Failures are logged by the dispatcher and never surface to the caller: an event that cannot be recorded must not fail the operation that produced it.
func IsPayloadFormat ¶ added in v0.7.0
IsPayloadFormat reports whether name is an accepted payload_format.
func IsSubscribableEvent ¶ added in v0.2.0
IsSubscribableEvent reports whether name is an event webhooks can subscribe to.
func PayloadFormats ¶ added in v0.7.0
func PayloadFormats() []string
PayloadFormats returns the accepted payload_format values.
func QuarantineChangedPayload ¶ added in v0.21.0
func QuarantineChangedPayload(q QuarantineChange) map[string]any
QuarantineChangedPayload builds the JSON payload of a quarantine.changed event.
func RepositoryPayload ¶ added in v0.2.0
RepositoryPayload builds the JSON payload of a repository.* event.
func ScanPayload ¶ added in v0.21.0
func ScanPayload(event string, s ScanCompleted) map[string]any
ScanPayload builds the JSON payload of a scan.completed or vulnerability.found event (event names which).
func SubscribableEvents ¶ added in v0.2.0
func SubscribableEvents() []string
SubscribableEvents returns the event names a webhook may subscribe to.
func VulnerabilityNewPayload ¶ added in v0.14.0
func VulnerabilityNewPayload(v VulnerabilityDetected) map[string]any
VulnerabilityNewPayload builds the JSON payload of a vulnerability.new event. The "source" is always "osv-mirror": the findings come from the local OSV mirror (OSV data, CC-BY 4.0, https://osv.dev).
Types ¶
type Artifact ¶ added in v0.2.0
type Artifact struct {
Repository string // repository name
Format string // repository format (deb, npm, ...)
Name string // package / artifact name
Version string // version, when the format has one
Path string // path or file name within the repository
SHA256 string // content digest, when known
Size int64 // size in bytes, when known
}
Artifact describes the artifact an artifact.* event is about.
type BundleCheckUpdate ¶ added in v0.21.0
type BundleCheckUpdate struct {
Repository string // first source repository of the bundle; empty when it has no items
Format string
Bundle string
Version string
Check string
Status string
Summary string
DetailsURL string
ReportedBy string
ExpiresAt *time.Time
}
BundleCheckUpdate describes a check result reported against a release bundle.
type BundlePromotion ¶ added in v0.8.0
type BundlePromotion struct {
Repository string // target repository name
Format string // target repository format
Bundle string // bundle name
Version string // bundle version
FromStage string // stage the bundle left ("" when it had none)
ToStage string // stage the bundle reached
Items int // bundle items promoted
Copied int // artifacts newly written to the target
Existing int // artifacts the target already held with the same content
Replaced int // artifacts a forced promotion moved to the target's trash
}
BundlePromotion describes a completed release bundle promotion.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func NewDispatcher ¶
func NewDispatcher(db DispatcherStore, log *logger.Logger) *Dispatcher
func (*Dispatcher) DeferDeliveries ¶ added in v0.15.0
func (d *Dispatcher) DeferDeliveries()
DeferDeliveries makes Dispatch and DispatchTo only record the deliveries: they are inserted pending and due, and a process that runs the dispatcher claims and delivers them (server.role=web). Call it before the first Dispatch.
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(ctx context.Context, repoID, eventType string, payload map[string]any)
Dispatch queues a webhook event for all matching webhooks. repoID can be empty for global events.
func (*Dispatcher) DispatchTo ¶ added in v0.2.0
func (d *Dispatcher) DispatchTo(ctx context.Context, wh *models.Webhook, eventType string, payload map[string]any) error
DispatchTo creates a delivery for exactly one webhook and queues it, regardless of the webhook's event subscriptions or enabled flag.
func (*Dispatcher) SetBaseURL ¶ added in v0.7.0
func (d *Dispatcher) SetBaseURL(baseURL string)
SetBaseURL sets the server's external base URL, used as the CloudEvents source of cloudevents-format deliveries. Call it before Start.
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start()
Start begins processing the delivery queue and retry loop.
func (*Dispatcher) Stop ¶
func (d *Dispatcher) Stop()
Stop gracefully shuts down the dispatcher. Safe to call more than once and without a prior Start. In-flight deliveries are cancelled after a grace period.
func (*Dispatcher) WithPollInterval ¶ added in v0.15.0
func (d *Dispatcher) WithPollInterval(interval time.Duration)
WithPollInterval sets how often the retry loop claims due deliveries; it is how soon a delivery recorded by another process is delivered. Call it before Start.
type DispatcherStore ¶ added in v0.15.0
type DispatcherStore interface {
ClaimPendingWebhookDeliveries(ctx context.Context, limit int, lease time.Duration) ([]*models.WebhookDelivery, error)
CreateWebhookDelivery(ctx context.Context, delivery *models.WebhookDelivery) error
GetWebhook(ctx context.Context, id string) (*models.Webhook, error)
ListWebhooksForEvent(ctx context.Context, repoID string, eventType string) ([]*models.Webhook, error)
UpdateWebhookDelivery(ctx context.Context, delivery *models.WebhookDelivery) error
}
DispatcherStore is the part of the database Dispatcher needs.
type Publisher ¶ added in v0.2.0
type Publisher interface {
Dispatch(ctx context.Context, repoID, eventType string, payload map[string]any)
}
Publisher is the slice of *Dispatcher that request handlers use to announce events. Handlers hold it as an optional dependency: a nil Publisher (tests, webhooks not wired) turns every Emit into a no-op.
type QuarantineChange ¶ added in v0.21.0
type QuarantineChange struct {
Repository string
Format string
RepoType string
Quarantined bool // the new state: true quarantined, false released
Kind ScanKind
ArtifactID string
Package string
Version string
Reason string // why: "review by an administrator", "blocking license policy"
Actor string // the user or token that did it; empty for the system
}
QuarantineChange describes an artifact quarantined or released.
type ScanCompleted ¶ added in v0.21.0
type ScanCompleted struct {
Repository string // repository name
Format string // repository format
RepoType string // "hosted", "proxy" or "group"
ScanID string // id of the stored scan result
Kind ScanKind
Status string // scan_status of the stored result (completed, partial, failed, clean, flagged)
ArtifactID string // the scan's artifact identifier
Package string // package name, when the scan names one
Version string // package version, when the scan names one
// Counts are the findings of the scan: critical, high, medium, low and
// total for a vulnerability scan; findings for a secret scan; licenses for
// a license scan.
Counts map[string]int
}
ScanCompleted describes a scan that reached a final status: the subject of the scan.completed and vulnerability.found events.
type VulnerabilityDetected ¶ added in v0.14.0
type VulnerabilityDetected struct {
Artifact Artifact
// RepoType is "hosted" or "proxy".
RepoType string
Findings []VulnerabilityFinding
}
VulnerabilityDetected describes the stored package version a vulnerability.new event is about and the advisories newly affecting it.