From 6ab8eee9e81128ec712e588115a6d8459f8f0d39 Mon Sep 17 00:00:00 2001 From: Adrien RAFFIN Date: Fri, 7 Apr 2017 17:10:47 +0200 Subject: [PATCH 1/2] fix: org_type was not the correct variable --- pymisp/api.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index 3f2c723..5b526df 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1300,16 +1300,21 @@ class PyMISP(object): # ############## Servers ################## def _set_server_organisation(self, server, organisation): - if organisation is not None and 'type' in organisation: - organisation_type = organisation['type'] - if organisation_type < 2: - if 'id' in organisation: - server['organisation_type'] = organisation_type - server['json'] = json.dump({'id': organisation['id']}) - else: - if 'name' in organisation and 'uuid' in organisation: - server['organisation_type'] = organisation_type - server['json'] = json.dumps({'name': organisation['name'], 'uuid': organisation['uuid']}) + if organisation is None: + raise PyMISPError('Need a valid organisation as argument, create it before if needed') + if 'Organisation' in organisation: + organisation=organisation.get('Organisation') + if 'local' not in organisation: + raise PyMISPError('Need a valid organisation as argument. "local" value have not been set in this organisation') + if 'id' not in organisation: + raise PyMISPError('Need a valid organisation as argument. "id" value doesn\'t exist in provided organisation') + # Local organisation is '0' and remote organisation is '1'. These values are extracted from web interface of MISP + if organisation.get('local') == True: + organisation_type = 0 + else: + organisation_type = 1 + server['organisation_type'] = organisation_type + server['json'] = json.dumps({'id': organisation['id']}) return server def _set_server_parameters(self, url, name, authkey, organisation, internal, From e46a74b41a94fd453fefdc99fcc3a4f232fd2812 Mon Sep 17 00:00:00 2001 From: Adrien RAFFIN Date: Mon, 10 Apr 2017 14:13:53 +0200 Subject: [PATCH 2/2] fix: Add default values for mandatory variable --- pymisp/api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index 5b526df..74d71bd 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1351,8 +1351,8 @@ class PyMISP(object): server['delete_client_cert'] = delete_client_cert return server - def add_server(self, url, name, authkey, organisation, internal=None, push=None, - pull=None, self_signed=None, push_rules=None, pull_rules=None, + def add_server(self, url, name, authkey, organisation, internal=None, push=False, + pull=False, self_signed=False, push_rules="", pull_rules="", submitted_cert=None, submitted_client_cert=None): new_server = self._set_server_parameters(url, name, authkey, organisation, internal, push, pull, self_signed, push_rules, pull_rules, submitted_cert, @@ -1370,8 +1370,8 @@ class PyMISP(object): response = session.post(url, data=json.dumps(jdata)) return self._check_response(response) - def edit_server(self, server_id, url=None, name=None, authkey=None, organisation=None, internal=None, push=None, - pull=None, self_signed=None, push_rules=None, pull_rules=None, + def edit_server(self, server_id, url=None, name=None, authkey=None, organisation=None, internal=None, push=False, + pull=False, self_signed=False, push_rules="", pull_rules="", submitted_cert=None, submitted_client_cert=None, delete_cert=None, delete_client_cert=None): new_server = self._set_server_parameters(url, name, authkey, organisation, internal, push, pull, self_signed, push_rules, pull_rules, submitted_cert,