lib

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrToURL

func AddrToURL(addr string) (*url.URL, error)

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 Bail

func Bail(err error)

Bail exits with nonzero exit code and prints an error to a log.

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

func DownloadAndCheck(ctx context.Context, url string, out io.Writer, checksum SHA256Sum) error

DownloadAndCheck gets a file from the Internet and checks its SHA256 sum.

func FromGRPC

func FromGRPC(err error) error

TODO: remove this when trail.FromGRPC will understand additional error codes

func IsCanceled

func IsCanceled(err error) bool

TODO: remove this when trail.FromGRPC will understand additional error codes

func IsDeadline

func IsDeadline(err error) bool

TODO: remove this when trail.FromGRPC will understand additional error codes

func IsEmail

func IsEmail(str string) bool

func MarkdownEscape

func MarkdownEscape(t string, n int) string

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

func PrintVersion(appName string, version string, gitref string)

PrintVersion prints the specified app version to STDOUT

func ReadPassword

func ReadPassword(filename string) (string, error)

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 NewHTTP

func NewHTTP(config HTTPConfig) (*HTTP, error)

NewHTTP creates a new HTTP wrapper

func (*HTTP) BaseURL

func (h *HTTP) BaseURL() *url.URL

BaseURL returns an url on which the server is accessible externally.

func (*HTTP) EnsureCert

func (h *HTTP) EnsureCert(defaultPath string) error

EnsureCert checks cert and key files consistency.

func (*HTTP) ListenAndServe

func (h *HTTP) ListenAndServe(ctx context.Context) error

ListenAndServe runs a http(s) server on a provided port.

func (*HTTP) NewURL

func (h *HTTP) NewURL(subpath string, values url.Values) *url.URL

NewURL builds an external url for a specific path and query parameters.

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.

func (*HTTP) Shutdown

func (h *HTTP) Shutdown(ctx context.Context) error

Shutdown stops the server gracefully.

func (*HTTP) ShutdownWithTimeout

func (h *HTTP) ShutdownWithTimeout(ctx context.Context, duration time.Duration) error

ShutdownWithTimeout stops the server gracefully.

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

type HTTPBasicAuthConfig struct {
	Username string `toml:"user"`
	Password string `toml:"password"`
}

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

type Job interface {
	DoJob(context.Context) error
}

func MustGetJob

func MustGetJob(ctx context.Context) Job

type Process

type Process struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func MustGetProcess

func MustGetProcess(ctx context.Context) *Process

func NewProcess

func NewProcess(ctx context.Context) *Process

func (*Process) Close

func (p *Process) Close()

Close shuts down all process jobs immediately.

func (*Process) CriticalError

func (p *Process) CriticalError() error

func (*Process) Done

func (p *Process) Done() <-chan struct{}

Done channel is used to wait for jobs completion.

func (*Process) OnTerminate

func (p *Process) OnTerminate(fn func(ctx context.Context) error)

func (*Process) Shutdown

func (p *Process) Shutdown(ctx context.Context) error

Shutdown signals a process to terminate and waits for completion of all jobs.

func (*Process) Spawn

func (p *Process) Spawn(fn func(ctx context.Context) error)

func (*Process) SpawnCritical

func (p *Process) SpawnCritical(fn func(ctx context.Context) error)

func (*Process) SpawnCriticalJob

func (p *Process) SpawnCriticalJob(job Job)

func (*Process) SpawnJob

func (p *Process) SpawnJob(job Job)

func (*Process) Terminate

func (p *Process) Terminate()

Terminate signals a process to terminate. You should avoid spawning new jobs after termination.

type SHA256

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

func NewSHA256

func NewSHA256() SHA256

func (SHA256) Sum

func (s SHA256) Sum() SHA256Sum

func (SHA256) Write

func (s SHA256) Write(p []byte) (n int, err error)

type SHA256Sum

type SHA256Sum [sha256.Size]byte

func MustHexSHA256

func MustHexSHA256(str string) SHA256Sum

func ReadFileSHA256

func ReadFileSHA256(fileName string) (SHA256Sum, error)

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

func (TeleportConfig) NewClient

func (cfg TeleportConfig) NewClient(ctx context.Context) (*client.Client, error)

type Terminable

type Terminable interface {
	// Shutdown attempts to gracefully terminate.
	Shutdown(context.Context) error
	// Close does a fast (force) termination.
	Close()
}

Directories

Path Synopsis
testing

Jump to

Keyboard shortcuts

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