Documentation ¶
Index ¶
- func AddrToURL(addr string) (*url.URL, error)
- func AssertServerVersion(pong proto.PingResponse, minVersion string) error
- func Bail(err error)
- func BuildURLPath(args ...interface{}) string
- func DownloadAndCheck(ctx context.Context, url string, out io.Writer, checksum SHA256Sum) error
- func FromGRPC(err error) error
- func IsCanceled(err error) bool
- func IsDeadline(err error) bool
- func IsEmail(str string) bool
- func MarkdownEscape(t string, n int) string
- func NewIdentityFileWatcher(ctx context.Context, path string, interval time.Duration) (*client.DynamicIdentityFileCreds, error)
- func PrintVersion(appName string, version string, gitref string)
- func ReadPassword(filename string) (string, error)
- func ServeSignals(app Terminable, shutdownTimeout time.Duration)
- type HTTP
- func (h *HTTP) BaseURL() *url.URL
- func (h *HTTP) EnsureCert(defaultPath string) error
- func (h *HTTP) ListenAndServe(ctx context.Context) error
- func (h *HTTP) NewURL(subpath string, values url.Values) *url.URL
- func (h *HTTP) ServiceJob() ServiceJob
- func (h *HTTP) Shutdown(ctx context.Context) error
- func (h *HTTP) ShutdownWithTimeout(ctx context.Context, duration time.Duration) error
- type HTTPBasicAuth
- type HTTPBasicAuthConfig
- type HTTPConfig
- type Job
- type Process
- func (p *Process) Close()
- func (p *Process) CriticalError() error
- func (p *Process) Done() <-chan struct{}
- func (p *Process) OnTerminate(fn func(ctx context.Context) error)
- func (p *Process) Shutdown(ctx context.Context) error
- func (p *Process) Spawn(fn func(ctx context.Context) error)
- func (p *Process) SpawnCritical(fn func(ctx context.Context) error)
- func (p *Process) SpawnCriticalJob(job Job)
- func (p *Process) SpawnJob(job Job)
- func (p *Process) Terminate()
- type SHA256
- type SHA256Sum
- type ServiceJob
- type TLSConfig
- type TeleportConfig
- type Terminable
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddrToURL ¶
AddrToURL transforms an address string that may or may not contain a leading protocol or trailing port number into a well-formed URL
func AssertServerVersion ¶
func AssertServerVersion(pong proto.PingResponse, minVersion string) error
AssertServerVersion returns an error if server version in ping response is less than minimum required version.
func BuildURLPath ¶
func BuildURLPath(args ...interface{}) string
BuildURLPath returns a URI with args represented as query params If any supplied argument is not a string, BuildURLPath will use fmt.Sprintf(value) to stringify it.
func DownloadAndCheck ¶
DownloadAndCheck gets a file from the Internet and checks its SHA256 sum.
func IsCanceled ¶
TODO: remove this when trail.FromGRPC will understand additional error codes
func IsDeadline ¶
TODO: remove this when trail.FromGRPC will understand additional error codes
func MarkdownEscape ¶
MarkdownEscape wraps some text `t` in triple backticks (escaping any backtick inside the message), limiting the length of the message to `n` runes (inside the single preformatted block). The text is trimmed before escaping. Backticks are escaped and thus count as two runes for the purpose of the truncation.
Example ¶
fmt.Printf("%q\n", MarkdownEscape(" ", 1000)) fmt.Printf("%q\n", MarkdownEscape("abc", 1000)) fmt.Printf("%q\n", MarkdownEscape("`foo` `bar`", 1000)) fmt.Printf("%q\n", MarkdownEscape(" 123456789012345 ", 10))
Output: "(empty)" "```\nabc```" "```\n`\ufefffoo`\ufeff `\ufeffbar`\ufeff```" "```\n1234567890``` (truncated)"
func NewIdentityFileWatcher ¶
func NewIdentityFileWatcher(ctx context.Context, path string, interval time.Duration) (*client.DynamicIdentityFileCreds, error)
NewIdentityFileWatcher returns a credential compatible with the Teleport client. This credential will reload from the identity file at the specified path each time interval time passes. This function blocks until the initial credential has been loaded and then returns, creating a goroutine in the background to manage the reloading that will exit when ctx is canceled.
func PrintVersion ¶
PrintVersion prints the specified app version to STDOUT
func ReadPassword ¶
ReadPassword reads password from file or env var, trims and returns
func ServeSignals ¶
func ServeSignals(app Terminable, shutdownTimeout time.Duration)
Types ¶
type HTTP ¶
type HTTP struct { HTTPConfig *httprouter.Router // contains filtered or unexported fields }
HTTP is a tiny wrapper around standard net/http. It starts either insecure server or secure one with TLS, depending on the settings. It also adds a context to its handlers and the server itself has context to. So you are guaranteed that server will be closed when the context is canceled.
func (*HTTP) EnsureCert ¶
EnsureCert checks cert and key files consistency.
func (*HTTP) ListenAndServe ¶
ListenAndServe runs a http(s) server on a provided port.
func (*HTTP) ServiceJob ¶
func (h *HTTP) ServiceJob() ServiceJob
ServiceJob creates a service job for the HTTP service, wraps it with a termination handler so it shuts down and logs when it quits.
type HTTPBasicAuth ¶
type HTTPBasicAuth struct { HTTPBasicAuthConfig // contains filtered or unexported fields }
HTTPBasicAuth wraps a http.Handler with HTTP Basic Auth check.
func (*HTTPBasicAuth) ServeHTTP ¶
func (auth *HTTPBasicAuth) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP processes one http request.
type HTTPBasicAuthConfig ¶
HTTPBasicAuthConfig stores configuration for HTTP Basic Authentication
type HTTPConfig ¶
type HTTPConfig struct { ListenAddr string `toml:"listen_addr"` PublicAddr string `toml:"public_addr"` KeyFile string `toml:"https_key_file"` CertFile string `toml:"https_cert_file"` BasicAuth HTTPBasicAuthConfig `toml:"basic_auth"` TLS TLSConfig `toml:"tls"` Insecure bool }
HTTPConfig stores configuration of an HTTP service including it's public address, listen host and port, TLS certificate and key path, and extra TLS configuration options, represented as TLSConfig.
func (*HTTPConfig) BaseURL ¶
func (conf *HTTPConfig) BaseURL() (*url.URL, error)
BaseURL builds a base url depending on "public_addr" parameter.
func (*HTTPConfig) Check ¶
func (conf *HTTPConfig) Check() error
Check validates the http server configuration.
type Job ¶
func MustGetJob ¶
type Process ¶
func MustGetProcess ¶
func NewProcess ¶
func (*Process) CriticalError ¶
func (*Process) Done ¶
func (p *Process) Done() <-chan struct{}
Done channel is used to wait for jobs completion.
func (*Process) Shutdown ¶
Shutdown signals a process to terminate and waits for completion of all jobs.
func (*Process) SpawnCriticalJob ¶
type ServiceJob ¶
type ServiceJob interface { Job IsReady() bool SetReady(ready bool) WaitReady(ctx context.Context) (bool, error) Done() <-chan struct{} Err() error }
func MustGetServiceJob ¶
func MustGetServiceJob(ctx context.Context) ServiceJob
func NewServiceJob ¶
func NewServiceJob(fn func(ctx context.Context) error) ServiceJob
type TLSConfig ¶
type TLSConfig struct { VerifyClientCertificate bool `toml:"verify_client_cert"` VerifyClientCertificateFunc func(chains [][]*x509.Certificate) error }
TLSConfig stores TLS configuration for a http service
type TeleportConfig ¶
type TeleportConfig struct { // AuthServer specifies the address that the client should connect to. // Deprecated: replaced by Addr AuthServer string `toml:"auth_server"` Addr string `toml:"addr"` ClientKey string `toml:"client_key"` ClientCrt string `toml:"client_crt"` RootCAs string `toml:"root_cas"` Identity string `toml:"identity"` RefreshIdentity bool `toml:"refresh_identity"` RefreshIdentityInterval time.Duration `toml:"refresh_identity_interval"` }
TeleportConfig stores config options for where the Teleport's Auth server is listening, and what certificates to use to authenticate in it.
func (*TeleportConfig) CheckAndSetDefaults ¶
func (cfg *TeleportConfig) CheckAndSetDefaults() error
func (*TeleportConfig) CheckTLSConfig ¶
func (cfg *TeleportConfig) CheckTLSConfig() error