Documentation
¶
Index ¶
- Constants
- func BearerToken(r *http.Request) string
- func DecodeCursor(s string) (int64, error)
- func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) bool
- func EncodeCursor(id int64) string
- func EnsureSQLiteSchema(db *sql.DB) error
- func HashToken(raw string) string
- func NewEventID() (string, error)
- func NewSafeClient(allowHost func(host string) error) *http.Client
- func NewSecret() (string, error)
- func NewToken(tokenPrefix string) (raw, hash, display string, err error)
- func NormalizeScopes(requested []string, allowed []string) ([]string, error)
- func ScopesInclude(granted []string, want string) bool
- func Sign(secret string, ts int64, body []byte) string
- func ValidateWebhookURL(raw string) error
- func VerifySignature(secret, header string, ts int64, body []byte, tolerance time.Duration, ...) bool
- func WriteError(w http.ResponseWriter, status int, code, message string)
- func WriteInternal(w http.ResponseWriter, what string, err error)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- func WriteList(w http.ResponseWriter, data any, nextID int64)
- type Admin
- func (a *Admin) CreateKey(w http.ResponseWriter, r *http.Request)
- func (a *Admin) CreateWebhook(w http.ResponseWriter, r *http.Request)
- func (a *Admin) DeleteWebhook(w http.ResponseWriter, r *http.Request)
- func (a *Admin) Deliveries(w http.ResponseWriter, r *http.Request)
- func (a *Admin) Overview(w http.ResponseWriter, r *http.Request)
- func (a *Admin) RevokeKey(w http.ResponseWriter, r *http.Request)
- func (a *Admin) TestWebhook(w http.ResponseWriter, r *http.Request)
- func (a *Admin) ToggleWebhook(w http.ResponseWriter, r *http.Request)
- type Authenticator
- type Config
- type Delivery
- type DeliveryView
- type Emitter
- type ErrorBody
- type Event
- type HandlerFunc
- type HookView
- type Key
- type KeyView
- type List
- type Op
- type OverviewView
- type Page
- type Param
- type Registry
- type SQLStore
- func (s *SQLStore) Insert(ctx context.Context, k Key, hash string) (int64, error)
- func (s *SQLStore) List(ctx context.Context, owner int64) ([]Key, error)
- func (s *SQLStore) Lookup(ctx context.Context, hash string) (*Key, error)
- func (s *SQLStore) Revoke(ctx context.Context, id int64, owner int64, now time.Time) (bool, error)
- func (s *SQLStore) Touch(ctx context.Context, id int64, ip string, now time.Time) error
- type SQLWebhookStore
- func (s *SQLWebhookStore) AddDelivery(ctx context.Context, d Delivery) error
- func (s *SQLWebhookStore) Create(ctx context.Context, w Webhook) (int64, error)
- func (s *SQLWebhookStore) Delete(ctx context.Context, id, owner int64) (bool, error)
- func (s *SQLWebhookStore) Deliveries(ctx context.Context, webhookID, owner int64, limit int) ([]Delivery, error)
- func (s *SQLWebhookStore) Get(ctx context.Context, id int64) (*Webhook, error)
- func (s *SQLWebhookStore) List(ctx context.Context, owner int64) ([]Webhook, error)
- func (s *SQLWebhookStore) ListFor(ctx context.Context, owner int64, eventType string) ([]Webhook, error)
- func (s *SQLWebhookStore) Prune(ctx context.Context, olderThan time.Time) error
- func (s *SQLWebhookStore) RecordResult(ctx context.Context, id int64, ok bool, disableAfter int) (bool, error)
- func (s *SQLWebhookStore) SetEnabled(ctx context.Context, id, owner int64, enabled bool) (bool, error)
- type SendResult
- type Store
- type Webhook
- type WebhookStore
Constants ¶
View Source
const ( SignatureHeader = "X-Webhook-Signature" TimestampHeader = "X-Webhook-Timestamp" EventIDHeader = "X-Webhook-Id" EventTypeHeader = "X-Webhook-Event" )
View Source
const MaxBodyBytes = 2 << 20
Variables ¶
This section is empty.
Functions ¶
func BearerToken ¶
func DecodeCursor ¶
func DecodeJSON ¶
func EncodeCursor ¶
func EnsureSQLiteSchema ¶
func NewEventID ¶
func ScopesInclude ¶
func ValidateWebhookURL ¶
func VerifySignature ¶
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, code, message string)
func WriteInternal ¶
func WriteInternal(w http.ResponseWriter, what string, err error)
Types ¶
type Admin ¶
type Admin struct {
Keys Store
Hooks WebhookStore
Emitter *Emitter
AllowedScopes func() []string
Events []string
TokenPrefix string
Owner func(r *http.Request) int64
Actor func(r *http.Request) int64
Audit func(r *http.Request, action, detail string)
Seal func(string) (string, error)
BaseURL func(r *http.Request) string
MaxKeys int
MaxHooks int
}
func (*Admin) CreateWebhook ¶
func (a *Admin) CreateWebhook(w http.ResponseWriter, r *http.Request)
func (*Admin) DeleteWebhook ¶
func (a *Admin) DeleteWebhook(w http.ResponseWriter, r *http.Request)
func (*Admin) Deliveries ¶
func (a *Admin) Deliveries(w http.ResponseWriter, r *http.Request)
func (*Admin) TestWebhook ¶
func (a *Admin) TestWebhook(w http.ResponseWriter, r *http.Request)
func (*Admin) ToggleWebhook ¶
func (a *Admin) ToggleWebhook(w http.ResponseWriter, r *http.Request)
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
func New ¶
func New(cfg Config) *Authenticator
func (*Authenticator) NewRegistry ¶
func (a *Authenticator) NewRegistry(mount func(method, path string, h http.Handler)) *Registry
func (*Authenticator) Wrap ¶
func (a *Authenticator) Wrap(scope string, h HandlerFunc) http.Handler
type DeliveryView ¶
type DeliveryView struct {
ID int64 `json:"id"`
EventID string `json:"event_id"`
EventType string `json:"event_type"`
Attempt int `json:"attempt"`
StatusCode int `json:"status_code"`
OK bool `json:"ok"`
Error string `json:"error"`
DurationMS int `json:"duration_ms"`
CreatedAt time.Time `json:"created_at"`
}
type Emitter ¶
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request, k *Key)
func Idempotent ¶
func Idempotent(h HandlerFunc) HandlerFunc
type Key ¶
type KeyView ¶
type KeyView struct {
ID int64 `json:"id"`
Label string `json:"label"`
Prefix string `json:"prefix"`
Scopes []string `json:"scopes"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt *time.Time `json:"last_used_at"`
LastUsedIP string `json:"last_used_ip"`
ExpiresAt *time.Time `json:"expires_at"`
Revoked bool `json:"revoked"`
Expired bool `json:"expired"`
}
type OverviewView ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Handle ¶
func (g *Registry) Handle(op Op, h HandlerFunc)
type SQLWebhookStore ¶
func (*SQLWebhookStore) AddDelivery ¶
func (s *SQLWebhookStore) AddDelivery(ctx context.Context, d Delivery) error
func (*SQLWebhookStore) Deliveries ¶
func (*SQLWebhookStore) RecordResult ¶
func (*SQLWebhookStore) SetEnabled ¶
type SendResult ¶
type Store ¶
type Store interface {
Insert(ctx context.Context, k Key, hash string) (int64, error)
Lookup(ctx context.Context, hash string) (*Key, error)
Touch(ctx context.Context, id int64, ip string, now time.Time) error
List(ctx context.Context, owner int64) ([]Key, error)
Revoke(ctx context.Context, id int64, owner int64, now time.Time) (bool, error)
}
type Webhook ¶
type WebhookStore ¶
type WebhookStore interface {
Create(ctx context.Context, w Webhook) (int64, error)
Get(ctx context.Context, id int64) (*Webhook, error)
List(ctx context.Context, owner int64) ([]Webhook, error)
ListFor(ctx context.Context, owner int64, eventType string) ([]Webhook, error)
Delete(ctx context.Context, id, owner int64) (bool, error)
SetEnabled(ctx context.Context, id, owner int64, enabled bool) (bool, error)
RecordResult(ctx context.Context, id int64, ok bool, disableAfter int) (bool, error)
AddDelivery(ctx context.Context, d Delivery) error
Deliveries(ctx context.Context, webhookID, owner int64, limit int) ([]Delivery, error)
Prune(ctx context.Context, olderThan time.Time) error
}
Click to show internal directories.
Click to hide internal directories.