connect

package module
v0.0.0-...-9997ea8 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package connect parses tt connection strings and URIs and resolves the credentials used to connect to Tarantool and etcd.

The API of this package is alpha and may change incompatibly.

Index

Constants

View Source
const (
	EnvSdkUsername = "TT_CLI_EE_USERNAME"
	EnvSdkPassword = "TT_CLI_EE_PASSWORD" //nolint:gosec // The name of a variable, not a secret.
)
View Source
const (
	TCPNetwork  = "tcp"
	UnixNetwork = "unix"
)
View Source
const EnvEtcdCredentialsHelp = "The command supports the following Etcd environment variables:\n" +
	"* " + EtcdUsernameEnv + " - specifies a Etcd username\n" +
	"* " + EtcdPasswordEnv + " - specifies a Etcd password"
View Source
const EnvTarantoolCredentialsHelp = "The command supports the following " +
	"Tarantool environment variables:\n" +
	"* " + TarantoolUsernameEnv + " - specifies a Tarantool username\n" +
	"* " + TarantoolPasswordEnv + " - specifies a Tarantool password"
View Source
const EtcdPasswordEnv = "TT_CLI_ETCD_PASSWORD" //nolint:gosec // A variable name, not a secret.

EtcdPasswordEnv is an environment variable with a password for etcd.

View Source
const EtcdUsernameEnv = "TT_CLI_ETCD_USERNAME"

EtcdUsernameEnv is an environment variable with a username for etcd.

View Source
const (

	// Redacted is what RedactCredentials replaces the credentials with.
	Redacted = "[REDACTED]"
)
View Source
const TarantoolPasswordEnv = "TT_CLI_PASSWORD"

TarantoolPasswordEnv is an environment variable with a password for Tarantool.

View Source
const TarantoolUsernameEnv = "TT_CLI_USERNAME"

TarantoolUsernameEnv is an environment variable with a username for Tarantool.

Variables

This section is empty.

Functions

func IsBaseURI

func IsBaseURI(str string) bool

IsBaseURI returns true if a string is a valid URI.

func IsCredentialsURI

func IsCredentialsURI(str string) bool

IsCredentialsURI returns true if a string is a valid credentials URI.

func MakeURLHelp

func MakeURLHelp(data map[string]any) string

MakeURLHelp returns a part of command help message related to URL arguments. The function uses a template to generate the message. Accepts following placeholders in the `data` map:

`header` - string: a header for the help message;
`footer` - string: a final message of the help;
`service` - string: name of the service to connect with URL;
`url_path` - string: custom URL path format (e.g., "/prefix/host-name/worker-name");
`prefix` - string: a base path used by service application;
`path_<name>` - string: description for a URL path component with <name>;
`tag` - string: description how `#fragment` part used by application;
`param_<name>` - string: description for an extra URL param with <name> added to help;
`env_<name>_auth` - string: service info. It will expanded to:
	* <name>_USERNAME - specifies a <info> username;
	* <name>_PASSWORD - specifies a <info> password.
`env_<name>` - string: description for an extra environment variable with <name>:
	* <name> - <description>.

func ParseBaseURI

func ParseBaseURI(uri string) (string, string)

ParseBaseURI parses an URI and returns: (network, address).

func ParseCredentialsURI

func ParseCredentialsURI(str string) (string, string, string)

ParseCredentialsURI parses a URI with credentials and returns: (URI without credentials, user, password).

func RedactCredentials

func RedactCredentials(str string) string

RedactCredentials returns a target (a URI, or anything a user typed in the place of one) fit to be shown in a message: if it holds credentials, that is an "@", everything before the last "@" other than the scheme is replaced by Redacted. The string is not parsed, so it works for what no parser accepts: a password with a "/" or an unescaped "@", and a piece of a URI cut at a ":", such as the "instance" of user:password@host:port. The price is that an "@" in the query hides the host as well.

func SplitURIQuery

func SplitURIQuery(uri string) (string, url.Values, error)

SplitURIQuery splits the query off a base URI that has one, as host:port?transport=ssl, tcp://host:port?k=v and unix/:path?k=v, and returns the URI without it and the parameters. A URI without a query is returned as it is, with no parameters. The path forms (./path, /path, ~/path, ../path, unix://path) are returned as they are: a "?" there is a part of the path.

The error does not quote the query, which may hold a password.

Types

type URIOpts

type URIOpts struct {
	// Endpoint is a an endpoint to connect: [scheme://]host[:port].
	Endpoint string
	// Scheme is the scheme part of the URI (for example, "tcp" or "https").
	Scheme string
	// Host is a an address to connect: host[:port].
	Host string
	// Prefix is a configuration prefix.
	Prefix string
	// Tag value of #fragment URL part.
	Tag string
	// Username is a user name for authorization.
	Username string
	// Password is a password for authorization.
	Password string
	// KeyFile is a path to a private SSL key file.
	KeyFile string
	// CertFile is a path to an SSL certificate file.
	CertFile string
	// CaPath is a path to a trusted certificate authorities (CA) directory.
	CaPath string
	// CaFile is a path to a trusted certificate authorities (CA) file.
	CaFile string
	// Ciphers is a colon-separated (:) list of SSL cipher suites the
	// connection can use.
	Ciphers string
	// SkipHostVerify controls whether a client verifies the server's
	// host name. This is dangerous option so by default it is false.
	SkipHostVerify bool
	// SkipHostVerify controls whether a client verifies the server's
	// certificate chain. This is dangerous option so by default it is false.
	SkipPeerVerify bool
	// Timeout is a timeout for actions.
	Timeout time.Duration
	// Params keeps extra URL parameters.
	Params map[string]string
}

URIOpts is a universal list of connect options retrieved from a URI.

func CreateURIOpts

func CreateURIOpts(url string) (URIOpts, error)

CreateURIOpts parses a URL string and creates appropriate URIOpts.

type UserCredentials

type UserCredentials struct {
	Username string
	Password string
}

func GetCreds

func GetCreds(credPath string) (UserCredentials, error)

GetCreds gets credentials for tarantool-ee download.

Jump to

Keyboard shortcuts

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