taskcluster-worker: github.com/taskcluster/taskcluster-worker/runtime/webhookserver Index | Files

package webhookserver

import "github.com/taskcluster/taskcluster-worker/runtime/webhookserver"

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

The simpliest 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.

Index

Package Files

config.go doc.go localserver.go localtunnel.go testserver.go webhookserver.go webhookset.go

Variables

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

ConfigSchema specifies schema for configuration passed to NewServer.

type LocalServer Uses

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 Uses

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 Uses

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 Uses

func (s *LocalServer) ListenAndServe() error

ListenAndServe starts the local server listening

func (*LocalServer) Stop Uses

func (s *LocalServer) Stop()

Stop will stop serving requests

type LocalTunnel Uses

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 Uses

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

NewLocalTunnel creates a LocalTunnel

Defaults to localtunnel.me if no baseURL is specified.

func (*LocalTunnel) AttachHook Uses

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 Uses

func (lt *LocalTunnel) Stop()

Stop will close the localtunnel and break all connections

type Server Uses

type Server interface {
    WebHookServer
    Stop()
}

Server abstracts various WebHookServer implementations

func NewServer Uses

func NewServer(config interface{}) (Server, error)

NewServer returns a Server implementing WebHookServer, choosing the implemetation based on the configuration passed in.

Config passed must match ConfigSchema.

type TestServer Uses

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 Uses

func NewTestServer() (*TestServer, error)

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

func (*TestServer) AttachHook Uses

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 Uses

func (s *TestServer) Stop()

Stop will stop serving requests

type WebHookServer Uses

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 Uses

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 Uses

func NewWebHookSet(server WebHookServer) *WebHookSet

NewWebHookSet returns a new WebHookSet wrapping the given WebHookServer

func (*WebHookSet) AttachHook Uses

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 Uses

func (s *WebHookSet) Dispose()

Dispose clears all hooks attached through this WebHookSet

Package webhookserver imports 13 packages (graph) and is imported by 3 packages. Updated 2017-04-26. Refresh now. Tools for package owners.