Skip to content

Commit

Permalink
Fix "tsh db connect" with "mariadb" when proxy is in seperate port mo…
Browse files Browse the repository at this point in the history
…de (#20353)
  • Loading branch information
greedy52 authored Jan 18, 2023
1 parent 4261e86 commit b901ace
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/client/db/dbcmd/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ func (c *CLICommandBuilder) getMariaDBArgs() []string {
return args
}

// Some options used in the MySQL options file are not compatible with the
// "mariadb" client. Thus instead of using `--defaults-group-suffix=`,
// specify the proxy host and port directly as parameters. When
// localProxyPort is specified, the --port and --host flags are set by
// getMySQLCommonCmdOpts.
if c.options.localProxyPort == 0 {
host, port := c.tc.MySQLProxyHostPort()
args = append(args, "--port", strconv.Itoa(port))
args = append(args, "--host", host)
}

sslCertPath := c.profile.DatabaseCertPathForCluster(c.tc.SiteName, c.db.ServiceName)

args = append(args, []string{"--ssl-key", c.profile.KeyPath()}...)
Expand Down
21 changes: 21 additions & 0 deletions lib/client/db/dbcmd/dbcmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,27 @@ func TestCLICommandBuilderGetConnectCommand(t *testing.T) {
"--protocol", "TCP"},
wantErr: false,
},
{
name: "mariadb (remote proxy)",
dbProtocol: defaults.ProtocolMySQL,
databaseName: "mydb",
opts: []ConnectCommandFunc{WithLocalProxy("", 0, "") /* negate default WithLocalProxy*/},
execer: &fakeExec{
execOutput: map[string][]byte{
"mariadb": []byte(""),
},
},
cmd: []string{"mariadb",
"--user", "myUser",
"--database", "mydb",
"--port", "3036",
"--host", "proxy.example.com",
"--ssl-key", "/tmp/keys/example.com/bob",
"--ssl-ca", "/tmp/keys/example.com/cas/root.pem",
"--ssl-cert", "/tmp/keys/example.com/bob-db/db.example.com/mysql-x509.pem",
"--ssl-verify-server-cert"},
wantErr: false,
},
{
name: "mongodb (legacy)",
dbProtocol: defaults.ProtocolMongoDB,
Expand Down

0 comments on commit b901ace

Please sign in to comment.