Documentation
¶
Index ¶
- func Context(ctx context.Context, payload any) context.Context
- func FilterWebhooks(ctx context.Context) (sq.Sqlizer, error)
- func LegacyMiddleware(queue *LegacyQueue) func(next http.Handler) http.Handler
- func Middleware(queue *WebhookQueue) func(next http.Handler) http.Handler
- func Payload(ctx context.Context) (any, error)
- func Validate(schema graphql.ExecutableSchema, query string) error
- type AuthConfig
- type LegacyQueue
- type LegacySubscription
- type WebhookContext
- type WebhookQueue
- type WebhookSubscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterWebhooks ¶
Returns an SQL expression to filter webhooks for the authenticated user.
func LegacyMiddleware ¶
func LegacyMiddleware(queue *LegacyQueue) func(next http.Handler) http.Handler
func Middleware ¶
func Middleware(queue *WebhookQueue) func(next http.Handler) http.Handler
Types ¶
type AuthConfig ¶
type AuthConfig struct {
AuthMethod string
TokenHash *string
Grants *string
ClientID *string
Expires *time.Time
NodeID *string
}
The following invariants apply to AuthConfig:
- AuthMethod will be either OAUTH2 or INTERNAL
- If OAUTH2, TokenHash, Grants, and Expires will be non-nil, and ClientID may be non-nil, and NodeID will be nil.
- If INTERNAL, TokenHash, Grants, Expires, and ClientID will be nil, and NodeID will be non-nil.
func NewAuthConfig ¶
func NewAuthConfig(ctx context.Context) (AuthConfig, error)
Pulls auth details out of the config context and returns a structure of all of the information necessary to build a webhook context with the same authentication parameters.
type LegacyQueue ¶
func LegacyForContext ¶
func LegacyForContext(ctx context.Context) *LegacyQueue
func NewLegacyQueue ¶
func NewLegacyQueue(conf ini.File) *LegacyQueue
Creates a new worker for delivering legacy webhooks. The caller must start the worker themselves.
func (*LegacyQueue) Schedule ¶
func (lq *LegacyQueue) Schedule(ctx context.Context, q sq.SelectBuilder, name, event string, payload []byte)
Schedules delivery of a legacy webhook to a set of subscribers.
The select builder should not return any columns, i.e. the caller should use squirrel.Select() with no parameters. The caller should prepare FROM and any WHERE clauses which are necessary to refine the subscriber list (e.g. by affected resource ID). The caller must alias the webhook table to "sub", e.g. sq.Select().From("my_webhook_subscription sub").
Name shall be the prefix of the webhook tables, e.g. "user" for "user_webhook_{delivery,subscription}".
type LegacySubscription ¶
type WebhookContext ¶
type WebhookContext struct {
Name string
Event string
User *auth.AuthContext
Payload any
PayloadUUID uuid.UUID
Subscription *WebhookSubscription
}
func (*WebhookContext) Exec ¶
func (webhook *WebhookContext) Exec(ctx context.Context, schema graphql.ExecutableSchema) ([]byte, error)
Executes the GraphQL query prepared stored in the WebhookContext. Handles the configuration of a secondary authentication and GraphQL context.
type WebhookQueue ¶
type WebhookQueue struct {
Queue *work.Queue
Schema graphql.ExecutableSchema
}
func ForContext ¶
func ForContext(ctx context.Context) *WebhookQueue
func NewQueue ¶
func NewQueue(schema graphql.ExecutableSchema, conf ini.File) *WebhookQueue
Creates a new worker for delivering webhooks. The caller must start the worker themselves.
func (*WebhookQueue) Schedule ¶
func (queue *WebhookQueue) Schedule(ctx context.Context, q sq.SelectBuilder, name, event string, payloadUUID uuid.UUID, payload any)
Schedules delivery of a webhook to a set of subscribers.
The select builder should not return any columns, i.e. the caller should use squirrel.Select() with no parameters. The caller should prepare FROM and any WHERE clauses which are necessary to refine the subscriber list (e.g. by affected resource ID). The caller must alias the webhook table to "sub", e.g. sq.Select().From("my_webhook_subscription sub").
Name shall be the prefix of the webhook tables, e.g. "profile" for "gql_profile_wh_{delivery,sub}".
The context should NOT be the context used to service the HTTP request which initiated the webhook delivery. It should instead be a fresh background context which contains the necessary state for your application to process the webhook resolvers.