Use dbcmd.WithPrintFormat only for preview of teleterm gateway command#39906
Merged
Use dbcmd.WithPrintFormat only for preview of teleterm gateway command#39906
Conversation
1549626 to
17944a2
Compare
greedy52
approved these changes
Mar 28, 2024
Member
Author
|
@probakowski Ping, we have a customer waiting for this fix. |
probakowski
approved these changes
Mar 29, 2024
|
@ravicious See the table below for backport results.
|
This was referenced Mar 29, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.WithPrintFormatwhen 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.GetGatewayCLICommandreturns twoexec.Cmds: 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.Cmdthat 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.