feature: Adds new methods to add new servers in MISP

pull/53/head
Sebastien Quioc 2017-02-22 17:22:00 +01:00
parent 0f6d7907c2
commit f0038d4be3
1 changed files with 62 additions and 0 deletions

View File

@ -1327,3 +1327,65 @@ class PyMISP(object):
url = urljoin(self.root_url, 'admin/organisations/delete/{}'.format(org_id)) url = urljoin(self.root_url, 'admin/organisations/delete/{}'.format(org_id))
response = session.post(url) response = session.post(url)
return self._check_response(response) return self._check_response(response)
# ############## 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']})
return server
def _set_server_parameters(self, url, name, authkey, organisation, internal,
push, pull, self_signed, push_rules, pull_rules,
submitted_cert, submitted_client_cert):
server = {}
self._set_server_organisation(server, organisation)
if url is not None:
server['url'] = url
if name is not None:
server['name'] = name
if authkey is not None:
server['authkey'] = authkey
if internal is not None:
server['internal'] = internal
if push is not None:
server['push'] = push
if pull is not None:
server['pull'] = pull
if self_signed is not None:
server['self_signed'] = self_signed
if push_rules is not None:
server['push_rules'] = push_rules
if pull_rules is not None:
server['pull_rules'] = pull_rules
if submitted_cert is not None:
server['submitted_cert'] = submitted_cert
if submitted_client_cert is not None:
server['submitted_client_cert'] = submitted_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,
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,
submitted_client_cert)
session = self.__prepare_session()
url = urljoin(self.root_url, 'servers/add')
response = session.post(url, data=json.dumps(new_server))
return self._check_response(response)
def add_server_json(self, json_file):
session = self.__prepare_session()
jdata = json.load(open(json_file))
url = urljoin(self.root_url, 'servers/add')
response = session.post(url, data=json.dumps(jdata))
return self._check_response(response)