Documentation ¶
Overview ¶
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 ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigSchema schematypes.Schema = schematypes.OneOf{
localhostConfigSchema,
localtunnelConfigSchema,
statelessDNSConfigSchema,
}
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
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
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.
type WebHookServer ¶
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