Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1687

Allow uri_parser to render a working connection string after validation

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Config
    • Labels:
    • Fully Compatible

      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. 

            Unassigned Unassigned
            andrew.hodgson@digital.hmrc.gov.uk Andrew Hodgson
            0 Vote for this issue
            3 Start watching this issue