As part of our work enabling teams to use credentials from Hashicorp Vault to connect to MongoDB, we have created our own code to handle inserting these credentials at deploy time and outputting a working connection string to be used as an environment variable.
It might be worthwhile to move this functionality into the uri_parser module, perhaps as a `render_uri` function. It would take an already-parsed URI dictionary and outputs a working connection string with the same values.
We discovered that due to how the URI components are parsed, a straightforward printing of the internal representation of these components does not derive a working connection string, e.g. options for read preference becomes a dictionary. One consequence of our work was to keep the original options string and append this to the new connection string containing credentials. If this is done after validation the operation seems to be relatively safe. Choices like this would benefit from review from the community.
By accounting for different URI contents in the uri_parser test cases we were able to make our code more robust. The set of URI components we support are much less than those required by the driver in the wild, and the current set of test cases document the variety of URIs that have to be able to be printed. By using these we can create a good set of test cases for URI rendering.
Some of this work has already been done, so this ticket is being created to gauge interest in finishing the work and creating a pull request.