webhookserver

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package webhookserver provides implementations of the WebHookServer interface. Which allows attachment and detachment for web-hooks to an internet exposed server.

The simplest implementation is to listen on a public port and forward request from there. But abstracting this as an interface allows us to implement different approaches like to ngrok, if we ever need to run the worker in an environment where machines can't be exposed to the internet. Old windows machines in a data center seems like a plausible use-case.

Webhooktunnel is an implementation of webhookserver which allows exposing endpoints without having to open any ports, public or otherwise. It uses webhookclient to connect to the proxy and multiplexes streams over websocket, and exposes a net.Listener interface which can be used by http.Server. This results in a more secure worker. Webhooktunnel requires TC credentials.

Index

Constants

This section is empty.

Variables

View Source
var ConfigSchema schematypes.Schema = schematypes.OneOf{
	localhostConfigSchema,
	localtunnelConfigSchema,
	statelessDNSConfigSchema,
	webhooktunnelConfigSchema,
}

ConfigSchema specifies schema for configuration passed to NewServer.

Functions

This section is empty.

Types

type LocalServer

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

LocalServer is a WebHookServer implementation that exposes webhooks on a local port directly exposed to the internet.

func NewLocalServer

func NewLocalServer(
	publicIP []byte,
	publicPort int,
	networkInterface string,
	localPort int,
	subdomain, dnsSecret, tlsCert, tlsKey string,
	expiration time.Duration,
) (*LocalServer, error)

NewLocalServer creates a WebHookServer that listens on publicIP, publicPort and uses stateless-dns-server to obtain a hostname.

If networkInterface is non-empty and localPort is non-zero then server will listen on the localPort for the given networkInterface. This is useful if running inside a container.

func (*LocalServer) AttachHook

func (s *LocalServer) AttachHook(handler http.Handler) (url string, detach func())

AttachHook setups handler such that it gets called when a request arrives at the returned url.

func (*LocalServer) ListenAndServe

func (s *LocalServer) ListenAndServe() error

ListenAndServe starts the local server listening

func (*LocalServer) Stop

func (s *LocalServer) Stop()

Stop will stop serving requests

type LocalTunnel added in v0.0.11

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

LocalTunnel is a WebHookServer implementation based on localtunnel.me

Useful when testing on localhost, should obviously never be used in production due to stability, security and scalability constraints.

func NewLocalTunnel added in v0.0.11

func NewLocalTunnel(baseURL string) (*LocalTunnel, error)

NewLocalTunnel creates a LocalTunnel

Defaults to localtunnel.me if no baseURL is specified.

func (*LocalTunnel) AttachHook added in v0.0.11

func (lt *LocalTunnel) AttachHook(handler http.Handler) (url string, detach func())

AttachHook setups handler such that it gets called when a request arrives at the returned url.

func (*LocalTunnel) Stop added in v0.0.11

func (lt *LocalTunnel) Stop()

Stop will close the localtunnel and break all connections

type Server added in v0.0.11

type Server interface {
	WebHookServer
	Stop()
}

Server abstracts various WebHookServer implementations

func NewServer added in v0.0.11

func NewServer(config interface{}, credentials *tcclient.Credentials) (Server, error)

NewServer returns a Server implementing WebHookServer, choosing the implemetation based on the configuration passed in. Config passed must match ConfigSchema. Credentials are required if the WebhookServer is Webhooktunnel.

type TestServer

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

TestServer is a WebHookServer implementation that exposes webhooks on a random port on localhost for testing.

func NewTestServer

func NewTestServer() (*TestServer, error)

NewTestServer returns a LocalServer running on a random port on localhost, this is exclusively for writing tests.

func (*TestServer) AttachHook

func (s *TestServer) AttachHook(handler http.Handler) (url string, detach func())

AttachHook setups handler such that it gets called when a request arrives at the returned url.

func (*TestServer) Stop

func (s *TestServer) Stop()

Stop will stop serving requests

type WebHookServer

type WebHookServer interface {
	AttachHook(handler http.Handler) (url string, detach func())
}

A WebHookServer can serve web hooks exposed to the public internet.

A hook is attached with:

url, detach := AttachHook(handler)

where url is the url at which the hook is exposed to the internet, and detach is a function that can be called to detatch the web hook.

When a request to any suffix of the url is called the request is modifed to have resource as the suffix, and then forwarded to the given handler. For example, if url = "http://localhost:8080/test/", then a request to "http://localhost:8080/test/<suffix>" will be given to the handler as a request for "/<suffix>".

This is useful for interactive web hooks like livelog, interactive shell and display.

type WebHookSet

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

A WebHookSet wraps a WebHookServer such that all hooks can be detached when the WebHookSet is disposed. This is useful for scoping a hook to a task-cycle.

func NewWebHookSet

func NewWebHookSet(server WebHookServer) *WebHookSet

NewWebHookSet returns a new WebHookSet wrapping the given WebHookServer

func (*WebHookSet) AttachHook

func (s *WebHookSet) AttachHook(handler http.Handler) (url string)

AttachHook returns a url-prefix for which requests will be given to handler.

func (*WebHookSet) Dispose

func (s *WebHookSet) Dispose()

Dispose clears all hooks attached through this WebHookSet

type WebhookTunnel added in v0.1.6

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

WebhookTunnel wraps a whclient instance as a WebHookServer

func NewWebhookTunnel added in v0.1.6

func NewWebhookTunnel(credentials *tcclient.Credentials) (*WebhookTunnel, error)

NewWebhookTunnel returns a pointer to a new WebhookTunnel instance

func (*WebhookTunnel) AttachHook added in v0.1.6

func (wt *WebhookTunnel) AttachHook(handler http.Handler) (string, func())

AttachHook adds a new webhook to the server

func (*WebhookTunnel) Stop added in v0.1.6

func (wt *WebhookTunnel) Stop()

Stop will close the webhooktunnel client

Jump to

Keyboard shortcuts

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