def parse_dsn(value: str) -> Optional[Dict[str, str]]:
    """
    Compatibility layer on top of function from psycopg2/psycopg3, which parses connection strings.
    In this function sets the `sslmode`, 'gssencmode', and `channel_binding` to `prefer`
    and `sslnegotiation` to `postgres` if they are not present in the connection string.
    This is necessary to simplify comparison of the old and the new values.

    >>> r = parse_dsn('postgresql://foo/postgres')
    >>> r == {'dbname': 'postgres', 'host': 'foo', 'sslmode': 'prefer', 'gssencmode': 'prefer',\
              'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    >>> r = parse_dsn(" host = 'host' dbname = db\\\\ name requiressl=1 ")
    >>> r == {'dbname': 'db name', 'host': 'host', 'sslmode': 'require',\
              'gssencmode': 'prefer', 'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    >>> parse_dsn('requiressl = 0\\\\') == {'sslmode': 'prefer', 'gssencmode': 'prefer',\
                                            'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    >>> parse_dsn('foo=bar') == {'foo': 'bar', 'sslmode': 'prefer', 'gssencmode': 'prefer',\
                                 'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    """
    ret = parse_conninfo(value, _conninfo_parse)

    if ret:
        ret.setdefault('sslmode', 'prefer')
        ret.setdefault('gssencmode', 'prefer')
        ret.setdefault('channel_binding', 'prefer')
        ret.setdefault('sslnegotiation', 'postgres')
    return ret

    Compatibility layer on top of function from psycopg2/psycopg3, which parses connection strings.
    In this function sets the `sslmode`, 'gssencmode', and `channel_binding` to `prefer`
    and `sslnegotiation` to `postgres` if they are not present in the connection string.
    This is necessary to simplify comparison of the old and the new values.

    >>> r = parse_dsn('postgresql://foo/postgres')
    >>> r == {'dbname': 'postgres', 'host': 'foo', 'sslmode': 'prefer', 'gssencmode': 'prefer',              'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    >>> r = parse_dsn(" host = 'host' dbname = db\\ name requiressl=1 ")
    >>> r == {'dbname': 'db name', 'host': 'host', 'sslmode': 'require',              'gssencmode': 'prefer', 'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    >>> parse_dsn('requiressl = 0\\') == {'sslmode': 'prefer', 'gssencmode': 'prefer',                                            'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    >>> parse_dsn('foo=bar') == {'foo': 'bar', 'sslmode': 'prefer', 'gssencmode': 'prefer',                                 'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}
    True
    
patroni/postgresql/config.py