webhook

package
v0.13.0-rc Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Hook = &Context{
	Endpoint: "/fake",
	Port:     "12000",
	URL:      "test-url",
}
View Source
var (
	// Mutex synchronizes ActiveServerHandlers
	Lock sync.Mutex
)

Functions

func ManageRoute

func ManageRoute(router Router, controller *Controller, eventStream gateways.Eventing_StartEventSourceServer) error

ManagerRoute manages the lifecycle of a route

func ProcessRouteStatus

func ProcessRouteStatus(ctrl *Controller)

ProcessRouteStatus processes route status as active and inactive.

func ValidateWebhookContext

func ValidateWebhookContext(context *Context) error

ValidateWebhookContext validates a webhook context

Types

type Context

type Context struct {
	// REST API endpoint
	Endpoint string `json:"endpoint" protobuf:"bytes,1,name=endpoint"`
	// Method is HTTP request method that indicates the desired action to be performed for a given resource.
	// See RFC7231 Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
	Method string `json:"method" protobuf:"bytes,2,name=method"`
	// Port on which HTTP server is listening for incoming events.
	Port string `json:"port" protobuf:"bytes,3,name=port"`
	// URL is the url of the server.
	URL string `json:"url" protobuf:"bytes,4,name=url"`
	// ServerCertPath refers the file that contains the cert.
	ServerCertPath string `json:"serverCertPath,omitempty" protobuf:"bytes,4,opt,name=serverCertPath"`
	// ServerKeyPath refers the file that contains private key
	ServerKeyPath string `json:"serverKeyPath,omitempty" protobuf:"bytes,5,opt,name=serverKeyPath"`
}

Context holds a general purpose REST API context

type Controller

type Controller struct {
	// ActiveServerHandlers keeps track of currently active mux/router for the http servers.
	ActiveServerHandlers map[string]*mux.Router
	// AllRoutes keep track of routes that are already registered with server and their status active or inactive
	AllRoutes map[string]*mux.Route
	// RouteActivateChan handles activation of routes
	RouteActivateChan chan Router
	// RouteDeactivateChan handles inactivation of routes
	RouteDeactivateChan chan Router
}

Controller controls the active servers and endpoints

func NewController

func NewController() *Controller

NewController returns a webhook controller

type FakeHttpWriter

type FakeHttpWriter struct {
	HeaderStatus int
	Payload      []byte
}

func (*FakeHttpWriter) Header

func (f *FakeHttpWriter) Header() http.Header

func (*FakeHttpWriter) Write

func (f *FakeHttpWriter) Write(body []byte) (int, error)

func (*FakeHttpWriter) WriteHeader

func (f *FakeHttpWriter) WriteHeader(status int)

type FakeRouter

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

func (*FakeRouter) GetRoute

func (f *FakeRouter) GetRoute() *Route

func (*FakeRouter) HandleRoute

func (f *FakeRouter) HandleRoute(writer http.ResponseWriter, request *http.Request)

func (*FakeRouter) PostActivate

func (f *FakeRouter) PostActivate() error

func (*FakeRouter) PostInactivate

func (f *FakeRouter) PostInactivate() error

type Route

type Route struct {
	// Context refers to the webhook context
	Context *Context
	// Logger to log stuff
	Logger *logrus.Logger
	// StartCh controls the
	StartCh chan struct{}
	// EventSource refers to gateway event source
	EventSource *gateways.EventSource
	// active determines whether the route is active and ready to process incoming requets
	// or it is an inactive route
	Active bool
	// data channel to receive data on this endpoint
	DataCh chan []byte
	// Stop channel to signal the end of the event source.
	StopChan chan struct{}
}

Route contains general information about a route

func GetFakeRoute

func GetFakeRoute() *Route

func NewRoute

func NewRoute(hookContext *Context, logger *logrus.Logger, eventSource *gateways.EventSource) *Route

NewRoute returns a vanilla route

type Router

type Router interface {
	// GetRoute returns the route
	GetRoute() *Route
	// HandleRoute processes the incoming requests on the route
	HandleRoute(writer http.ResponseWriter, request *http.Request)
	// PostActivate captures the operations if any after route being activated and ready to process requests.
	PostActivate() error
	// PostInactivate captures cleanup operations if any after route is inactivated
	PostInactivate() error
}

Router is an interface to manage the route

Jump to

Keyboard shortcuts

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