{"modulePath":"github.com/taskcluster/taskcluster-worker","version":"v0.1.20","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package webhookserver\n\nPackage webhookserver provides implementations of the WebHookServer interface. Which allows attachment and detachment for web-hooks to an internet exposed server.\n\nThe 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.\n\nWebhooktunnel 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.\n\n## Variables\n\n```go\nvar ConfigSchema schematypes.Schema = schematypes.OneOf{\n\tlocalhostConfigSchema,\n\tlocaltunnelConfigSchema,\n\tstatelessDNSConfigSchema,\n\twebhooktunnelConfigSchema,\n}\n```\nConfigSchema specifies schema for configuration passed to NewServer.\n\n## Types\n\n```go\ntype LocalServer struct {\n\t// contains filtered or unexported fields\n}\n```\nLocalServer is a WebHookServer implementation that exposes webhooks on a local port directly exposed to the internet.\n\n```go\nfunc NewLocalServer(\n\tpublicIP []byte,\n\tpublicPort int,\n\tnetworkInterface string,\n\tlocalPort int,\n\tsubdomain, dnsSecret, tlsCert, tlsKey string,\n\texpiration time.Duration,\n) (*LocalServer, error)\n```\nNewLocalServer creates a WebHookServer that listens on publicIP, publicPort and uses stateless-dns-server to obtain a hostname.\n\nIf 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.\n\n```go\nfunc (s *LocalServer) AttachHook(handler http.Handler) (url string, detach func())\n```\nAttachHook setups handler such that it gets called when a request arrives at the returned url.\n\n```go\nfunc (s *LocalServer) ListenAndServe() error\n```\nListenAndServe starts the local server listening\n\n```go\nfunc (s *LocalServer) Stop()\n```\nStop will stop serving requests\n\n```go\ntype LocalTunnel struct {\n\t// contains filtered or unexported fields\n}\n```\nLocalTunnel is a WebHookServer implementation based on localtunnel.me\n\nUseful when testing on localhost, should obviously never be used in production due to stability, security and scalability constraints.\n\n```go\nfunc NewLocalTunnel(baseURL string) (*LocalTunnel, error)\n```\nNewLocalTunnel creates a LocalTunnel\n\nDefaults to localtunnel.me if no baseURL is specified.\n\n```go\nfunc (lt *LocalTunnel) AttachHook(handler http.Handler) (url string, detach func())\n```\nAttachHook setups handler such that it gets called when a request arrives at the returned url.\n\n```go\nfunc (lt *LocalTunnel) Stop()\n```\nStop will close the localtunnel and break all connections\n\n```go\ntype Server interface {\n\tWebHookServer\n\tStop()\n}\n```\nServer abstracts various WebHookServer implementations\n\n```go\nfunc NewServer(config interface{}, credentials *tcclient.Credentials) (Server, error)\n```\nNewServer 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.\n\n```go\ntype TestServer struct {\n\t// contains filtered or unexported fields\n}\n```\nTestServer is a WebHookServer implementation that exposes webhooks on a random port on localhost for testing.\n\n```go\nfunc NewTestServer() (*TestServer, error)\n```\nNewTestServer returns a LocalServer running on a random port on localhost, this is exclusively for writing tests.\n\n```go\nfunc (s *TestServer) AttachHook(handler http.Handler) (url string, detach func())\n```\nAttachHook setups handler such that it gets called when a request arrives at the returned url.\n\n```go\nfunc (s *TestServer) Stop()\n```\nStop will stop serving requests\n\n```go\ntype WebHookServer interface {\n\tAttachHook(handler http.Handler) (url string, detach func())\n}\n```\nA WebHookServer can serve web hooks exposed to the public internet.\n\nA hook is attached with:\n\n\turl, detach := AttachHook(handler)\n\nwhere 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.\n\nWhen 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/](http://localhost:8080/test/)\", then a request to \"[http://localhost:8080/test/](http://localhost:8080/test/)\\\u003csuffix\u003e\" will be given to the handler as a request for \"/\\\u003csuffix\u003e\".\n\nThis is useful for interactive web hooks like livelog, interactive shell and display.\n\n```go\ntype WebHookSet struct {\n\t// contains filtered or unexported fields\n}\n```\nA 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.\n\n```go\nfunc NewWebHookSet(server WebHookServer) *WebHookSet\n```\nNewWebHookSet returns a new WebHookSet wrapping the given WebHookServer\n\n```go\nfunc (s *WebHookSet) AttachHook(handler http.Handler) (url string)\n```\nAttachHook returns a url-prefix for which requests will be given to handler.\n\n```go\nfunc (s *WebHookSet) Dispose()\n```\nDispose clears all hooks attached through this WebHookSet\n\n```go\ntype WebhookTunnel struct {\n\t// contains filtered or unexported fields\n}\n```\nWebhookTunnel wraps a whclient instance as a WebHookServer\n\n```go\nfunc NewWebhookTunnel(credentials *tcclient.Credentials) (*WebhookTunnel, error)\n```\nNewWebhookTunnel returns a pointer to a new WebhookTunnel instance\n\n```go\nfunc (wt *WebhookTunnel) AttachHook(handler http.Handler) (string, func())\n```\nAttachHook adds a new webhook to the server\n\n```go\nfunc (wt *WebhookTunnel) Stop()\n```\nStop will close the webhooktunnel client\n\n","path":"github.com/taskcluster/taskcluster-worker/runtime/webhookserver","name":"webhookserver","synopsis":"Package webhookserver provides implementations of the WebHookServer interface.","isRedistributable":true}
