Documentation
¶
Overview ¶
Package webhooks runs actions on stacks and containers when a secret URL is called (#85, #91, ADR-0041), e.g. from CI after a new image was published.
Index ¶
- Constants
- Variables
- func Path(token string) string
- type Environments
- type Input
- type JobRunner
- type Service
- func (s *Service) Call(ctx context.Context, token string) (Webhook, jobs.Job, error)
- func (s *Service) Create(ctx context.Context, in Input, user string) (Webhook, string, error)
- func (s *Service) Delete(ctx context.Context, id int64) error
- func (s *Service) List(ctx context.Context) ([]Webhook, error)
- func (s *Service) NewToken(ctx context.Context, id int64) (string, error)
- func (s *Service) Update(ctx context.Context, id int64, in Input) (Webhook, error)
- type StackFinder
- type Store
- type Webhook
Constants ¶
const ( KindStack = "stack" KindContainer = "container" // ActionRedeploy pulls images and recreates: compose pull + up for a stack, pull and // recreate with the same settings for a container. ActionRedeploy = "redeploy" // ActionRestart restarts as is. ActionRestart = "restart" )
Target kinds and actions.
Variables ¶
var ErrReadOnly = fmt.Errorf("%w: the environment is in read-only mode", errdefs.ErrUnavailable)
ErrReadOnly is returned when the webhook's environment cannot be changed (ADR-0011).
Functions ¶
Types ¶
type Environments ¶
type Environments interface {
Get(id string) (*environment.Environment, bool)
}
Environments finds environments; *environment.Registry implements it.
type Input ¶
type Input struct {
Name string `json:"name"`
Environment string `json:"environment"`
Namespace string `json:"namespace"`
TargetKind string `json:"targetKind"`
Target string `json:"target"`
Action string `json:"action"`
Enabled bool `json:"enabled"`
}
Input creates or changes a webhook. Keep in sync with api/openapi.yaml.
type Service ¶
type Service struct {
Store Store
Environments Environments
Stacks StackFinder // nil: stack webhooks fail
Jobs JobRunner
Now func() time.Time
}
Service manages webhooks and runs them.
func (*Service) Call ¶
Call runs the webhook of a token as a job. Unknown and disabled tokens are not found.
type StackFinder ¶
StackFinder finds the compose file of a stack; *stacks.Service implements it.
type Store ¶
type Store interface {
ListWebhooks(ctx context.Context) ([]db.Webhook, error)
GetWebhook(ctx context.Context, id int64) (db.Webhook, error)
GetWebhookByToken(ctx context.Context, tokenHash string) (db.Webhook, error)
CreateWebhook(ctx context.Context, arg db.CreateWebhookParams) (db.Webhook, error)
UpdateWebhook(ctx context.Context, arg db.UpdateWebhookParams) (db.Webhook, error)
SetWebhookToken(ctx context.Context, arg db.SetWebhookTokenParams) (int64, error)
SetWebhookCalled(ctx context.Context, arg db.SetWebhookCalledParams) error
DeleteWebhook(ctx context.Context, id int64) (int64, error)
}
Store is the database of webhooks; *db.Queries of the write connection implements it.
type Webhook ¶
type Webhook struct {
ID int64 `json:"id"`
Name string `json:"name"`
Environment string `json:"environment"`
Namespace string `json:"namespace"`
TargetKind string `json:"targetKind"`
Target string `json:"target"`
Action string `json:"action"`
Enabled bool `json:"enabled"`
CreatedBy string `json:"createdBy,omitempty"`
CreatedAt time.Time `json:"createdAt"`
LastCalledAt *time.Time `json:"lastCalledAt,omitempty"`
// LastJob is the job of the newest call; LastError why it could not start.
LastJob string `json:"lastJob,omitempty"`
LastError string `json:"lastError,omitempty"`
}
Webhook is a webhook without its token. Keep in sync with api/openapi.yaml.