chg: Raise an exception when distribution is sharing group, but the ID is missing.

pull/176/head
Raphaël Vinot 2018-01-16 12:15:30 +01:00
parent 13ca2e742f
commit aff57876bc
1 changed files with 9 additions and 0 deletions

View File

@ -203,6 +203,15 @@ class MISPAttribute(AbstractMISP):
self.timestamp = datetime.datetime.fromtimestamp(int(kwargs.pop('timestamp')), UTC()) self.timestamp = datetime.datetime.fromtimestamp(int(kwargs.pop('timestamp')), UTC())
if kwargs.get('sharing_group_id'): if kwargs.get('sharing_group_id'):
self.sharing_group_id = int(kwargs.pop('sharing_group_id')) self.sharing_group_id = int(kwargs.pop('sharing_group_id'))
if self.distribution == 4:
# The distribution is set to sharing group, a sharing_group_id is required.
if not hasattr(self, 'sharing_group_id'):
raise NewAttributeError('If the distribution is set to sharing group, a sharing group ID is required.')
elif not self.sharing_group_id:
# Cannot be None or 0 either.
raise NewAttributeError('If the distribution is set to sharing group, a sharing group ID is required (cannot be {}).'.format(self.sharing_group_id))
if kwargs.get('Tag'): if kwargs.get('Tag'):
for tag in kwargs.pop('Tag'): for tag in kwargs.pop('Tag'):
self.add_tag(tag) self.add_tag(tag)