Documentation
¶
Overview ¶
Package webhookapi is the admin REST surface for inbound webhook sources (#1870): list, create, read with status, change, and delete, and the status of every source in one response (#1979). Secrets are write-only: a view says whether one is set and until when the previous one is still accepted, and never carries either.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthInput ¶
type AuthInput struct {
Mode string `json:"mode" example:"hmac"`
Secret string `json:"secret,omitempty" example:"whsec_example"`
Algorithm string `json:"algorithm,omitempty" example:"sha256"`
SignatureHeader string `json:"signature_header,omitempty" example:"X-Signature"`
Encoding string `json:"encoding,omitempty" example:"hex"`
Prefix string `json:"prefix,omitempty" example:"sha256="`
TimestampHeader string `json:"timestamp_header,omitempty" example:"X-Timestamp"`
ToleranceSeconds int `json:"tolerance_seconds,omitempty" example:"300"`
Signed string `json:"signed,omitempty" example:"body"`
Header string `json:"header,omitempty" example:"X-Webhook-Token"`
Username string `json:"username,omitempty" example:"sender"`
}
AuthInput is how a request proves it came from the sender. secret is write-only; on an update, an empty secret keeps the stored one.
type AuthView ¶
type AuthView struct {
Mode string `json:"mode"`
SecretSet bool `json:"secret_set"`
PreviousUntil *time.Time `json:"previous_secret_until,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
SignatureHeader string `json:"signature_header,omitempty"`
Encoding string `json:"encoding,omitempty"`
Prefix string `json:"prefix,omitempty"`
TimestampHeader string `json:"timestamp_header,omitempty"`
ToleranceSeconds int `json:"tolerance_seconds,omitempty"`
Signed string `json:"signed,omitempty"`
Header string `json:"header,omitempty"`
Username string `json:"username,omitempty"`
}
AuthView is a source's authentication without its secrets.
type Config ¶
type Config struct {
// Service manages sources. nil mounts nothing.
Service Service
// Author resolves the acting admin.
Author func(*http.Request) string
}
Config carries the service and the parent-owned helpers.
type Service ¶
type Service interface {
List(ctx context.Context) ([]whsource.Source, error)
Get(ctx context.Context, name string) (whsource.Source, whstore.Status, error)
Create(ctx context.Context, src whsource.Source) (whsource.Source, error)
Update(ctx context.Context, name string, u whadmin.Update) (whsource.Source, error)
Delete(ctx context.Context, name string) error
Overview(ctx context.Context, span, step time.Duration) (whadmin.Overview, error)
}
Service is what the routes act through. whadmin.Service satisfies it.
type SourceDetail ¶
type SourceDetail struct {
Source SourceView `json:"source"`
Status whstore.Status `json:"status"`
}
SourceDetail is one source with its status.
type SourceInput ¶
type SourceInput struct {
Name string `json:"name,omitempty" example:"esp-events"`
Enabled *bool `json:"enabled,omitempty" example:"true"`
Connection string `json:"connection,omitempty" example:"scratch"`
Auth AuthInput `json:"auth"`
Config whsource.Config `json:"config"`
// RotationOverlapSeconds keeps the previous secret valid this long when
// auth.secret replaces it. Zero ends it at once.
RotationOverlapSeconds int `json:"rotation_overlap_seconds,omitempty" example:"86400"`
}
SourceInput is the write shape. name and connection are read on create only: the table was created on that connection under a name derived from the source's.
type SourceList ¶
type SourceList struct {
Sources []SourceView `json:"sources"`
}
SourceList is the collection response.
type SourceRejection ¶ added in v1.138.2
type SourceRejection struct {
Source string `json:"source"`
At time.Time `json:"at"`
Outcome string `json:"outcome"`
Reason string `json:"reason"`
}
SourceRejection is one refused request and the source it was sent to.
type SourceStatus ¶ added in v1.138.2
type SourceStatus struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
// Health is the source's overall state. When more than one applies, the
// first of disabled, failing, silent, receiving is reported.
Health string `json:"health" enums:"receiving,silent,failing,disabled"`
AuthMode string `json:"auth_mode"`
Connection string `json:"connection"`
Table string `json:"table"`
// LastEventAt is when the source last received an event; null when it
// never has, or not within the windows it still holds.
LastEventAt *time.Time `json:"last_event_at"`
// LastHour and LastDay are request counts by outcome.
LastHour map[string]int64 `json:"last_hour"`
LastDay map[string]int64 `json:"last_day"`
// Pending counts windows owed a compaction; Failing, those whose last
// attempt failed, with the newest one's error in LastError.
Pending int `json:"pending"`
Failing int `json:"failing"`
LastError string `json:"last_error,omitempty"`
}
SourceStatus is one source's line on the overview.
type SourceView ¶
type SourceView struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
Connection string `json:"connection"`
// Path is where the sender posts, relative to the platform's address:
// /hooks/{name}, with the token as a further segment for path_token.
Path string `json:"path" example:"/hooks/esp-events"`
// Table is what readers query, in the connection's scratch schema.
Table string `json:"table" example:"webhook_esp_events"`
Auth AuthView `json:"auth"`
Config whsource.Config `json:"config"`
CreatedBy string `json:"created_by,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SourceView is the read shape.
type StatusOverview ¶ added in v1.138.2
type StatusOverview struct {
GeneratedAt time.Time `json:"generated_at"`
// Range is the span the series covers: hour or day.
Range string `json:"range" enums:"hour,day" example:"hour"`
// From is the series' lower bound: a minute's counts are in the series
// when the minute is at or after it.
From time.Time `json:"from"`
// BucketSeconds is the length of one bucket of the series.
BucketSeconds int `json:"bucket_seconds" example:"60"`
// SilentAfterSeconds is how long an enabled source may go without an
// event before it is reported silent.
SilentAfterSeconds int `json:"silent_after_seconds" example:"86400"`
Sources []SourceStatus `json:"sources"`
Volume []VolumePoint `json:"volume"`
Rejections []SourceRejection `json:"rejections"`
}
StatusOverview is the status of every source in one response (#1979): each source's health and counts, the request series over the range, and the newest rejections of every source.
type VolumePoint ¶ added in v1.138.2
type VolumePoint struct {
At time.Time `json:"at"`
Source string `json:"source"`
Outcome string `json:"outcome"`
Count int64 `json:"count"`
}
VolumePoint is the number of requests of one source with one outcome in the bucket starting at At. A bucket with no requests has no point.