webhook

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package clients encapsulates all clients and associated helper methods to interact with other services.

Package webhook is the base webhook server for the github metrics ingestion.

Index

Constants

View Source
const (
	// SHA256SignatureHeader is the GitHub header key used to pass the HMAC-SHA256 hexdigest.
	SHA256SignatureHeader = "X-Hub-Signature-256"
	// EventTypeHeader is the GitHub header key used to pass the event type.
	EventTypeHeader = "X-Github-Event"
	// DeliveryIDHeader is the GitHub header key used to pass the unique ID for the webhook event.
	DeliveryIDHeader = "X-Github-Delivery"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BigQuery

type BigQuery struct {
	// contains filtered or unexported fields
}

BigQuery provides a client and dataset identifiers.

func NewBigQuery

func NewBigQuery(ctx context.Context, projectID, datasetID string, opts ...option.ClientOption) (*BigQuery, error)

NewBigQuery creates a new instance of a BigQuery client.

func (*BigQuery) Close

func (bq *BigQuery) Close() error

Close releases any resources held by the BigQuery client.

func (*BigQuery) DeliveryEventExists

func (bq *BigQuery) DeliveryEventExists(ctx context.Context, eventsTableID, deliveryID string) (bool, error)

Check if an entry with a given delivery_id already exists in the events table, this attempts to prevent duplicate processing of events. This is used by the webhook service.

func (*BigQuery) FailureEventsExceedsRetryLimit

func (bq *BigQuery) FailureEventsExceedsRetryLimit(ctx context.Context, failureEventTableID, deliveryID string, retryLimit int) (bool, error)

Check if the number of entries with a given delivery_id in the failure-events table exceeds the retry limit. This is used by the webhook service.

func (*BigQuery) WriteFailureEvent

func (bq *BigQuery) WriteFailureEvent(ctx context.Context, failureEventTableID, deliveryID, createdAt string) error

Write a failure event entry if there is a failure in processing the event. This is used by the webhook service.

type Config

type Config struct {
	BigQueryProjectID    string `env:"BIG_QUERY_PROJECT_ID,default=$PROJECT_ID"`
	DatasetID            string `env:"DATASET_ID,required"`
	EventsTableID        string `env:"EVENTS_TABLE_ID,required"`
	FailureEventsTableID string `env:"FAILURE_EVENTS_TABLE_ID,required"`
	Port                 string `env:"PORT,default=8080"`
	ProjectID            string `env:"PROJECT_ID,required"`
	RetryLimit           int    `env:"RETRY_LIMIT,required"`
	EventsTopicID        string `env:"EVENTS_TOPIC_ID,required"`
	DLQEventsTopicID     string `env:"DLQ_EVENTS_TOPIC_ID,required"`
	GitHubWebhookSecret  string `env:"GITHUB_WEBHOOK_SECRET,required"`
}

Config defines the set over environment variables required for running this application.

func NewConfig

func NewConfig(ctx context.Context) (*Config, error)

NewConfig creates a new Config from environment variables.

func (*Config) ToFlags

func (cfg *Config) ToFlags(set *cli.FlagSet) *cli.FlagSet

ToFlags binds the config to the give cli.FlagSet and returns it.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate validates the service config after load.

type Datastore

type Datastore interface {
	DeliveryEventExists(ctx context.Context, eventsTableID, deliveryID string) (bool, error)
	FailureEventsExceedsRetryLimit(ctx context.Context, failureEventTableID, deliveryID string, retryLimit int) (bool, error)
	WriteFailureEvent(ctx context.Context, failureEventTableID, deliveryID, createdAt string) error
	Close() error
}

Datastore adheres to the interaction the webhook service has with a datastore.

type FailureEventEntry

type FailureEventEntry struct {
	// contains filtered or unexported fields
}

FailureEventEntry is the skhape of an entry to the failure_events table.

func (*FailureEventEntry) Save

func (fe *FailureEventEntry) Save() (map[string]bigquery.Value, string, error)

Save implements the ValueSaver interface for a FailureEventEntry. A random insertID is generated by the library to facilitate deduplication.

type MockDatastore

type MockDatastore struct {
	// contains filtered or unexported fields
}

func (*MockDatastore) Close

func (m *MockDatastore) Close() error

func (*MockDatastore) DeliveryEventExists

func (m *MockDatastore) DeliveryEventExists(ctx context.Context, eventsTableID, deliveryID string) (bool, error)

func (*MockDatastore) FailureEventsExceedsRetryLimit

func (m *MockDatastore) FailureEventsExceedsRetryLimit(ctx context.Context, failureEventTableID, deliveryID string, retryLimit int) (bool, error)

func (*MockDatastore) WriteFailureEvent

func (m *MockDatastore) WriteFailureEvent(ctx context.Context, failureEventTableID, deliveryID, createdAt string) error

type PubSubClientConfig

type PubSubClientConfig struct {
	PubSubURL      string
	PubSubGRPCConn *grpc.ClientConn
}

PubSubClientConfig are the pubsub client config options.

type PubSubMessenger

type PubSubMessenger struct {
	// contains filtered or unexported fields
}

PubSubMessenger implements the Messenger interface for Google Cloud pubsub.

func NewPubSubMessenger

func NewPubSubMessenger(ctx context.Context, projectID, topicID string, opts ...option.ClientOption) (*PubSubMessenger, error)

NewPubSubMessenger creates a new instance of the PubSubMessenger.

func (*PubSubMessenger) Close

func (p *PubSubMessenger) Close() error

Close handles the graceful shutdown of the pubsub client.

func (*PubSubMessenger) Send

func (p *PubSubMessenger) Send(ctx context.Context, msg []byte) error

Send sends a message to a Google Cloud pubsub topic.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server provides the server implementation.

func NewServer

func NewServer(ctx context.Context, cfg *Config, wco *WebhookClientOptions) (*Server, error)

NewServer creates a new HTTP server implementation that will handle receiving webhook payloads.

func (*Server) Close

func (s *Server) Close() error

Close handles the graceful shutdown of the webhook server.

func (*Server) Routes

func (s *Server) Routes(ctx context.Context) http.Handler

Routes creates a ServeMux of all of the routes that this Router supports.

type WebhookClientOptions

type WebhookClientOptions struct {
	EventPubsubClientOpts    []option.ClientOption
	DLQEventPubsubClientOpts []option.ClientOption
	BigQueryClientOpts       []option.ClientOption
	DatastoreClientOverride  Datastore // used for unit testing
}

WebhookClientOptions encapsulate client config options as well as dependency implementation overrides.

Jump to

Keyboard shortcuts

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