Skip to content

Commit

Permalink
fix: Allow to pass value, UUID, or ID to a sighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Jan 25, 2018
1 parent 076393d commit 837372c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 6 additions & 4 deletions pymisp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,16 +1326,18 @@ def sighting_per_json(self, json_file):
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 ##################
Expand Down
14 changes: 11 additions & 3 deletions pymisp/mispevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -769,6 +773,10 @@ def from_dict(self, value, source=None, type=None, timestamp=None, **kwargs):
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)


Expand Down

0 comments on commit 837372c

Please sign in to comment.