mirror of https://github.com/MISP/PyMISP
Update get_template_id, cleanup
parent
c09ce0032c
commit
f66af15c62
|
@ -24,17 +24,17 @@ if __name__ == '__main__':
|
|||
|
||||
if seos:
|
||||
for s in seos:
|
||||
template_id = pymisp.get_object_template_id(s['name'])
|
||||
template_id = pymisp.get_object_template_id(s.template_uuid)
|
||||
r = pymisp.add_object(args.event, template_id, s)
|
||||
|
||||
if peo:
|
||||
template_id = pymisp.get_object_template_id(peo['name'])
|
||||
template_id = pymisp.get_object_template_id(peo.template_uuid)
|
||||
r = pymisp.add_object(args.event, template_id, peo)
|
||||
for ref in peo.references:
|
||||
r = pymisp.add_object_reference(ref)
|
||||
|
||||
if fo:
|
||||
template_id = pymisp.get_object_template_id(fo['name'])
|
||||
template_id = pymisp.get_object_template_id(fo.template_uuid)
|
||||
response = pymisp.add_object(args.event, template_id, fo)
|
||||
for ref in fo.references:
|
||||
r = pymisp.add_object_reference(ref)
|
||||
|
|
|
@ -1600,12 +1600,12 @@ class PyMISP(object):
|
|||
response = session.get(url)
|
||||
return self._check_response(response)['response']
|
||||
|
||||
def get_object_template_id(self, object_name):
|
||||
def get_object_template_id(self, object_uuid):
|
||||
templates = self.get_object_templates_list()
|
||||
for t in templates:
|
||||
if t['ObjectTemplate']['name'] == object_name:
|
||||
if t['ObjectTemplate']['uuid'] == object_uuid:
|
||||
return t['ObjectTemplate']['id']
|
||||
raise Exception('Unable to find template name {} on the MISP instance'.format(object_name))
|
||||
raise Exception('Unable to find template uuid {} on the MISP instance'.format(object_uuid))
|
||||
|
||||
# ###########################
|
||||
# ####### Deprecated ########
|
||||
|
|
|
@ -41,7 +41,9 @@ class FileObject(MISPObjectGenerator):
|
|||
self.filename = filename
|
||||
else:
|
||||
raise Exception('File buffer (BytesIO) or a path is required.')
|
||||
MISPObjectGenerator.__init__(self, 'file')
|
||||
# PY3 way:
|
||||
# super().__init__('file')
|
||||
super(FileObject, self).__init__('file')
|
||||
self.data = self.pseudofile.getvalue()
|
||||
self.generate_attributes()
|
||||
|
||||
|
|
|
@ -83,13 +83,13 @@ class MISPObjectGenerator(AbstractMISP):
|
|||
'data', 'misp-objects', 'objects')
|
||||
with open(os.path.join(self.misp_objects_path, template_dir, 'definition.json'), 'r') as f:
|
||||
self.definition = json.load(f)
|
||||
self.object_attributes = self.definition['attributes'].keys()
|
||||
self.misp_event = MISPEvent()
|
||||
self.name = self.definition['name']
|
||||
setattr(self, 'meta-category', self.definition['meta-category'])
|
||||
self.uuid = str(uuid.uuid4())
|
||||
self.template_uuid = self.definition['uuid']
|
||||
self.description = self.definition['description']
|
||||
self.version = self.definition['version']
|
||||
self.uuid = str(uuid.uuid4())
|
||||
self.Attribute = []
|
||||
self.references = []
|
||||
|
||||
|
@ -121,7 +121,7 @@ class MISPObjectGenerator(AbstractMISP):
|
|||
if self.definition.get('required'):
|
||||
for r in self.definition.get('required'):
|
||||
if r not in all_attribute_names:
|
||||
raise InvalidMISPObject('{} is required is required'.format(r))
|
||||
raise InvalidMISPObject('{} is required'.format(r))
|
||||
return True
|
||||
|
||||
def add_reference(self, destination_uuid, relationship_type, comment=None):
|
||||
|
|
|
@ -43,7 +43,9 @@ class PEObject(MISPObjectGenerator):
|
|||
self.pe = parsed
|
||||
else:
|
||||
raise Exception('Not a lief.PE.Binary: {}'.format(type(parsed)))
|
||||
MISPObjectGenerator.__init__(self, 'pe')
|
||||
# Python3 way
|
||||
# super().__init__('pe')
|
||||
super(PEObject, self).__init__('pe')
|
||||
self.generate_attributes()
|
||||
|
||||
def _is_exe(self):
|
||||
|
@ -114,7 +116,9 @@ class PEObject(MISPObjectGenerator):
|
|||
class PESectionObject(MISPObjectGenerator):
|
||||
|
||||
def __init__(self, section):
|
||||
MISPObjectGenerator.__init__(self, 'pe-section')
|
||||
# Python3 way
|
||||
# super().__init__('pe-section')
|
||||
super(PESectionObject, self).__init__('pe-section')
|
||||
self.section = section
|
||||
self.data = bytes(self.section.content)
|
||||
self.generate_attributes()
|
||||
|
|
Loading…
Reference in New Issue