Exemplo n.º 1
0
    def _destroy(self,
                 unique_identifier=None,
                 credential=None):
        operation = Operation(OperationEnum.DESTROY)

        uuid = None
        if unique_identifier is not None:
            uuid = attr.UniqueIdentifier(unique_identifier)

        payload = destroy.DestroyRequestPayload(unique_identifier=uuid)

        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=payload)
        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
        else:
            payload_unique_identifier = payload.unique_identifier

        result = DestroyResult(batch_item.result_status,
                               batch_item.result_reason,
                               batch_item.result_message,
                               payload_unique_identifier)
        return result
Exemplo n.º 2
0
    def _mac(self,
             unique_identifier=None,
             cryptographic_parameters=None,
             data=None,
             credential=None):
        operation = Operation(OperationEnum.MAC)

        req_pl = mac.MACRequestPayload(
            unique_identifier=attr.UniqueIdentifier(unique_identifier),
            cryptographic_parameters=cryptographic_parameters,
            data=objects.Data(data))
        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=req_pl)

        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
            payload_mac_data = None
        else:
            payload_unique_identifier = payload.unique_identifier
            payload_mac_data = payload.mac_data

        result = MACResult(batch_item.result_status, batch_item.result_reason,
                           batch_item.result_message,
                           payload_unique_identifier, payload_mac_data)
        return result
Exemplo n.º 3
0
    def _build_discover_versions_batch_item(self, protocol_versions=None):
        operation = Operation(OperationEnum.DISCOVER_VERSIONS)

        payload = discover_versions.DiscoverVersionsRequestPayload(
            protocol_versions)

        batch_item = messages.RequestBatchItem(
            operation=operation, request_payload=payload)
        return batch_item
Exemplo n.º 4
0
 def _build_get_attributes_batch_item(self,
                                      uuid=None,
                                      attribute_names=None):
     operation = Operation(OperationEnum.GET_ATTRIBUTES)
     payload = get_attributes.GetAttributesRequestPayload(
         uuid, attribute_names)
     batch_item = messages.RequestBatchItem(operation=operation,
                                            request_payload=payload)
     return batch_item
Exemplo n.º 5
0
    def _get(self,
             unique_identifier=None,
             key_format_type=None,
             key_compression_type=None,
             key_wrapping_specification=None,
             credential=None):
        operation = Operation(OperationEnum.GET)

        uuid = None
        kft = None
        kct = None
        kws = None

        if unique_identifier is not None:
            uuid = attr.UniqueIdentifier(unique_identifier)
        if key_format_type is not None:
            kft = get.GetRequestPayload.KeyFormatType(key_format_type.value)
        if key_compression_type is not None:
            kct = key_compression_type
            kct = get.GetRequestPayload.KeyCompressionType(kct)
        if key_wrapping_specification is not None:
            kws = objects.KeyWrappingSpecification(key_wrapping_specification)

        req_pl = get.GetRequestPayload(unique_identifier=uuid,
                                       key_format_type=kft,
                                       key_compression_type=kct,
                                       key_wrapping_specification=kws)

        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=req_pl)
        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
            payload_object_type = None
            payload_secret = None
        else:
            payload_unique_identifier = payload.unique_identifier
            payload_object_type = payload.object_type
            payload_secret = payload.secret

        result = GetResult(batch_item.result_status,
                           batch_item.result_reason,
                           batch_item.result_message,
                           payload_object_type,
                           payload_unique_identifier,
                           payload_secret)
        return result
Exemplo n.º 6
0
 def _build_create_key_pair_batch_item(self, common_template_attribute=None,
                                       private_key_template_attribute=None,
                                       public_key_template_attribute=None):
     operation = Operation(OperationEnum.CREATE_KEY_PAIR)
     payload = create_key_pair.CreateKeyPairRequestPayload(
         common_template_attribute=common_template_attribute,
         private_key_template_attribute=private_key_template_attribute,
         public_key_template_attribute=public_key_template_attribute)
     batch_item = messages.RequestBatchItem(
         operation=operation, request_payload=payload)
     return batch_item
