mirror of
https://github.com/gravitational/teleport
synced 2024-10-21 01:34:01 +00:00
feat(dbcmd): add sqlcmd
support (#28918)
This commit is contained in:
parent
800e79b113
commit
caacc54696
|
@ -60,6 +60,8 @@ const (
|
|||
redisBin = "redis-cli"
|
||||
// mssqlBin is the SQL Server client program name.
|
||||
mssqlBin = "mssql-cli"
|
||||
// sqlcmd is the SQL Server client program name.
|
||||
sqlcmdBin = "sqlcmd"
|
||||
// snowsqlBin is the Snowflake client program name.
|
||||
snowsqlBin = "snowsql"
|
||||
// cqlshBin is the Cassandra client program name.
|
||||
|
@ -429,6 +431,12 @@ func (c *CLICommandBuilder) isMySQLBinMariaDBFlavor() (bool, error) {
|
|||
return strings.Contains(strings.ToLower(string(mysqlVer)), "mariadb"), nil
|
||||
}
|
||||
|
||||
// isSqlcmdAvailable returns true if "sqlcmd" binary is fouind in the system
|
||||
// PATH.
|
||||
func (c *CLICommandBuilder) isSqlcmdAvailable() bool {
|
||||
return c.isBinAvailable(sqlcmdBin)
|
||||
}
|
||||
|
||||
func (c *CLICommandBuilder) shouldUseMongoshBin() bool {
|
||||
// Use "mongosh" if available.
|
||||
// If not, use legacy "mongo" if available.
|
||||
|
@ -554,6 +562,8 @@ func (c *CLICommandBuilder) getRedisCommand() *exec.Cmd {
|
|||
return exec.Command(redisBin, args...)
|
||||
}
|
||||
|
||||
// getSQLServerCommand returns a command to connect to SQL Server.
|
||||
// mssql-cli and sqlcmd commands have the same argument names.
|
||||
func (c *CLICommandBuilder) getSQLServerCommand() *exec.Cmd {
|
||||
args := []string{
|
||||
// Host and port must be comma-separated.
|
||||
|
@ -568,6 +578,10 @@ func (c *CLICommandBuilder) getSQLServerCommand() *exec.Cmd {
|
|||
args = append(args, "-d", c.db.Database)
|
||||
}
|
||||
|
||||
if c.isSqlcmdAvailable() {
|
||||
return exec.Command(sqlcmdBin, args...)
|
||||
}
|
||||
|
||||
return exec.Command(mssqlBin, args...)
|
||||
}
|
||||
|
||||
|
|
|
@ -416,6 +416,23 @@ func TestCLICommandBuilderGetConnectCommand(t *testing.T) {
|
|||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "sqlserver sqlcmd",
|
||||
dbProtocol: defaults.ProtocolSQLServer,
|
||||
databaseName: "mydb",
|
||||
execer: &fakeExec{
|
||||
execOutput: map[string][]byte{
|
||||
"sqlcmd": {},
|
||||
},
|
||||
},
|
||||
cmd: []string{sqlcmdBin,
|
||||
"-S", "localhost,12345",
|
||||
"-U", "myUser",
|
||||
"-P", fixtures.UUID,
|
||||
"-d", "mydb",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "redis-cli",
|
||||
dbProtocol: defaults.ProtocolRedis,
|
||||
|
|
Loading…
Reference in a new issue