Example #1
0
 def get_message_attributes_md5(self, req_data):
     req_data = clone(req_data)
     orig_types = {}
     for key, entry in dict(req_data).items():
         # Fix an issue in moto where data types like 'Number.java.lang.Integer' are
         # not supported: Keep track of the original data type, and temporarily change
         # it to the short form (e.g., 'Number'), before changing it back again.
         if key.endswith('DataType'):
             parts = entry[0].split('.')
             if len(parts) > 2:
                 short_type_name = parts[0]
                 full_type_name = req_data[key][0]
                 attr_num = key.split('.')[1]
                 attr_name = req_data['MessageAttribute.%s.Name' %
                                      attr_num][0]
                 orig_types[attr_name] = full_type_name
                 req_data[key] = [short_type_name]
                 if full_type_name not in TRANSPORT_TYPE_ENCODINGS:
                     TRANSPORT_TYPE_ENCODINGS[
                         full_type_name] = TRANSPORT_TYPE_ENCODINGS[
                             short_type_name]
     moto_message = Message('dummy_msg_id', 'dummy_body')
     moto_message.message_attributes = parse_message_attributes(req_data)
     for key, data_type in orig_types.items():
         moto_message.message_attributes[key]['data_type'] = data_type
     message_attr_hash = moto_message.attribute_md5
     return message_attr_hash
Example #2
0
    def get_message_attributes_md5(cls, req_data):
        req_data = clone(req_data)
        orig_types = {}
        for key, entry in dict(req_data).items():
            # Fix an issue in moto where data types like 'Number.java.lang.Integer' are
            # not supported: Keep track of the original data type, and temporarily change
            # it to the short form (e.g., 'Number'), before changing it back again.
            if key.endswith("DataType"):
                parts = entry.split(".")
                if len(parts) > 2:
                    short_type_name = parts[0]
                    full_type_name = entry
                    attr_num = key.split(".")[1]
                    attr_name = req_data["MessageAttribute.%s.Name" % attr_num]
                    orig_types[attr_name] = full_type_name
                    req_data[key] = [short_type_name]
                    if full_type_name not in TRANSPORT_TYPE_ENCODINGS:
                        TRANSPORT_TYPE_ENCODINGS[
                            full_type_name] = TRANSPORT_TYPE_ENCODINGS[
                                short_type_name]

        # moto parse_message_attributes(..) expects params to be passed as dict of lists
        req_data_lists = {k: [v] for k, v in req_data.items()}
        moto_message = Message("dummy_msg_id", "dummy_body")
        moto_message.message_attributes = parse_message_attributes(
            req_data_lists)
        for key, data_type in orig_types.items():
            moto_message.message_attributes[key]["data_type"] = data_type
        message_attr_hash = moto_message.attribute_md5

        return message_attr_hash
Example #3
0
def _create_message_attribute_hash(message_attributes) -> Optional[str]:
    # To avoid the need to check for dict conformity everytime we invoke this function
    if not isinstance(message_attributes, dict):
        return
    hash = hashlib.md5()

    for attrName in sorted(message_attributes.keys()):
        attr_value = message_attributes[attrName]
        # Encode name
        MotoMessage.update_binary_length_and_value(hash,
                                                   MotoMessage.utf8(attrName))
        # Encode data type
        MotoMessage.update_binary_length_and_value(
            hash, MotoMessage.utf8(attr_value["DataType"]))
        # Encode transport type and value
        if attr_value.get("StringValue"):
            hash.update(bytearray([STRING_TYPE_FIELD_INDEX]))
            MotoMessage.update_binary_length_and_value(
                hash, MotoMessage.utf8(attr_value.get("StringValue")))
        elif attr_value.get("BinaryValue"):
            hash.update(bytearray([BINARY_TYPE_FIELD_INDEX]))
            decoded_binary_value = base64.b64decode(
                attr_value.get("BinaryValue"))
            MotoMessage.update_binary_length_and_value(hash,
                                                       decoded_binary_value)
        # string_list_value, binary_list_value type is not implemented, reserved for the future use.
        # See https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_MessageAttributeValue.html
    return hash.hexdigest()