Use dbcmd.WithPrintFormat only for preview of teleterm gateway command #39906
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #39836.
Changelog: Fixed "Invalid URI" error when starting mongosh from database connection tab in Teleport Connect
Currently lib/teleterm uses
dbcmd.WithPrintFormat
when generating db commands. This option is meant to be used when the command is printed rather than executed, i.e.tsh db config --format cmd
. It wraps connection strings in quotes. This way when the user copies a command and tries to execute it in a shell, the shell doesn't interpret certain characters in the connection string as special characters.This worked in Connect because for a long time we did put those commands directly into a shell. However, in #26441 we switched to spawning CLI clients directly, which means that the quotes are at best unnecessary and at worst cause problems like the one described in #39836.
To fix this,
daemon.Service.GetGatewayCLICommand
returns twoexec.Cmd
s: one that doesn't use the print format and one that does. The one that does use the print format should be used forapi.GatewayCLICommand.Preview
, while other fields should come from theexec.Cmd
that doesn't use the print format.This way when the user clicks "Run", we execute the command without the quotes. But in the UI we display the version with the quotes, so that the user can simply copy and paste the command somewhere outside of Teleport Connect.
At the moment it mostly affects Mongodb. Looking at dbcmd, I don't think other protocols were affected.