def test_roundtrip2(self): addr_dict = {'address_value': "1.2.3.4", 'category': Address.CAT_IPV4, 'is_destination': True, 'is_source': False} addr_obj = Address.object_from_dict(addr_dict) addr_dict2 = Address.dict_from_object(addr_obj) self.assertEqual(addr_dict, addr_dict2)
def object_from_dict(cls, network_connection_attributes): """Create the Network Connection Object object representation from an input dictionary""" network_connection_obj = network_connection_binding.NetworkConnectionType() for key, value in network_connection_attributes.items(): if key == "tls_used" and utils.test_value(value): network_connection_obj.set_tls_used(value.get("value")) elif key == "layer3_protocol" and utils.test_value(value): network_connection_obj.set_Layer3_Protocol( Base_Object_Attribute.object_from_dict( common_types_binding.StringObjectAttributeType(datatype="String"), value ) ) elif key == "layer4_protocol" and utils.test_value(value): network_connection_obj.set_Layer4_Protocol( Base_Object_Attribute.object_from_dict( common_types_binding.StringObjectAttributeType(datatype="String"), value ) ) elif key == "layer7_protocol" and utils.test_value(value): network_connection_obj.set_Layer7_Protocol( Base_Object_Attribute.object_from_dict( common_types_binding.StringObjectAttributeType(datatype="String"), value ) ) elif key == "local_ip_address": network_connection_obj.set_Local_IP_Address(Address.object_from_dict(value)) elif key == "local_port": network_connection_obj.set_Local_Port(Port.object_from_dict(value)) elif key == "remote_ip_address": network_connection_obj.set_Remote_IP_Address(Address.object_from_dict(value)) elif key == "remote_port": network_connection_obj.set_Local_Port(Port.object_from_dict(value)) elif key == "layer7_connections": layer7_conn_object = network_connection_binding.Layer7ConnectionsType() if value.get("http_session") is not None: layer7_conn_object.set_HTTP_Session(HTTP_Session.object_from_dict(value.get("http_session"))) if layer7_conn_object.hasContent_(): network_connection_obj.set_Layer7_Connections(layer7_conn_object) return network_connection_obj
def object_from_dict(cls, process_dict, process_obj = None): if process_obj == None: process_obj = process_binding.ProcessObjectType() process_obj.set_anyAttributes_({'xsi:type' : 'ProcessObj:ProcessObjectType'}) for key, value in process_dict.items(): if key == 'is_hidden' and utils.test_value(value): process_obj.set_is_hidden(value.get('value')) elif key == 'name' and utils.test_value(value): process_obj.set_Name(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'),value)) elif key == 'image_info': image_info = process_binding.ImageInfoType() for image_info_key, image_info_value in value.items(): if image_info_key == 'file_name' and utils.test_value(image_info_value): image_info.set_File_Name(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'),image_info_value)) elif image_info_key == 'command_line' and utils.test_value(image_info_value): image_info.set_Command_Line(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'),image_info_value)) elif image_info_key == 'current_directory' and utils.test_value(image_info_value): image_info.set_Current_Directory(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'),image_info_value)) elif image_info_key == 'path' and utils.test_value(image_info_value): image_info.set_Command_Line(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'),image_info_value)) if image_info.hasContent_() : process_obj.set_Image_Info(image_info) elif key == 'pid' and utils.test_value(value): process_obj.set_PID(Base_Object_Attribute.object_from_dict(common_types_binding.UnsignedIntegerObjectAttributeType(datatype='UnsignedInt'),value)) elif key == 'parent_pid' and utils.test_value(value): process_obj.set_Parent_PID(Base_Object_Attribute.object_from_dict(common_types_binding.UnsignedIntegerObjectAttributeType(datatype='UnsignedInt'),value)) elif key == 'child_pid_list': child_list = process_binding.ChildPIDListType() for id in value: child_list.add_Child_PID(Base_Object_Attribute.object_from_dict(common_types_binding.UnsignedIntegerObjectAttributeType(datatype='UnsignedInt'), id)) if child_list.hasContent_() : process_obj.set_Child_PID_List(child_list) elif key == 'argument_list': arg_list = [] for arg in value: arg_list.append(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'),arg)) argument_list = process_binding.ArgumentListType() argument_list.set_Argument(arg_list) process_obj.set_Argument_List(argument_list) elif key == 'environment_variable_list': env_variable_list = Environment_Variable_List.object_from_dict(value) if env_variable_list.hasContent_(): process_obj.set_Environment_Variable_List(env_list) elif key == 'port_list': port_list = process_binding.PortListType() for port_dict in value: port_obj = port.object_from_dict(port_dict) port_list.add_Port(port_obj) process_obj.set_Post_List(port_list) elif key == 'network_connection_list': conn_list = process_binding.NetworkConnectionListType() for conn_dict in value: connobj = process_binding.NetworkConnectionType() for conn_key, conn_value in conn_dict.items(): if conn_key == 'creation_time' and utils.test_value(conn_value): connobj.set_Creation_Time(Base_Object_Attribute.object_from_dict(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'),conn_value)) elif conn_key == 'destination_ip_Address' and utils.test_value(conn_value): connobj.set_Destination_Address(Address.object_from_dict(conn_value)) elif conn_key == 'destination_port' and utils.test_value(conn_value): connobj.set_Source_Port(port.object_from_dict(conn_value)) elif conn_key == 'source_ip_Address' and utils.test_value(conn_value): connobj.set_Source_Address(Address.object_from_dict(conn_value)) elif conn_key == 'source_port' and utils.test_value(conn_value): connobj.set_Source_Port(port.object_from_dict(conn_value)) elif conn_key == 'tcp_state' and utils.test_value(conn_value): connobj.set_TCP_State(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'), value)) if connobj.hasContent_() : conn_list.add_Network_Connection(connobj) elif key == 'string_list': string_list = Extracted_String_List.object_from_list(value) if string_list.hasContent_() : process_obj.set_String_List(string_list) elif key == 'username' and utils.test_value(value): process_obj.set_Username(Base_Object_Attribute.object_from_dict(common_types_binding.StringObjectAttributeType(datatype='String'),value)) elif key == 'creation_time' and utils.test_value(value): process_obj.set_Creation_Time(Base_Object_Attribute.object_from_dict(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'),value)) elif key == 'start_time' and utils.test_value(value): process_obj.set_Start_Time(Base_Object_Attribute.object_from_dict(common_types_binding.DateTimeObjectAttributeType(datatype='DateTime'),value)) elif key == 'kernel_time' and utils.test_value(value): process_obj.set_Kernel_Time(Base_Object_Attribute.object_from_dict(common_types_binding.DurationObjectAttributeType(datatype='Duration'),value)) elif key == 'user_time' and utils.test_value(value): process_obj.set_User_Time(Base_Object_Attribute.object_from_dict(common_types_binding.DurationObjectAttributeType(datatype='Duration'),value)) return process_obj