Merge pull request #69 from SekoiaLab/fix/serverCreation

Fix/server creation
pull/77/head
Raphaël Vinot 2017-04-11 10:51:01 +02:00 committed by GitHub
commit deb88969b5
1 changed files with 19 additions and 14 deletions

View File

@ -1307,16 +1307,21 @@ class PyMISP(object):
# ############## Servers ################## # ############## Servers ##################
def _set_server_organisation(self, server, organisation): def _set_server_organisation(self, server, organisation):
if organisation is not None and 'type' in organisation: if organisation is None:
organisation_type = organisation['type'] raise PyMISPError('Need a valid organisation as argument, create it before if needed')
if organisation_type < 2: if 'Organisation' in organisation:
if 'id' in organisation: organisation=organisation.get('Organisation')
server['organisation_type'] = organisation_type if 'local' not in organisation:
server['json'] = json.dump({'id': organisation['id']}) raise PyMISPError('Need a valid organisation as argument. "local" value have not been set in this organisation')
else: if 'id' not in organisation:
if 'name' in organisation and 'uuid' in organisation: raise PyMISPError('Need a valid organisation as argument. "id" value doesn\'t exist in provided organisation')
server['organisation_type'] = organisation_type # Local organisation is '0' and remote organisation is '1'. These values are extracted from web interface of MISP
server['json'] = json.dumps({'name': organisation['name'], 'uuid': organisation['uuid']}) 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 return server
def _set_server_parameters(self, url, name, authkey, organisation, internal, def _set_server_parameters(self, url, name, authkey, organisation, internal,
@ -1353,8 +1358,8 @@ class PyMISP(object):
server['delete_client_cert'] = delete_client_cert server['delete_client_cert'] = delete_client_cert
return server return server
def add_server(self, url, name, authkey, organisation, internal=None, push=None, def add_server(self, url, name, authkey, organisation, internal=None, push=False,
pull=None, self_signed=None, push_rules=None, pull_rules=None, pull=False, self_signed=False, push_rules="", pull_rules="",
submitted_cert=None, submitted_client_cert=None): submitted_cert=None, submitted_client_cert=None):
new_server = self._set_server_parameters(url, name, authkey, organisation, internal, new_server = self._set_server_parameters(url, name, authkey, organisation, internal,
push, pull, self_signed, push_rules, pull_rules, submitted_cert, push, pull, self_signed, push_rules, pull_rules, submitted_cert,
@ -1372,8 +1377,8 @@ class PyMISP(object):
response = session.post(url, data=json.dumps(jdata)) response = session.post(url, data=json.dumps(jdata))
return self._check_response(response) return self._check_response(response)
def edit_server(self, server_id, url=None, name=None, authkey=None, organisation=None, internal=None, push=None, def edit_server(self, server_id, url=None, name=None, authkey=None, organisation=None, internal=None, push=False,
pull=None, self_signed=None, push_rules=None, pull_rules=None, pull=False, self_signed=False, push_rules="", pull_rules="",
submitted_cert=None, submitted_client_cert=None, delete_cert=None, delete_client_cert=None): 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, new_server = self._set_server_parameters(url, name, authkey, organisation, internal,
push, pull, self_signed, push_rules, pull_rules, submitted_cert, push, pull, self_signed, push_rules, pull_rules, submitted_cert,