webhook

package
v0.0.0-...-f6a3790 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: Apache-2.0 Copyright 2024 Seqera

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0 Copyright 2024 Seqera

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchServiceAdapter

type BatchServiceAdapter struct {
	Logger *slog.Logger
	Pool   *pgxpool.Pool
	// contains filtered or unexported fields
}

BatchServiceAdapter processes webhook events asynchronously with batching to reduce database load and improve webhook response times

func NewBatchServiceAdapter

func NewBatchServiceAdapter(log *slog.Logger, pool *pgxpool.Pool) *BatchServiceAdapter

NewBatchServiceAdapter creates a new batch webhook service adapter Configuration is pulled from environment variables with sensible defaults:

  • STATICREG_METRICS_BATCH_SIZE: Number of events to batch before flushing (default: 100)
  • STATICREG_METRICS_FLUSH_INTERVAL: Time interval to force flush (default: 5s)
  • STATICREG_METRICS_BUFFER_SIZE: Channel buffer size (default: 10000)

func (*BatchServiceAdapter) Close

func (a *BatchServiceAdapter) Close(timeout time.Duration) error

Close gracefully shuts down the worker, flushing any pending events

func (*BatchServiceAdapter) GetMetrics

func (a *BatchServiceAdapter) GetMetrics() map[string]int64

GetMetrics returns current metrics for observability

func (*BatchServiceAdapter) SavePullEvent

func (a *BatchServiceAdapter) SavePullEvent(ctx context.Context, event *DistributionEvent) error

SavePullEvent queues an event for asynchronous processing Returns immediately without blocking on database operations

type DistributionEvent

type DistributionEvent struct {
	ID        string                   `json:"id"`
	Timestamp time.Time                `json:"timestamp"`
	Action    string                   `json:"action"`
	Target    DistributionEventTarget  `json:"target"`
	Request   DistributionEventRequest `json:"request"`
	Actor     DistributionEventActor   `json:"actor"`
	Source    DistributionEventSource  `json:"source"`
}

DistributionEvent represents a single Docker Distribution event

func (*DistributionEvent) GetArchitecture

func (e *DistributionEvent) GetArchitecture() string

GetArchitecture extracts architecture from the event's user agent string Docker clients typically include platform info in the user agent Format examples:

  • "docker/20.10.7 go/go1.16.4 git-commit/f0df350 kernel/5.10.0 os/linux arch/amd64"
  • "containerd/1.4.4+unknown"

func (*DistributionEvent) IsFromStaticReg

func (e *DistributionEvent) IsFromStaticReg() bool

IsFromStaticReg checks if the event originates from staticreg itself This helps exclude staticreg's internal manifest fetches from pull metrics

func (*DistributionEvent) IsManifestPull

func (e *DistributionEvent) IsManifestPull() bool

IsManifestPull checks if the event is a manifest pull (final step of container pull)

func (*DistributionEvent) IsManifestPush

func (e *DistributionEvent) IsManifestPush() bool

IsManifestPush checks if the event is a manifest push (final step of container push)

func (*DistributionEvent) IsPullEvent

func (e *DistributionEvent) IsPullEvent() bool

IsPullEvent checks if the event is a pull action

func (*DistributionEvent) IsPushEvent

func (e *DistributionEvent) IsPushEvent() bool

IsPushEvent checks if the event is a push action

type DistributionEventActor

type DistributionEventActor struct {
	Name string `json:"name,omitempty"`
}

DistributionEventActor represents the agent that initiated the event

type DistributionEventEnvelope

type DistributionEventEnvelope struct {
	Events []DistributionEvent `json:"events"`
}

DistributionEventEnvelope represents the envelope containing Docker Distribution events

type DistributionEventRequest

type DistributionEventRequest struct {
	ID        string `json:"id"`
	Addr      string `json:"addr"`
	Host      string `json:"host"`
	Method    string `json:"method"`
	UserAgent string `json:"useragent"`
}

DistributionEventRequest contains request metadata

type DistributionEventSource

type DistributionEventSource struct {
	Addr       string `json:"addr"`
	InstanceID string `json:"instanceID"`
}

DistributionEventSource contains information about the registry node

type DistributionEventTarget

type DistributionEventTarget struct {
	MediaType  string `json:"mediaType"`
	Size       int64  `json:"size,omitempty"`
	Digest     string `json:"digest"`
	Length     int64  `json:"length,omitempty"`
	Repository string `json:"repository"`
	URL        string `json:"url,omitempty"`
	Tag        string `json:"tag,omitempty"`
}

DistributionEventTarget contains details about the affected artifact

type ServiceAdapter

type ServiceAdapter struct {
	Logger *slog.Logger
	Pool   *pgxpool.Pool
}

func NewServiceAdapter

func NewServiceAdapter(log *slog.Logger, pool *pgxpool.Pool) *ServiceAdapter

func (*ServiceAdapter) Close

func (a *ServiceAdapter) Close(timeout time.Duration) error

Close is a no-op for synchronous ServiceAdapter (implements WebhookService interface)

func (*ServiceAdapter) SavePullEvent

func (a *ServiceAdapter) SavePullEvent(ctx context.Context, event *DistributionEvent) error

type WebhookService

type WebhookService interface {
	// Database operation method
	SavePullEvent(ctx context.Context, event *DistributionEvent) error
	// Close gracefully shuts down the service, flushing pending events
	Close(timeout time.Duration) error
}

WebhookService defines the contract for all post-webhook operations.

Jump to

Keyboard shortcuts

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