Example #1
0
    def build(keys, hostname='localhost', port=8123, tls=False):
        m = messages.Command()
        m.header.messageType = messages.Command.PEER2PEERPUSH
        m.body.p2pOperation.peer.hostname = hostname
        m.body.p2pOperation.peer.port = port
        m.body.p2pOperation.peer.tls = tls

        operations = []
        for k in keys:
            op = None
            if isinstance(k, str):
                op = messages.Command.P2POperation.Operation(key=k)
            elif isinstance(k, common.P2pOp):
                op = messages.Command.P2POperation.Operation(key=k.key)
                if k.version:
                    op.version = k.version
                if k.newKey:
                    op.newKey = k.newKey
                if k.force:
                    op.force = k.force
            operations.append(op)

        m.body.p2pOperation.operation.extend(operations)

        return (m, None)
Example #2
0
    def build(firmware):
        m = messages.Command()
        m.header.messageType = messages.Command.SETUP

        m.body.setup.firmwareDownload = True

        return (m, firmware)
Example #3
0
    def network_recv(self):
        """
        Receives a raw Kinetic message from the network.

        return: the message received
        """

        (m, value) = self._recv_delimited_v2()

        if self.debug:
            print m

        if m.authType == messages.Message.HMACAUTH:
            if m.hmacAuth.identity == self.identity:
                hmac = calculate_hmac(self.secret, m.commandBytes)
                if not hmac == m.hmacAuth.hmac:
                    raise Exception('Hmac does not match')
            else:
                raise Exception('Wrong identity received!')

        resp = messages.Command()
        resp.ParseFromString(m.commandBytes)

        if self.debug:
            print resp

        # update connectionId to whatever the drive said.
        if resp.header.connectionID:
            self.connection_id = resp.header.connectionID

        return (m, resp, value)
Example #4
0
    def _network_recv(self):
        """
        Receive Kinetic message, response, and value from network (Kinetic device).

        Args:

        Returns:
            Message (message header), Command (proto response), String (Value)
        """
        msg = self._fast_read(9)

        magic, proto_ln, value_ln = struct.unpack_from(">bii", buffer(msg))
        # read proto message
        raw_proto = self._fast_read(proto_ln)

        value = ''
        if value_ln > 0:
            value = self._fast_read(value_ln)

        msg = kinetic_pb2.Message()
        msg.ParseFromString(str(raw_proto))

        cmd = kinetic_pb2.Command()
        cmd.ParseFromString(msg.commandBytes)
        # update connectionId to whatever the drive said.
        if cmd.header.connectionID:
            self._connection_id = cmd.header.connectionID
        return msg, cmd, value
Example #5
0
    def build(version):
        m = messages.Command()
        m.header.messageType = messages.Command.SETUP

        m.body.setup.newClusterVersion = version

        return (m, None)
