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
- func IsBaseURI(str string) bool
- func IsCredentialsURI(str string) bool
- func MakeURLHelp(data map[string]any) string
- func ParseBaseURI(uri string) (string, string)
- func ParseCredentialsURI(str string) (string, string, string)
- func RedactCredentials(str string) string
- func SplitURIQuery(uri string) (string, url.Values, error)
- type URIOpts
- type UserCredentials
Constants ¶
const ( EnvSdkUsername = "TT_CLI_EE_USERNAME" EnvSdkPassword = "TT_CLI_EE_PASSWORD" //nolint:gosec // The name of a variable, not a secret. )
const ( TCPNetwork = "tcp" UnixNetwork = "unix" )
const EnvEtcdCredentialsHelp = "The command supports the following Etcd environment variables:\n" + "* " + EtcdUsernameEnv + " - specifies a Etcd username\n" + "* " + EtcdPasswordEnv + " - specifies a Etcd password"
const EnvTarantoolCredentialsHelp = "The command supports the following " + "Tarantool environment variables:\n" + "* " + TarantoolUsernameEnv + " - specifies a Tarantool username\n" + "* " + TarantoolPasswordEnv + " - specifies a Tarantool password"
const EtcdPasswordEnv = "TT_CLI_ETCD_PASSWORD" //nolint:gosec // A variable name, not a secret.
EtcdPasswordEnv is an environment variable with a password for etcd.
const EtcdUsernameEnv = "TT_CLI_ETCD_USERNAME"
EtcdUsernameEnv is an environment variable with a username for etcd.
const (
// Redacted is what RedactCredentials replaces the credentials with.
Redacted = "[REDACTED]"
)
const TarantoolPasswordEnv = "TT_CLI_PASSWORD"
TarantoolPasswordEnv is an environment variable with a password for Tarantool.
const TarantoolUsernameEnv = "TT_CLI_USERNAME"
TarantoolUsernameEnv is an environment variable with a username for Tarantool.
Variables ¶
This section is empty.
Functions ¶
func IsCredentialsURI ¶
IsCredentialsURI returns true if a string is a valid credentials URI.
func MakeURLHelp ¶
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 ¶
ParseBaseURI parses an URI and returns: (network, address).
func ParseCredentialsURI ¶
ParseCredentialsURI parses a URI with credentials and returns: (URI without credentials, user, password).
func RedactCredentials ¶
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 ¶
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 ¶
CreateURIOpts parses a URL string and creates appropriate URIOpts.
type UserCredentials ¶
func GetCreds ¶
func GetCreds(credPath string) (UserCredentials, error)
GetCreds gets credentials for tarantool-ee download.