diff --git a/examples/add_file_object.py b/examples/add_file_object.py index e61d809..aa8ab8e 100755 --- a/examples/add_file_object.py +++ b/examples/add_file_object.py @@ -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) diff --git a/pymisp/api.py b/pymisp/api.py index 4638726..8d7856e 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -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 ######## diff --git a/pymisp/tools/fileobject.py b/pymisp/tools/fileobject.py index 770307c..ebea362 100644 --- a/pymisp/tools/fileobject.py +++ b/pymisp/tools/fileobject.py @@ -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() diff --git a/pymisp/tools/objectgenerator.py b/pymisp/tools/objectgenerator.py index 1617580..d4b5105 100644 --- a/pymisp/tools/objectgenerator.py +++ b/pymisp/tools/objectgenerator.py @@ -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): diff --git a/pymisp/tools/peobject.py b/pymisp/tools/peobject.py index e7dc206..bea117a 100644 --- a/pymisp/tools/peobject.py +++ b/pymisp/tools/peobject.py @@ -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()