webhooks

package
v0.0.0-...-5a81e2c Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: BSD-3-Clause Imports: 23 Imported by: 40

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(ctx context.Context, payload interface{}) context.Context

Prepares an context for a specific webhook delivery.

func FilterWebhooks

func FilterWebhooks(ctx context.Context) (sq.Sqlizer, error)

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

func Payload

func Payload(ctx context.Context) (interface{}, error)

Returns the active payload for a webhook context.

func Validate

func Validate(schema graphql.ExecutableSchema, query string) error

Validates the given query against the provided schema and returns any errors should they be found, or nil if the query passes validation.

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:

  1. AuthMethod will be either OAUTH2 or INTERNAL
  2. If OAUTH2, TokenHash, Grants, and Expires will be non-nil, and ClientID may be non-nil, and NodeID will be nil.
  3. 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

type LegacyQueue struct {
	Queue *work.Queue
}

func LegacyForContext

func LegacyForContext(ctx context.Context) *LegacyQueue

func NewLegacyQueue

func NewLegacyQueue() *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 LegacySubscription struct {
	ID      int
	Created time.Time
	URL     string
	Events  []string
}

type WebhookContext

type WebhookContext struct {
	Name         string
	Event        string
	User         *auth.AuthContext
	Payload      interface{}
	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) *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 interface{})

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.

type WebhookSubscription

type WebhookSubscription struct {
	ID    int
	URL   string
	Query string
	// See AuthConfig in webhooks/config.go for an explanation of these fields
	AuthMethod string
	TokenHash  *string
	Grants     *string
	ClientID   *string
	Expires    *time.Time
	NodeID     *string
}

Jump to

Keyboard shortcuts

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