예제 #1
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        super(RequestHeader, self).read(
            istream,
            kmip_version=kmip_version
        )
        tstream = BytearrayStream(istream.read(self.length))

        self.protocol_version = contents.ProtocolVersion()
        self.protocol_version.read(tstream, kmip_version=kmip_version)

        kmip_version = contents.protocol_version_to_kmip_version(
            self.protocol_version
        )

        # Read the maximum response size if it is present
        if self.is_tag_next(Tags.MAXIMUM_RESPONSE_SIZE, tstream):
            self.maximum_response_size = contents.MaximumResponseSize()
            self.maximum_response_size.read(tstream, kmip_version=kmip_version)

        # Read the asynchronous indicator if it is present
        if self.is_tag_next(Tags.ASYNCHRONOUS_INDICATOR, tstream):
            self.asynchronous_indicator = contents.AsynchronousIndicator()
            self.asynchronous_indicator.read(
                tstream,
                kmip_version=kmip_version
            )

        # Read the authentication if it is present
        if self.is_tag_next(Tags.AUTHENTICATION, tstream):
            self.authentication = contents.Authentication()
            self.authentication.read(tstream, kmip_version=kmip_version)

        # Read the batch error continuation option if it is present
        if self.is_tag_next(Tags.BATCH_ERROR_CONTINUATION_OPTION, tstream):
            self.batch_error_cont_option = BatchErrorContinuationOption()
            self.batch_error_cont_option.read(
                tstream,
                kmip_version=kmip_version
            )

        # Read the batch order option if it is present
        if self.is_tag_next(Tags.BATCH_ORDER_OPTION, tstream):
            self.batch_order_option = contents.BatchOrderOption()
            self.batch_order_option.read(tstream, kmip_version=kmip_version)

        # Read the time stamp if it is present
        if self.is_tag_next(Tags.TIME_STAMP, tstream):
            self.time_stamp = contents.TimeStamp()
            self.time_stamp.read(tstream, kmip_version=kmip_version)

        self.batch_count = contents.BatchCount()
        self.batch_count.read(tstream, kmip_version=kmip_version)

        self.is_oversized(tstream)
