Пример #1
0
def connect(url, max_retries=None, auth=None, **kwargs):
    """Connects to a Phoenix query server.

    :param url:
        URL to the Phoenix query server, e.g. ``http://localhost:8765/``

    :param autocommit:
        Switch the connection to autocommit mode.

    :param readonly:
        Switch the connection to readonly mode.

    :param max_retries:
        The maximum number of retries in case there is a connection error.

    :param cursor_factory:
        If specified, the connection's :attr:`~phoenixdb.connection.Connection.cursor_factory` is set to it.

    :param auth
        If specified a specific auth type will be used, otherwise connection will be unauthenticated
        Currently only SPNEGO is supported

    :returns:
        :class:`~phoenixdb.connection.Connection` object.
    """
    client = AvaticaClient(url, max_retries=max_retries, auth=auth)
    client.connect()
    return Connection(client, **kwargs)
Пример #2
0
def connect(url, **kwargs):
    """Connects to a Phoenix query server.

    :param url:
        URL to the Phoenix query server, e.g. ``http://localhost:8765/``

    :param autocommit:
        Switch the connection to autocommit mode.

    :param readonly:
        Switch the connection to readonly mode.

    :returns:
        :class:`~phoenixdb.connection.Connection` object.
    """
    client = AvaticaClient(url)
    client.connect()
    return Connection(client, **kwargs)
Пример #3
0
def connect(url, max_retries=None, **kwargs):
    """Connects to a Phoenix query server.

    :param url:
        URL to the Phoenix query server, e.g. ``http://localhost:8765/``

    :param autocommit:
        Switch the connection to autocommit mode.

    :param readonly:
        Switch the connection to readonly mode.

    :param max_retries:
        The maximum number of retries in case there is a connection error.

    :returns:
        :class:`~phoenixdb.connection.Connection` object.
    """
    client = AvaticaClient(url, max_retries=max_retries)
    client.connect()
    return Connection(client, **kwargs)
Пример #4
0
def connect(url,
            max_retries=None,
            auth=None,
            authentication=None,
            avatica_user=None,
            avatica_password=None,
            truststore=None,
            verify=None,
            **kwargs):
    """Connects to a Phoenix query server.

    :param url:
        URL to the Phoenix query server, e.g. ``http://localhost:8765/``

    :param autocommit:
        Switch the connection to autocommit mode.

    :param readonly:
        Switch the connection to readonly mode.

    :param max_retries:
        The maximum number of retries in case there is a connection error.

    :param cursor_factory:
        If specified, the connection's :attr:`~phoenixdb.connection.Connection.cursor_factory`
        is set to it.

    :param auth:
        Authentication configuration object as expected by the underlying python_requests and
        python_requests_gssapi library

    :param authentication:
        Alternative way to specify the authentication mechanism that mimics
        the semantics of the JDBC drirver

    :param avatica_user:
        Username for BASIC or DIGEST authentication. Use in conjunction with the
        `~authentication' option.

    :param avatica_password:
        Password for BASIC or DIGEST authentication. Use in conjunction with the
        `~authentication' option.

    :param verify:
        The path to the PEM file for verifying the server's certificate. It is passed directly to
        the `~verify` parameter of the underlying python_requests library.
        Setting it to false disables the server certificate verification.

    :param truststore:
        Alias for verify

    :returns:
        :class:`~phoenixdb.connection.Connection` object.
    """

    url_parsed = urlparse(url)
    url_params = parse_qs(url_parsed.query, keep_blank_values=True)

    # Parse supported JDBC compatible options from URL. args have precendece
    rebuild = False
    if auth is None and authentication is None and 'authentication' in url_params:
        authentication = url_params['authentication'][0]
        del url_params['authentication']
        rebuild = True

    if avatica_user is None and 'avatica_user' in url_params:
        avatica_user = url_params['avatica_user'][0]
        del url_params['avatica_user']
        rebuild = True

    if avatica_password is None and 'avatica_password' in url_params:
        avatica_password = url_params['avatica_password'][0]
        del url_params['avatica_password']
        rebuild = True

    if verify is None and truststore is None and 'truststore' in url_params:
        truststore = url_params['truststore'][0]
        del url_params['truststore']
        rebuild = True

    if rebuild:
        url_parsed._replace(query=urlencode(url_params, True))
        url = urlunparse(url_parsed)

    if auth == "SPNEGO":
        # Special case for backwards compatibility
        auth = HTTPSPNEGOAuth(opportunistic_auth=True)
    elif auth is None and authentication is not None:
        if authentication == "SPNEGO":
            auth = HTTPSPNEGOAuth(opportunistic_auth=True)
        elif authentication == "BASIC" and avatica_user is not None and avatica_password is not None:
            auth = HTTPBasicAuth(avatica_user, avatica_password)
        elif authentication == "DIGEST" and avatica_user is not None and avatica_password is not None:
            auth = HTTPDigestAuth(avatica_user, avatica_password)

    if verify is None and truststore is not None:
        verify = truststore

    client = AvaticaClient(url,
                           max_retries=max_retries,
                           auth=auth,
                           verify=verify)
    client.connect()
    return Connection(client, **kwargs)
Пример #5
0
def connect(url,
            max_retries=None,
            auth=None,
            authentication=None,
            avatica_user=None,
            avatica_password=None,
            truststore=None,
            verify=None,
            do_as=None,
            user=None,
            password=None,
            **kwargs):
    """Connects to a Phoenix query server.

    :param url:
        URL to the Phoenix query server, e.g. ``http://localhost:8765/``

    :param autocommit:
        Switch the connection to autocommit mode.

    :param readonly:
        Switch the connection to readonly mode.

    :param max_retries:
        The maximum number of retries in case there is a connection error.

    :param cursor_factory:
        If specified, the connection's :attr:`~phoenixdb.connection.Connection.cursor_factory`
        is set to it.

    :param auth:
        Authentication configuration object as expected by the underlying python_requests and
        python_requests_gssapi library

    :param verify:
        The path to the PEM file for verifying the server's certificate. It is passed directly to
        the `~verify` parameter of the underlying python_requests library.
        Setting it to False disables the server certificate verification.

    :param do_as:
        Username to impersonate (sets the Hadoop doAs URL parameter)

    :param authentication:
        Alternative way to specify the authentication mechanism that mimics
        the semantics of the JDBC drirver

    :param avatica_user:
        Username for BASIC or DIGEST authentication. Use in conjunction with the
        `~authentication' option.

    :param avatica_password:
        Password for BASIC or DIGEST authentication. Use in conjunction with the
        `~authentication' option.

    :param user
        If `~authentication' is BASIC or DIGEST then alias for `~avatica_user`
        If `~authentication' is NONE or SPNEGO then alias for `~do_as`

    :param password
        If `~authentication' is BASIC or DIGEST then is alias for `~avatica_password`

    :param truststore:
        Alias for verify

    :returns:
        :class:`~phoenixdb.connection.Connection` object.
    """

    (url, auth, verify) = _process_args(url,
                                        auth=auth,
                                        authentication=authentication,
                                        avatica_user=avatica_user,
                                        avatica_password=avatica_password,
                                        truststore=truststore,
                                        verify=verify,
                                        do_as=do_as,
                                        user=user,
                                        password=password)

    client = AvaticaClient(url,
                           max_retries=max_retries,
                           auth=auth,
                           verify=verify)
    client.connect()
    return Connection(client, **kwargs)