コード例 #1
0
    def get_metastore_client(self):
        """
        Returns a Hive thrift client.
        """
        from thrift.transport import TSocket, TTransport
        from thrift.protocol import TBinaryProtocol
        ms = self.metastore_conn
        auth_mechanism = ms.extra_dejson.get('authMechanism', 'NOSASL')
        if configuration.conf.get('core', 'security') == 'kerberos':
            auth_mechanism = ms.extra_dejson.get('authMechanism', 'GSSAPI')
            kerberos_service_name = ms.extra_dejson.get('kerberos_service_name', 'hive')

        socket = TSocket.TSocket(ms.host, ms.port)
        if configuration.conf.get('core', 'security') == 'kerberos' \
                and auth_mechanism == 'GSSAPI':
            try:
                import saslwrapper as sasl
            except ImportError:
                import sasl

            def sasl_factory():
                sasl_client = sasl.Client()
                sasl_client.setAttr("host", ms.host)
                sasl_client.setAttr("service", kerberos_service_name)
                sasl_client.init()
                return sasl_client

            from thrift_sasl import TSaslClientTransport
            transport = TSaslClientTransport(sasl_factory, "GSSAPI", socket)
        else:
            transport = TTransport.TBufferedTransport(socket)

        protocol = TBinaryProtocol.TBinaryProtocol(transport)

        return hmsclient.HMSClient(iprot=protocol)
コード例 #2
0
ファイル: hive.py プロジェクト: leahecole/airflow
    def get_metastore_client(self) -> Any:
        """Returns a Hive thrift client."""
        import hmsclient
        from thrift.protocol import TBinaryProtocol
        from thrift.transport import TSocket, TTransport

        host = self._find_valid_host()
        conn = self.conn

        if not host:
            raise AirflowException("Failed to locate the valid server.")

        if 'authMechanism' in conn.extra_dejson:
            warnings.warn(
                "The 'authMechanism' option is deprecated. Please use 'auth_mechanism'.",
                DeprecationWarning,
                stacklevel=2,
            )
            conn.extra_dejson['auth_mechanism'] = conn.extra_dejson[
                'authMechanism']
            del conn.extra_dejson['authMechanism']

        auth_mechanism = conn.extra_dejson.get('auth_mechanism', 'NOSASL')

        if conf.get('core', 'security') == 'kerberos':
            auth_mechanism = conn.extra_dejson.get('auth_mechanism', 'GSSAPI')
            kerberos_service_name = conn.extra_dejson.get(
                'kerberos_service_name', 'hive')

        conn_socket = TSocket.TSocket(host, conn.port)

        if conf.get('core',
                    'security') == 'kerberos' and auth_mechanism == 'GSSAPI':
            try:
                import saslwrapper as sasl
            except ImportError:
                import sasl

            def sasl_factory() -> sasl.Client:
                sasl_client = sasl.Client()
                sasl_client.setAttr("host", host)
                sasl_client.setAttr("service", kerberos_service_name)
                sasl_client.init()
                return sasl_client

            from thrift_sasl import TSaslClientTransport

            transport = TSaslClientTransport(sasl_factory, "GSSAPI",
                                             conn_socket)
        else:
            transport = TTransport.TBufferedTransport(conn_socket)

        protocol = TBinaryProtocol.TBinaryProtocol(transport)

        return hmsclient.HMSClient(iprot=protocol)
コード例 #3
0
ファイル: hive.py プロジェクト: zorseti/airflow
    def get_metastore_client(self):
        """
        Returns a Hive thrift client.
        """
        import hmsclient
        from thrift.transport import TSocket, TTransport
        from thrift.protocol import TBinaryProtocol

        conn = self._find_valid_server()

        if not conn:
            raise AirflowException("Failed to locate the valid server.")

        auth_mechanism = conn.extra_dejson.get('authMechanism', 'NOSASL')

        if conf.get('core', 'security') == 'kerberos':
            auth_mechanism = conn.extra_dejson.get('authMechanism', 'GSSAPI')
            kerberos_service_name = conn.extra_dejson.get(
                'kerberos_service_name', 'hive')

        conn_socket = TSocket.TSocket(conn.host, conn.port)

        if conf.get('core', 'security') == 'kerberos' \
                and auth_mechanism == 'GSSAPI':
            try:
                import saslwrapper as sasl
            except ImportError:
                import sasl

            def sasl_factory():
                sasl_client = sasl.Client()
                sasl_client.setAttr("host", conn.host)
                sasl_client.setAttr("service", kerberos_service_name)
                sasl_client.init()
                return sasl_client

            from thrift_sasl import TSaslClientTransport
            transport = TSaslClientTransport(sasl_factory, "GSSAPI",
                                             conn_socket)
        else:
            transport = TTransport.TBufferedTransport(conn_socket)

        protocol = TBinaryProtocol.TBinaryProtocol(transport)

        return hmsclient.HMSClient(iprot=protocol)