예제 #2
0
    def read(self, istream):
        super(self.__class__, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.protocol_version = contents.ProtocolVersion()
        self.protocol_version.read(tstream)

        # Read the maximum response size if it is present
        if self.is_tag_next(Tags.MAXIMUM_RESPONSE_SIZE, tstream):
            self.maximum_response_size = contents.MaximumResponseSize()
            self.maximum_response_size.read(tstream)

        # Read the asynchronous indicator if it is present
        if self.is_tag_next(Tags.ASYNCHRONOUS_INDICATOR, tstream):
            self.asynchronous_indicator = contents.AsynchronousIndicator()
            self.asynchronous_indicator.read(tstream)

        # Read the authentication if it is present
        if self.is_tag_next(Tags.AUTHENTICATION, tstream):
            self.authentication = contents.Authentication()
            self.authentication.read(tstream)

        # Read the batch error continuation option if it is present
        if self.is_tag_next(Tags.BATCH_ERROR_CONTINUATION_OPTION, tstream):
            self.batch_error_cont_option = BatchErrorContinuationOption()
            self.batch_error_cont_option.read(tstream)

        # Read the batch order option if it is present
        if self.is_tag_next(Tags.BATCH_ORDER_OPTION, tstream):
            self.batch_order_option = contents.BatchOrderOption()
            self.batch_order_option.read(tstream)

        # Read the time stamp if it is present
        if self.is_tag_next(Tags.TIME_STAMP, tstream):
            self.time_stamp = contents.TimeStamp()
            self.time_stamp.read(tstream)

        self.batch_count = contents.BatchCount()
        self.batch_count.read(tstream)

        self.is_oversized(tstream)
예제 #3
0
class RequestHeader(Struct):

    def __init__(self,
                 protocol_version=None,
                 maximum_response_size=None,
                 asynchronous_indicator=None,
                 authentication=None,
                 batch_error_cont_option=None,
                 batch_order_option=None,
                 time_stamp=None,
                 batch_count=None):
        super(RequestHeader, self).__init__(tag=Tags.REQUEST_HEADER)
        self.protocol_version = protocol_version
        self.maximum_response_size = maximum_response_size
        self.asynchronous_indicator = asynchronous_indicator
        self.authentication = authentication
        self.batch_error_cont_option = batch_error_cont_option
        self.batch_order_option = batch_order_option
        self.time_stamp = time_stamp
        self.batch_count = batch_count

    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        super(RequestHeader, self).read(
            istream,
            kmip_version=kmip_version
        )
        tstream = BytearrayStream(istream.read(self.length))

        self.protocol_version = contents.ProtocolVersion()
        self.protocol_version.read(tstream, kmip_version=kmip_version)

        kmip_version = contents.protocol_version_to_kmip_version(
            self.protocol_version
        )

        # Read the maximum response size if it is present
        if self.is_tag_next(Tags.MAXIMUM_RESPONSE_SIZE, tstream):
            self.maximum_response_size = contents.MaximumResponseSize()
            self.maximum_response_size.read(tstream, kmip_version=kmip_version)

        # Read the asynchronous indicator if it is present
        if self.is_tag_next(Tags.ASYNCHRONOUS_INDICATOR, tstream):
            self.asynchronous_indicator = contents.AsynchronousIndicator()
            self.asynchronous_indicator.read(
                tstream,
                kmip_version=kmip_version
            )

        # Read the authentication if it is present
        if self.is_tag_next(Tags.AUTHENTICATION, tstream):
            self.authentication = contents.Authentication()
            self.authentication.read(tstream, kmip_version=kmip_version)

        # Read the batch error continuation option if it is present
        if self.is_tag_next(Tags.BATCH_ERROR_CONTINUATION_OPTION, tstream):
            self.batch_error_cont_option = BatchErrorContinuationOption()
            self.batch_error_cont_option.read(
                tstream,
                kmip_version=kmip_version
            )

        # Read the batch order option if it is present
        if self.is_tag_next(Tags.BATCH_ORDER_OPTION, tstream):
            self.batch_order_option = contents.BatchOrderOption()
            self.batch_order_option.read(tstream, kmip_version=kmip_version)

        # Read the time stamp if it is present
        if self.is_tag_next(Tags.TIME_STAMP, tstream):
            self.time_stamp = contents.TimeStamp()
            self.time_stamp.read(tstream, kmip_version=kmip_version)

        self.batch_count = contents.BatchCount()
        self.batch_count.read(tstream, kmip_version=kmip_version)

        self.is_oversized(tstream)

    def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        tstream = BytearrayStream()

        # Write the contents of a request header to the stream
        self.protocol_version.write(tstream, kmip_version=kmip_version)
        if self.maximum_response_size is not None:
            self.maximum_response_size.write(
                tstream,
                kmip_version=kmip_version
            )
        if self.asynchronous_indicator is not None:
            self.asynchronous_indicator.write(
                tstream,
                kmip_version=kmip_version
            )
        if self.authentication is not None:
            self.authentication.write(tstream, kmip_version=kmip_version)
        if self.batch_error_cont_option is not None:
            self.batch_error_cont_option.write(
                tstream,
                kmip_version=kmip_version
            )
        if self.batch_order_option is not None:
            self.batch_order_option.write(tstream, kmip_version=kmip_version)
        if self.time_stamp is not None:
            self.time_stamp.write(tstream, kmip_version=kmip_version)
        self.batch_count.write(tstream, kmip_version=kmip_version)

        # Write the length and value of the request header
        self.length = tstream.length()
        super(RequestHeader, self).write(
            ostream,
            kmip_version=kmip_version
        )
        ostream.write(tstream.buffer)
예제 #4
0
class RequestHeader(Struct):

    def __init__(self,
                 protocol_version=None,
                 maximum_response_size=None,
                 asynchronous_indicator=None,
                 authentication=None,
                 batch_error_cont_option=None,
                 batch_order_option=None,
                 time_stamp=None,
                 batch_count=None):
        super(self.__class__, self).__init__(tag=Tags.REQUEST_HEADER)
        self.protocol_version = protocol_version
        self.maximum_response_size = maximum_response_size
        self.asynchronous_indicator = asynchronous_indicator
        self.authentication = authentication
        self.batch_error_cont_option = batch_error_cont_option
        self.batch_order_option = batch_order_option
        self.time_stamp = time_stamp
        self.batch_count = batch_count

    def read(self, istream):
        super(self.__class__, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        self.protocol_version = contents.ProtocolVersion()
        self.protocol_version.read(tstream)

        # Read the maximum response size if it is present
        if self.is_tag_next(Tags.MAXIMUM_RESPONSE_SIZE, tstream):
            self.maximum_response_size = contents.MaximumResponseSize()
            self.maximum_response_size.read(tstream)

        # Read the asynchronous indicator if it is present
        if self.is_tag_next(Tags.ASYNCHRONOUS_INDICATOR, tstream):
            self.asynchronous_indicator = contents.AsynchronousIndicator()
            self.asynchronous_indicator.read(tstream)

        # Read the authentication if it is present
        if self.is_tag_next(Tags.AUTHENTICATION, tstream):
            self.authentication = contents.Authentication()
            self.authentication.read(tstream)

        # Read the batch error continuation option if it is present
        if self.is_tag_next(Tags.BATCH_ERROR_CONTINUATION_OPTION, tstream):
            self.batch_error_cont_option = BatchErrorContinuationOption()
            self.batch_error_cont_option.read(tstream)

        # Read the batch order option if it is present
        if self.is_tag_next(Tags.BATCH_ORDER_OPTION, tstream):
            self.batch_order_option = contents.BatchOrderOption()
            self.batch_order_option.read(tstream)

        # Read the time stamp if it is present
        if self.is_tag_next(Tags.TIME_STAMP, tstream):
            self.time_stamp = contents.TimeStamp()
            self.time_stamp.read(tstream)

        self.batch_count = contents.BatchCount()
        self.batch_count.read(tstream)

        self.is_oversized(tstream)

    def write(self, ostream):
        tstream = BytearrayStream()

        # Write the contents of a request header to the stream
        self.protocol_version.write(tstream)
        if self.maximum_response_size is not None:
            self.maximum_response_size.write(tstream)
        if self.asynchronous_indicator is not None:
            self.asynchronous_indicator.write(tstream)
        if self.authentication is not None:
            self.authentication.write(tstream)
        if self.batch_error_cont_option is not None:
            self.batch_error_cont_option.write(tstream)
        if self.batch_order_option is not None:
            self.batch_order_option.write(tstream)
        if self.time_stamp is not None:
            self.time_stamp.write(tstream)
        self.batch_count.write(tstream)

        # Write the length and value of the request header
        self.length = tstream.length()
        super(self.__class__, self).write(ostream)
        ostream.write(tstream.buffer)
예제 #5
0
파일: processor.py 프로젝트: nausley/PyKMIP
    def _process_request(self, message):
        header = message.request_header

        protocol_version = header.protocol_version
        #        maximum_response_size = header.maximum_response_size
        asynchronous_indicator = header.asynchronous_indicator
        #        authentication = header.authentication
        batch_error_cont_option = header.batch_error_cont_option
        #        batch_order_option = header.batch_order_option
        #        time_stamp = header.time_stamp
        request_batch_count = header.batch_count.value

        # TODO (peter-hamilton) Log receipt of message with time stamp

        if asynchronous_indicator is None:
            asynchronous_indicator = AsynchronousIndicator(False)

        if batch_error_cont_option is None:
            batch_error_cont_option = BatchErrorContinuationOption(BECO.STOP)

        request_batch_items = message.batch_items
        response_batch_items = []

        for i in range(request_batch_count):
            request_batch_item = request_batch_items[i]
            failure_occurred = False

            operation = request_batch_item.operation
            ubi_id = request_batch_item.unique_batch_item_id
            payload = request_batch_item.request_payload
            message_extension = request_batch_item.message_extension

            result = self._process_operation(operation, payload)

            result_status = result[0]
            result_reason = result[1]
            result_message = result[2]
            asyn_cv = None
            response_payload = None
            message_extension = None

            if result_status.value is RS.SUCCESS:
                response_payload = result[3]
            elif result_status.value is RS.OPERATION_FAILED:
                failure_occurred = True
                result_reason = result[1]
            elif result_status.value is RS.OPERATION_PENDING:
                # TODO (peter-hamilton) Need to add a way to track async
                # TODO (peter-hamilton) operations.
                asyn_cv = b'\x00'
            elif result_status.value is RS.OPERATION_UNDONE:
                result_reason = result[1]
            else:
                msg = 'Unrecognized operation result status: {0}'
                raise RuntimeError(msg.format(result_status))

            resp_bi = ResponseBatchItem(operation=operation,
                                        unique_batch_item_id=ubi_id,
                                        result_status=result_status,
                                        result_reason=result_reason,
                                        result_message=result_message,
                                        async_correlation_value=asyn_cv,
                                        response_payload=response_payload,
                                        message_extension=message_extension)
            response_batch_items.append(resp_bi)

            if failure_occurred:
                if batch_error_cont_option.value is BECO.STOP:
                    break
                elif batch_error_cont_option.value is BECO.UNDO:
                    # TODO (peter-hamilton) Tell client to undo operations.
                    # TODO (peter-hamilton) Unclear what response should be.
                    break
                elif batch_error_cont_option.value is BECO.CONTINUE:
                    continue
                else:
                    msg = 'Unrecognized batch error continuation option: {0}'
                    raise RuntimeError(msg.format(batch_error_cont_option))

        response_batch_count = BatchCount(len(response_batch_items))
        response_time_stamp = TimeStamp(int(time.time()))
        response_header = ResponseHeader(protocol_version=protocol_version,
                                         time_stamp=response_time_stamp,
                                         batch_count=response_batch_count)

        response_message = ResponseMessage(response_header=response_header,
                                           batch_items=response_batch_items)
        return response_message