# python 3 support from __future__ import absolute_import, print_function, division import struct import re from snakebite.protobuf.RpcHeader_pb2 import RpcRequestHeaderProto, RpcResponseHeaderProto, RpcSaslProto from snakebite.config import HDFSConfig from snakebite import logger import google.protobuf.internal.encoder as encoder from puresasl.client import SASLClient # Configure package logging log = logger.getLogger(__name__) def log_protobuf_message(header, message): log.debug("%s:\n\n\033[92m%s\033[0m" % (header, message)) class SaslRpcClient: def __init__(self, trans, hdfs_namenode_principal=None): self.sasl = None self._trans = trans self.hdfs_namenode_principal = hdfs_namenode_principal def _send_sasl_message(self, message): rpcheader = RpcRequestHeaderProto() rpcheader.rpcKind = 2 # RPC_PROTOCOL_BUFFER
from snakebite.rpc_sasl import SaslRpcClient import sasl import google.protobuf.internal.encoder as encoder import google.protobuf.internal.decoder as decoder # Module imports from snakebite import logger import logging import struct import uuid # Configure package logging log = logger.getLogger(__name__) def log_protobuf_message(header, message): log.debug("%s:\n\n\033[92m%s\033[0m" % (header, message)) def get_delimited_message_bytes(byte_stream, nr=4): """ Parse a delimited protobuf message. This is done by first getting a protobuf varint from the stream that represents the length of the message, then reading that amount of from the message and then parse it. Since the int can be represented as max 4 bytes, first get 4 bytes and try to decode. The decoder returns the value and the position where the value was found, so we need to rewind the buffer to the position, because the remaining bytes belong to the message after. """