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 ##################
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,
@ -1353,8 +1358,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,
@ -1372,8 +1377,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,