common

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package common contains structs and methods that are shared across different gateways.

Index

Constants

View Source
const EventSourceDir = "../../../examples/event-sources"

Variables

View Source
var (
	ErrNilEventSource = fmt.Errorf("event source can't be nil")
)
View Source
var Hook = &Webhook{
	Endpoint: "/fake",
	Port:     "12000",
	URL:      "test-url",
}

Functions

func FormatWebhookEndpoint

func FormatWebhookEndpoint(endpoint string) string

func GenerateFormattedURL

func GenerateFormattedURL(w *Webhook) string

func GetAWSCreds added in v0.8.3

func GetAWSCreds(client kubernetes.Interface, namespace string, access *corev1.SecretKeySelector, secret *corev1.SecretKeySelector) (*credentials.Credentials, error)

GetAWSCreds reads credential stored in Kubernetes secrets and return it.

func GetAWSSession added in v0.8.3

func GetAWSSession(creds *credentials.Credentials, region string) (*session.Session, error)

func GetAWSSessionWithoutCreds added in v0.9.3

func GetAWSSessionWithoutCreds(region string) (*session.Session, error)

func InitRouteChannels

func InitRouteChannels(helper *WebhookHelper)

InitRouteChannels initializes route channels so they can activate and deactivate routes.

func ProcessRoute

func ProcessRoute(routeManager RouteManager, helper *WebhookHelper, eventStream gateways.Eventing_StartEventSourceServer) error

func ValidateGatewayEventSource

func ValidateGatewayEventSource(eventSource *gateways.EventSource, version string, parseEventSource func(string) (interface{}, error), validateEventSource func(interface{}) error) (*gateways.ValidEventSource, error)

func ValidateWebhook

func ValidateWebhook(w *Webhook) error

Types

type Endpoint

type Endpoint struct {
	// whether endpoint is active
	Active bool
	// data channel to receive data on this endpoint
	DataCh chan []byte
}

endpoint contains state of an http endpoint

type FakeGRPCStream added in v0.8.3

type FakeGRPCStream struct {
	SentData *gateways.Event
	Ctx      context.Context
}

func (*FakeGRPCStream) Context added in v0.8.3

func (f *FakeGRPCStream) Context() context.Context

func (*FakeGRPCStream) RecvMsg added in v0.8.3

func (f *FakeGRPCStream) RecvMsg(m interface{}) error

func (*FakeGRPCStream) Send added in v0.8.3

func (f *FakeGRPCStream) Send(event *gateways.Event) error

func (*FakeGRPCStream) SendHeader added in v0.8.3

func (f *FakeGRPCStream) SendHeader(metadata.MD) error

func (*FakeGRPCStream) SendMsg added in v0.8.3

func (f *FakeGRPCStream) SendMsg(m interface{}) error

func (*FakeGRPCStream) SetHeader added in v0.8.3

func (f *FakeGRPCStream) SetHeader(metadata.MD) error

func (*FakeGRPCStream) SetTrailer added in v0.8.3

func (f *FakeGRPCStream) SetTrailer(metadata.MD)

type FakeHttpWriter added in v0.8.3

type FakeHttpWriter struct {
	HeaderStatus int
	Payload      []byte
}

func (*FakeHttpWriter) Header added in v0.8.3

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

func (*FakeHttpWriter) Write added in v0.8.3

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

func (*FakeHttpWriter) WriteHeader added in v0.8.3

func (f *FakeHttpWriter) WriteHeader(status int)

type FakeRouteConfig added in v0.9.1

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

func (*FakeRouteConfig) GetRoute added in v0.9.1

func (f *FakeRouteConfig) GetRoute() *Route

func (*FakeRouteConfig) PostStart added in v0.9.1

func (f *FakeRouteConfig) PostStart() error

func (*FakeRouteConfig) PostStop added in v0.9.1

func (f *FakeRouteConfig) PostStop() error

func (*FakeRouteConfig) RouteHandler added in v0.9.1

func (f *FakeRouteConfig) RouteHandler(writer http.ResponseWriter, request *http.Request)

type Route added in v0.9.1

type Route struct {
	Webhook     *Webhook
	Logger      *logrus.Logger
	StartCh     chan struct{}
	EventSource *gateways.EventSource
}

Route contains common information for a route

func GetFakeRoute added in v0.9.1

func GetFakeRoute() *Route

type RouteManager added in v0.9.1

type RouteManager interface {
	GetRoute() *Route
	RouteHandler(writer http.ResponseWriter, request *http.Request)
	PostStart() error
	PostStop() error
}

RouteManager is an interface to manage the configuration for a route

type WatchPathConfig

type WatchPathConfig struct {
	// Directory to watch for events
	Directory string `json:"directory"`
	// Path is relative path of object to watch with respect to the directory
	Path string `json:"path,omitempty"`
	// PathRegexp is regexp of relative path of object to watch with respect to the directory
	PathRegexp string `json:"pathRegexp,omitempty"`
}

func (*WatchPathConfig) Validate

func (c *WatchPathConfig) Validate() error

Validate validates WatchPathConfig

type Webhook

type Webhook 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"`
	// contains filtered or unexported fields
}

Webhook is a general purpose REST API

type WebhookHelper

type WebhookHelper struct {
	// Mutex synchronizes ActiveServers
	Mutex sync.Mutex
	// ActiveServers keeps track of currently running http servers.
	ActiveServers map[string]*activeServer
	// ActiveEndpoints keep track of endpoints that are already registered with server and their status active or inactive
	ActiveEndpoints map[string]*Endpoint
	// RouteActivateChan handles assigning new route to server.
	RouteActivateChan chan RouteManager
	// RouteDeactivateChan handles deactivating existing route
	RouteDeactivateChan chan RouteManager
}

WebhookHelper is a helper struct

func NewWebhookHelper

func NewWebhookHelper() *WebhookHelper

NewWebhookHelper returns new Webhook helper

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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