def process_uri(uri, tls=False, user=None, password=None):
    """
    Extracts hostname, protocol, user and passworrd from URI

    Parameters
    ----------
    uri: str or None
        Connection string in the form username:password@hostname:port
    tls: boolean
        Whether TLS is enabled
    username: str or None
        Username if not supplied as part of the URI
    password: str or None
        Password if not supplied as part of the URI
    """
    if '://' in uri:
        protocol, uri = uri.split('://')
    else:
        protocol = 'grpc+tls' if tls else 'grpc+tcp'
    if '@' in uri:
        if user or password:
            raise ValueError(
                "Dremio URI must not include username and password "
                "if they were supplied explicitly."
            )
        userinfo, hostname = uri.split('@')
        user, password = userinfo.split(':')
    elif not (user and password):
        raise ValueError(
            "Dremio URI must include username and password "
            "or they must be provided explicitly."
        )
    else:
        hostname = uri
    return protocol, hostname, user, password