From 837372cf3e36cd95570cda011ef18d05f44ebdc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 25 Jan 2018 16:24:24 +0100 Subject: [PATCH] fix: Allow to pass value, UUID, or ID to a sighting. --- pymisp/api.py | 10 ++++++---- pymisp/mispevent.py | 14 +++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index 81f9f93..e17e464 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1326,16 +1326,18 @@ class PyMISP(object): jdata = json.load(f) return self.set_sightings(jdata) - def sighting(self, value, source=None, type=None, timestamp=None, **kwargs): + def sighting(self, value=None, uuid=None, id=None, source=None, type=None, timestamp=None, **kwargs): """ Set a single sighting. - :value: Value can either be the attribute's value (to update sighting on all the attributes with this value), - or an UUID in order to update the sightings of one particular attribute. + :value: Value of the attribute the sighting is related too. Pushing this object + will update the sighting count of each attriutes with thifs value on the instance + :uuid: UUID of the attribute to update + :id: ID of the attriute to update :source: Source of the sighting :type: Type of the sighting :timestamp: Timestamp associated to the sighting """ s = MISPSighting() - s.from_dict(value=value, source=source, type=type, timestamp=timestamp, **kwargs) + s.from_dict(value=value, uuid=uuid, id=id, source=source, type=type, timestamp=timestamp, **kwargs) return self.set_sightings(s) # ############## Sharing Groups ################## diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index 26a98fc..5d96719 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -752,15 +752,19 @@ class MISPSighting(AbstractMISP): def __init__(self): super(MISPSighting, self).__init__() - def from_dict(self, value, source=None, type=None, timestamp=None, **kwargs): + def from_dict(self, value=None, uuid=None, id=None, source=None, type=None, timestamp=None, **kwargs): """Initialize the MISPSighting from a dictionary - :value: Value can either be the attribute's value (to update sighting on all the attributes with this value), - or an UUID in order to update the sightings of one particular attribute. + :value: Value of the attribute the sighting is related too. Pushing this object + will update the sighting count of each attriutes with thifs value on the instance + :uuid: UUID of the attribute to update + :id: ID of the attriute to update :source: Source of the sighting :type: Type of the sighting :timestamp: Timestamp associated to the sighting """ self.value = value + self.uuid = uuid + self.id = id self.source = source self.type = type self.timestamp = timestamp @@ -769,6 +773,10 @@ class MISPSighting(AbstractMISP): def __repr__(self): if hasattr(self, 'value'): return '<{self.__class__.__name__}(value={self.value})'.format(self=self) + if hasattr(self, 'id'): + return '<{self.__class__.__name__}(value={self.id})'.format(self=self) + if hasattr(self, 'uuid'): + return '<{self.__class__.__name__}(value={self.uuid})'.format(self=self) return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)