Exemplo n.º 7
0
 def _build_rekey_key_pair_batch_item(self,
                                      private_key_uuid=None, offset=None,
                                      common_template_attribute=None,
                                      private_key_template_attribute=None,
                                      public_key_template_attribute=None):
     operation = Operation(OperationEnum.REKEY_KEY_PAIR)
     payload = rekey_key_pair.RekeyKeyPairRequestPayload(
         private_key_uuid, offset,
         common_template_attribute=common_template_attribute,
         private_key_template_attribute=private_key_template_attribute,
         public_key_template_attribute=public_key_template_attribute)
     batch_item = messages.RequestBatchItem(
         operation=operation, request_payload=payload)
     return batch_item
Exemplo n.º 8
0
    def _locate(self,
                maximum_items=None,
                storage_status_mask=None,
                object_group_member=None,
                attributes=[],
                credential=None):

        operation = Operation(OperationEnum.LOCATE)

        mxi = None
        ssmask = None
        objgrp = None

        if maximum_items is not None:
            mxi = locate.LocateRequestPayload.MaximumItems(maximum_items)
        if storage_status_mask is not None:
            m = storage_status_mask
            ssmask = locate.LocateRequestPayload.StorageStatusMask(m)
        if object_group_member is not None:
            o = object_group_member
            objgrp = locate.LocateRequestPayload.ObjectGroupMember(o)

        payload = locate.LocateRequestPayload(maximum_items=mxi,
                                              storage_status_mask=ssmask,
                                              object_group_member=objgrp,
                                              attributes=attributes)

        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=payload)

        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()

        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            uuids = None
        else:
            uuids = payload.unique_identifiers

        result = LocateResult(batch_item.result_status,
                              batch_item.result_reason,
                              batch_item.result_message, uuids)
        return result
Exemplo n.º 9
0
    def _create(self,
                object_type=None,
                template_attribute=None,
                credential=None):
        operation = Operation(OperationEnum.CREATE)

        if object_type is None:
            raise ValueError('object_type cannot be None')

        req_pl = create.CreateRequestPayload(
            object_type=object_type,
            template_attribute=template_attribute)
        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=req_pl)

        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
            payload_template_attribute = None
            payload_object_type = None
        else:
            payload_unique_identifier = payload.unique_identifier
            payload_template_attribute = payload.template_attribute
            payload_object_type = payload.object_type

        result = CreateResult(batch_item.result_status,
                              batch_item.result_reason,
                              batch_item.result_message,
                              payload_object_type,
                              payload_unique_identifier,
                              payload_template_attribute)
        return result
Exemplo n.º 10
0
    def _revoke(self,
                unique_identifier=None,
                revocation_code=None,
                revocation_message=None,
                credential=None):
        operation = Operation(OperationEnum.REVOKE)

        reason = objects.RevocationReason(code=revocation_code,
                                          message=revocation_message)
        uuid = None
        if unique_identifier is not None:
            uuid = attr.UniqueIdentifier(unique_identifier)

        payload = revoke.RevokeRequestPayload(
            unique_identifier=uuid,
            revocation_reason=reason,
            compromise_date=None)  # TODO(tim-kelsey): sort out date handling

        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=payload)
        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
        else:
            payload_unique_identifier = payload.unique_identifier

        result = RevokeResult(batch_item.result_status,
                              batch_item.result_reason,
                              batch_item.result_message,
                              payload_unique_identifier)
        return result
Exemplo n.º 11
0
 def _build_get_attribute_list_batch_item(self, uid=None):
     operation = Operation(OperationEnum.GET_ATTRIBUTE_LIST)
     payload = get_attribute_list.GetAttributeListRequestPayload(uid)
     batch_item = messages.RequestBatchItem(
         operation=operation, request_payload=payload)
     return batch_item
Exemplo n.º 12
0
 def _build_query_batch_item(self, query_functions=None):
     operation = Operation(OperationEnum.QUERY)
     payload = query.QueryRequestPayload(query_functions)
     batch_item = messages.RequestBatchItem(
         operation=operation, request_payload=payload)
     return batch_item