mirror of https://github.com/MISP/PyMISP
chg: Open all json files as bytes before loading in json
parent
f0b094f7b3
commit
e2ddb48f18
|
@ -126,7 +126,7 @@ class PyMISP(object):
|
||||||
return self._check_response(response)
|
return self._check_response(response)
|
||||||
|
|
||||||
def get_local_describe_types(self):
|
def get_local_describe_types(self):
|
||||||
with open(os.path.join(self.resources_path, 'describeTypes.json'), 'r') as f:
|
with open(os.path.join(self.resources_path, 'describeTypes.json'), 'rb') as f:
|
||||||
describe_types = json.load(f)
|
describe_types = json.load(f)
|
||||||
return describe_types['result']
|
return describe_types['result']
|
||||||
|
|
||||||
|
@ -1390,7 +1390,7 @@ class PyMISP(object):
|
||||||
|
|
||||||
def sighting_per_json(self, json_file):
|
def sighting_per_json(self, json_file):
|
||||||
"""Push a sighting (JSON file)"""
|
"""Push a sighting (JSON file)"""
|
||||||
with open(json_file, 'r') as f:
|
with open(json_file, 'rb') as f:
|
||||||
jdata = json.load(f)
|
jdata = json.load(f)
|
||||||
return self.set_sightings(jdata)
|
return self.set_sightings(jdata)
|
||||||
|
|
||||||
|
@ -1460,7 +1460,7 @@ class PyMISP(object):
|
||||||
return self._rest_add('admin/users', new_user)
|
return self._rest_add('admin/users', new_user)
|
||||||
|
|
||||||
def add_user_json(self, json_file):
|
def add_user_json(self, json_file):
|
||||||
with open(json_file, 'r') as f:
|
with open(json_file, 'rb') as f:
|
||||||
jdata = json.load(f)
|
jdata = json.load(f)
|
||||||
new_user = MISPUser()
|
new_user = MISPUser()
|
||||||
new_user.from_dict(**jdata)
|
new_user.from_dict(**jdata)
|
||||||
|
@ -1475,7 +1475,7 @@ class PyMISP(object):
|
||||||
return self._rest_edit('admin/users', edit_user, user_id)
|
return self._rest_edit('admin/users', edit_user, user_id)
|
||||||
|
|
||||||
def edit_user_json(self, json_file, user_id):
|
def edit_user_json(self, json_file, user_id):
|
||||||
with open(json_file, 'r') as f:
|
with open(json_file, 'rb') as f:
|
||||||
jdata = json.load(f)
|
jdata = json.load(f)
|
||||||
new_user = MISPUser()
|
new_user = MISPUser()
|
||||||
new_user.from_dict(**jdata)
|
new_user.from_dict(**jdata)
|
||||||
|
@ -1505,7 +1505,7 @@ class PyMISP(object):
|
||||||
return self._rest_add('admin/organisations', new_org)
|
return self._rest_add('admin/organisations', new_org)
|
||||||
|
|
||||||
def add_organisation_json(self, json_file):
|
def add_organisation_json(self, json_file):
|
||||||
with open(json_file, 'r') as f:
|
with open(json_file, 'rb') as f:
|
||||||
jdata = json.load(f)
|
jdata = json.load(f)
|
||||||
new_org = MISPOrganisation()
|
new_org = MISPOrganisation()
|
||||||
new_org.from_dict(**jdata)
|
new_org.from_dict(**jdata)
|
||||||
|
@ -1520,7 +1520,7 @@ class PyMISP(object):
|
||||||
return self._rest_edit('admin/organisations', edit_org, org_id)
|
return self._rest_edit('admin/organisations', edit_org, org_id)
|
||||||
|
|
||||||
def edit_organisation_json(self, json_file, org_id):
|
def edit_organisation_json(self, json_file, org_id):
|
||||||
with open(json_file, 'r') as f:
|
with open(json_file, 'rb') as f:
|
||||||
jdata = json.load(f)
|
jdata = json.load(f)
|
||||||
edit_org = MISPOrganisation()
|
edit_org = MISPOrganisation()
|
||||||
edit_org.from_dict(**jdata)
|
edit_org.from_dict(**jdata)
|
||||||
|
@ -1594,7 +1594,7 @@ class PyMISP(object):
|
||||||
return self._check_response(response)
|
return self._check_response(response)
|
||||||
|
|
||||||
def add_server_json(self, json_file):
|
def add_server_json(self, json_file):
|
||||||
with open(json_file, 'r') as f:
|
with open(json_file, 'rb') as f:
|
||||||
jdata = json.load(f)
|
jdata = json.load(f)
|
||||||
url = urljoin(self.root_url, 'servers/add')
|
url = urljoin(self.root_url, 'servers/add')
|
||||||
response = self.__prepare_request('POST', url, json.dumps(jdata))
|
response = self.__prepare_request('POST', url, json.dumps(jdata))
|
||||||
|
@ -1611,7 +1611,7 @@ class PyMISP(object):
|
||||||
return self._check_response(response)
|
return self._check_response(response)
|
||||||
|
|
||||||
def edit_server_json(self, json_file, server_id):
|
def edit_server_json(self, json_file, server_id):
|
||||||
with open(json_file, 'r') as f:
|
with open(json_file, 'rb') as f:
|
||||||
jdata = json.load(f)
|
jdata = json.load(f)
|
||||||
url = urljoin(self.root_url, 'servers/edit/{}'.format(server_id))
|
url = urljoin(self.root_url, 'servers/edit/{}'.format(server_id))
|
||||||
response = self.__prepare_request('POST', url, json.dumps(jdata))
|
response = self.__prepare_request('POST', url, json.dumps(jdata))
|
||||||
|
|
|
@ -93,7 +93,7 @@ class MISPAttribute(AbstractMISP):
|
||||||
super(MISPAttribute, self).__init__()
|
super(MISPAttribute, self).__init__()
|
||||||
if not describe_types:
|
if not describe_types:
|
||||||
ressources_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
|
ressources_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
|
||||||
with open(os.path.join(ressources_path, 'describeTypes.json'), 'r') as f:
|
with open(os.path.join(ressources_path, 'describeTypes.json'), 'rb') as f:
|
||||||
t = json.load(f)
|
t = json.load(f)
|
||||||
describe_types = t['result']
|
describe_types = t['result']
|
||||||
self.__categories = describe_types['categories']
|
self.__categories = describe_types['categories']
|
||||||
|
@ -351,13 +351,13 @@ class MISPEvent(AbstractMISP):
|
||||||
super(MISPEvent, self).__init__()
|
super(MISPEvent, self).__init__()
|
||||||
ressources_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
|
ressources_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
|
||||||
if strict_validation:
|
if strict_validation:
|
||||||
with open(os.path.join(ressources_path, 'schema.json'), 'r') as f:
|
with open(os.path.join(ressources_path, 'schema.json'), 'rb') as f:
|
||||||
self.__json_schema = json.load(f)
|
self.__json_schema = json.load(f)
|
||||||
else:
|
else:
|
||||||
with open(os.path.join(ressources_path, 'schema-lax.json'), 'r') as f:
|
with open(os.path.join(ressources_path, 'schema-lax.json'), 'rb') as f:
|
||||||
self.__json_schema = json.load(f)
|
self.__json_schema = json.load(f)
|
||||||
if not describe_types:
|
if not describe_types:
|
||||||
with open(os.path.join(ressources_path, 'describeTypes.json'), 'r') as f:
|
with open(os.path.join(ressources_path, 'describeTypes.json'), 'rb') as f:
|
||||||
t = json.load(f)
|
t = json.load(f)
|
||||||
describe_types = t['result']
|
describe_types = t['result']
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ class MISPEvent(AbstractMISP):
|
||||||
"""Load a JSON dump from a file on the disk"""
|
"""Load a JSON dump from a file on the disk"""
|
||||||
if not os.path.exists(event_path):
|
if not os.path.exists(event_path):
|
||||||
raise PyMISPError('Invalid path, unable to load the event.')
|
raise PyMISPError('Invalid path, unable to load the event.')
|
||||||
with open(event_path, 'r') as f:
|
with open(event_path, 'rb') as f:
|
||||||
self.load(f)
|
self.load(f)
|
||||||
|
|
||||||
def load(self, json_event):
|
def load(self, json_event):
|
||||||
|
@ -897,7 +897,7 @@ class MISPObject(AbstractMISP):
|
||||||
else:
|
else:
|
||||||
self._known_template = False
|
self._known_template = False
|
||||||
if self._known_template:
|
if self._known_template:
|
||||||
with open(template_path, 'r') as f:
|
with open(template_path, 'rb') as f:
|
||||||
self._definition = json.load(f)
|
self._definition = json.load(f)
|
||||||
setattr(self, 'meta-category', self._definition['meta-category'])
|
setattr(self, 'meta-category', self._definition['meta-category'])
|
||||||
self.template_uuid = self._definition['uuid']
|
self.template_uuid = self._definition['uuid']
|
||||||
|
|
Loading…
Reference in New Issue