Skip to content

Commit

Permalink
connect: user/pass environment variables as const
Browse files Browse the repository at this point in the history
We need this environment variables for `tt-ee` modules.

Part of tarantool/roadmap-internal#281
  • Loading branch information
oleg-jukovec committed Oct 24, 2023
1 parent d7e1b4e commit 1cf128e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cli/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (
)

const (
usernameEnv = "TT_CLI_USERNAME"
passwordEnv = "TT_CLI_PASSWORD"
userpassRe = `[^@:/]+:[^@:/]+`
// userPathRe is a regexp for a username:password pair.
userpassRe = `[^@:/]+:[^@:/]+`

// uriPathPrefixRe is a regexp for a path prefix in uri, such as `scheme://path``.
uriPathPrefixRe = `((~?/+)|((../+)*))?`
Expand Down Expand Up @@ -70,8 +69,8 @@ func NewConnectCmd() *cobra.Command {
Short: "Connect to the tarantool instance",
Long: "Connect to the tarantool instance.\n\n" +
"The command supports the following environment variables:\n\n" +
"* " + usernameEnv + " - specifies a username\n" +
"* " + passwordEnv + " - specifies a password\n" +
"* " + connect.TarantoolUsernameEnv + " - specifies a username\n" +
"* " + connect.TarantoolPasswordEnv + " - specifies a password\n" +
"\n" +
"You could pass command line arguments to the interpreted SCRIPT" +
" or COMMAND passed via -f flag:\n\n" +
Expand Down Expand Up @@ -271,10 +270,10 @@ func resolveConnectOpts(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts,
} else if isBaseURI(args[0]) {
// Environment variables do not overwrite values.
if connectCtx.Username == "" {
connectCtx.Username = os.Getenv(usernameEnv)
connectCtx.Username = os.Getenv(connect.TarantoolUsernameEnv)
}
if connectCtx.Password == "" {
connectCtx.Password = os.Getenv(passwordEnv)
connectCtx.Password = os.Getenv(connect.TarantoolPasswordEnv)
}
network, address := parseBaseURI(args[0])
connOpts = makeConnOpts(network, address, *connectCtx)
Expand Down
8 changes: 8 additions & 0 deletions cli/connect/const.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package connect

// TarantoolUsernameEnv is an environment variable with a username for
// Tarantool.
const TarantoolUsernameEnv = "TT_CLI_USERNAME"

// TarantoolPasswordEnv is an environment variable with a password for
// Tarantool.
const TarantoolPasswordEnv = "TT_CLI_PASSWORD"

// setLanguagePrefix is used to set a language in the Tarantool console.
const setLanguagePrefix = "\\set language"

Expand Down

0 comments on commit 1cf128e

Please sign in to comment.