Example #6
0
def _buildMessage(messageType, key, data=None, version='', new_version='',
                  force=False, tag=None, algorithm=None, synchronization=None):
    m = messages.Command()
    m.header.messageType = messageType
    if len(key) > common.MAX_KEY_SIZE: raise common.KineticClientException("Key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))
    m.body.keyValue.key = key
    if data:
        if len(data) > common.MAX_VALUE_SIZE: raise common.KineticClientException("Value exceeds maximum size of {0} bytes.".format(common.MAX_VALUE_SIZE))

    if tag and algorithm:
        m.body.keyValue.tag = tag
        m.body.keyValue.algorithm = algorithm
    elif messageType == messages.Command.PUT:
        m.body.keyValue.tag = 'l337'
        m.body.keyValue.algorithm = 1 # nacho: should be change to a value over 100
    if synchronization:
        m.body.keyValue.synchronization = synchronization
    if version:
        m.body.keyValue.dbVersion = version
    if new_version:
        m.body.keyValue.newVersion = new_version
    if force:
        m.body.keyValue.force = True

    return (m,data)
Example #7
0
 def _client_error_callback(self, status_code, status_msg):
     msg = kinetic_pb2.Message()
     msg.authType = kinetic_pb2.Message.INVALID_AUTH_TYPE
     cmd = kinetic_pb2.Command()
     cmd.status.statusMessage = "client reported."+status_msg
     cmd.status.code = status_code
     cmd.header.messageType = kinetic_pb2.Command.INVALID_MESSAGE_TYPE
     self._on_response(msg, cmd, "")
Example #8
0
    def build():
        m = messages.Command()

        m.header.messageType = messages.Command.PINOP

        m.body.pinOp.pinOpType = messages.Command.PinOperation.SECURE_ERASE_PINOP

        return (m, None)
Example #9
0
 def check_connection(self, *args, **kwargs):
     if not self.is_connected and self.auto_reconnect_count < 1:
         self._client_error_callback(kinetic_pb2.Command.Status.NOT_ATTEMPTED, "call connect() before the operation")
     else:
         self._queue_semaphore.acquire()
         command_start_time = time.time()
         cmd = kinetic_pb2.Command()
         value, message_build_time = func(self, cmd=cmd, *args, **kwargs)
         self._network_send(None, cmd, value, command_start_time, message_build_time)
Example #10
0
    def build(types, device=None):
        m = messages.Command()
        m.header.messageType = messages.Command.GETLOG

        log = m.body.getLog
        log.types.extend(types) #type is actually a repeatable field

        if device:
            log.device.name = device

        return (m, None)
Example #11
0
    def build(keys, hostname='localhost', port=8123, **kwargs):
        m = messages.Command()
        m.header.messageType = messages.Command.PEER2PEERPUSH
        m.body.p2pOperation.peer.hostname = hostname
        m.body.p2pOperation.peer.port = port

        m.body.p2pOperation.operation.extend([
            messages.Command.P2POperation.Operation(key=key) for key in keys
        ])

        return (m, None)
Example #12
0
    def build(keys, targets):
        m = messages.Command()
        m.header.messageType = messages.Command.PEER2PEERPUSH
        m.body.p2pOperation.peer.hostname = targets[0].hostname
        m.body.p2pOperation.peer.port = targets[0].port
        if targets[0].tls:
            m.body.p2pOperation.peer.tls = targets[0].tls


        def rec(targets, op):
            if len(targets) > 0:
                target = targets[0]
                op.p2pop.peer.hostname = target.hostname
                op.p2pop.peer.port = target.port
                if target.tls:
                    op.p2pop.peer.tls = target.tls
                innerop = messages.Command.P2POperation.Operation(key=op.key)
                if op.version:
                    innerop.version = op.version
                if op.force:
                    innerop.force = op.force

                rec(targets[1:],innerop)

                op.p2pop.operation.extend([innerop])

        warn_newKey = False
        operations = []
        for k in keys:
            op = None
            if isinstance(k, str):
                op = messages.Command.P2POperation.Operation(key=k)
            elif isinstance(k, common.P2pOp):
                op = messages.Command.P2POperation.Operation(key=k.key)
                if k.version:
                    op.version = k.version
                if k.newKey:
                    warn_newKey = True
                if k.force:
                    op.force = k.force

            rec(targets[1:],op)

            operations.append(op)

        if warn_newKey:
            LOG.warn("Setting new key on piped push is not currently supported.")

        m.body.p2pOperation.operation.extend(operations)

        return (m, None)
Example #13
0
        def pin_operation(pin=None, **kwargs):
            """
            PIN AUTH operations

            Args:
            pin(str): Pin for the pin based commands.
            """
            if not self.is_connected and self.auto_reconnect_count < 1:
                self._client_error_callback(kinetic_pb2.Command.Status.NOT_ATTEMPTED, "call connect() before the operation")
            else:
                self._queue_semaphore.acquire()
                command_start_time = time.time()
                m = kinetic_pb2.Message()
                m.authType = kinetic_pb2.Message.PINAUTH
                if pin is not None:
                    m.pinAuth.pin = pin
                cmd = kinetic_pb2.Command()
                cmd, _, message_build_time = self._build_message(cmd, kinetic_pb2.Command.PINOP, **kwargs)
                cmd.body.pinOp.pinOpType = pin_operation.__number__
                self._network_send(m, cmd, "", command_start_time, message_build_time)
Example #14
0
    def build(startKey=None, endKey=None, startKeyInclusive=True, endKeyInclusive=True, maxReturned=200):
        if not startKey:
            startKey = ''
        if not endKey:
            endKey = '\xFF' * common.MAX_KEY_SIZE

        if len(startKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("Start key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))
        if len(endKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("End key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))

        m = messages.Command()
        m.header.messageType = messages.Command.GETKEYRANGE

        kr = m.body.range
        kr.startKey = startKey
        kr.endKey = endKey
        kr.startKeyInclusive = startKeyInclusive
        kr.endKeyInclusive = endKeyInclusive
        kr.maxReturned = maxReturned

        return (m, None)
Example #15
0
    def build(acls=None, old_erase_pin=None, new_erase_pin=None, old_lock_pin=None, new_lock_pin=None):
        m = messages.Command()
        m.header.messageType = messages.Command.SECURITY
        op = m.body.security

        if acls:
            proto_acls = []

            for acl in acls:
                proto_acl = messages.Command.Security.ACL(identity=acl.identity,
                                                          key=acl.key,
                                                          hmacAlgorithm=acl.hmacAlgorithm,
                                                          maxPriority=acl.max_priority)

                proto_domains = []

                for domain in acl.domains:
                    proto_d = messages.Command.Security.ACL.Scope(
                                TlsRequired=domain.tlsRequired)

                    proto_d.permission.extend(domain.roles)

                    if domain.offset:
                        proto_d.offset = domain.offset
                    if domain.value:
                        proto_d.value = domain.value

                    proto_domains.append(proto_d)

                proto_acl.scope.extend(proto_domains)
                proto_acls.append(proto_acl)

            op.acl.extend(proto_acls)

        if not old_lock_pin is None: op.oldLockPIN = old_lock_pin
        if not new_lock_pin is None: op.newLockPIN = new_lock_pin
        if not old_erase_pin is None: op.oldErasePIN = old_erase_pin
        if not new_erase_pin is None: op.newErasePIN = new_erase_pin

        return (m, None)
Example #16
0
        def proto_operation(key=None, value=None, batch_flag=False, **kwargs):
            """
            HMAC AUTH operations.

            Args:
            key(str): Entry key of kinetic object.
            value(str): The value, during a put operation, that is being sent over.
                        The kinetic message and the value are sent in different packets.
            batch_flag(bool): Flag that denotes if a command is a batch command or not.
                Also used to indicate to the client whether to wait for a response or not for a START_BATCH, END_BATCH,
                or ABORT_BATCH.
            """
            if not self.is_connected and self.auto_reconnect_count < 1:
                self._client_error_callback(kinetic_pb2.Command.Status.NOT_ATTEMPTED, "call connect() before the operation")
            else:
                if not batch_flag:
                    self._queue_semaphore.acquire()

                command_start_time = time.time()
                cmd = kinetic_pb2.Command()
                cmd, value, message_build_time = \
                    self._build_message(cmd, proto_operation.__number__, key=key, value=value, **kwargs)
                self._network_send(None, cmd, value, command_start_time, message_build_time, batch_flag)
Example #17
0
    def build(self, *args, **kwargs):
        self.m = messages.Command()

        if 'timeout' in kwargs:
            self.m.header.timeout = kwargs['timeout']
            del kwargs['timeout']

        if 'priority' in kwargs:
            self.m.header.priority = kwargs['priority']
            del kwargs['priority']

        if 'early_exit' in kwargs:
            self.m.header.earlyExit = kwargs['early_exit']
            del kwargs['early_exit']

        if 'time_quanta' in kwargs:
            self.m.header.TimeQuanta = kwargs['time_quanta']
            del kwargs['time_quanta']

        if 'batch_id' in kwargs:
            self.m.header.batchID = kwargs['batch_id']
            del kwargs['batch_id']

        return self._build(*args, **kwargs)
Example #18
0
 def build():
     m = messages.Command()
     m.header.messageType = messages.Command.NOOP
     return (m, None)
Example #19
0
    def build():
        m = messages.Command()
        m.header.messageType = messages.Command.FLUSHALLDATA

        return (m, None)