From cd6b5965745b11cf79e45fe7e1b309b486544833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 13 Feb 2018 11:25:05 +0100 Subject: [PATCH] new: APIs to manage sharing groups Fix #185 --- pymisp/api.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pymisp/api.py b/pymisp/api.py index 7e9b531..437a4c5 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1736,6 +1736,52 @@ class PyMISP(object): # DEPRECATED return self.cache_feeds_all() + # ###################### + # ### Sharing Groups ### + # ###################### + + def sharing_group_org_add(self, sharing_group, organisation, extend=False): + '''Add an organisation to a sharing group. + :sharing_group: Sharing group's local instance ID, or Sharing group's global UUID + :organisation: Organisation's local instance ID, or Organisation's global UUID, or Organisation's name as known to the curent instance + :extend: Allow the organisation to extend the group + ''' + to_jsonify = {'sg_id': sharing_group, 'org_id': organisation, 'extend': extend} + url = urljoin(self.root_url, '/sharingGroups/addOrg') + response = self.__prepare_request('POST', url, json.dumps(to_jsonify)) + return self._check_response(response) + + def sharing_group_org_remove(self, sharing_group, organisation): + '''Remove an organisation from a sharing group. + :sharing_group: Sharing group's local instance ID, or Sharing group's global UUID + :organisation: Organisation's local instance ID, or Organisation's global UUID, or Organisation's name as known to the curent instance + ''' + to_jsonify = {'sg_id': sharing_group, 'org_id': organisation} + url = urljoin(self.root_url, '/sharingGroups/removeOrg') + response = self.__prepare_request('POST', url, json.dumps(to_jsonify)) + return self._check_response(response) + + def sharing_group_server_add(self, sharing_group, server, all_orgs=False): + '''Add a server to a sharing group. + :sharing_group: Sharing group's local instance ID, or Sharing group's global UUID + :server: Server's local instance ID, or URL of the Server, or Server's name as known to the curent instance + :all_orgs: Add all the organisations of the server to the group + ''' + to_jsonify = {'sg_id': sharing_group, 'server_id': server, 'all_orgs': all_orgs} + url = urljoin(self.root_url, '/sharingGroups/addServer') + response = self.__prepare_request('POST', url, json.dumps(to_jsonify)) + return self._check_response(response) + + def sharing_group_server_remove(self, sharing_group, server): + '''Remove a server from a sharing group. + :sharing_group: Sharing group's local instance ID, or Sharing group's global UUID + :server: Server's local instance ID, or URL of the Server, or Server's name as known to the curent instance + ''' + to_jsonify = {'sg_id': sharing_group, 'server_id': server} + url = urljoin(self.root_url, '/sharingGroups/removeServer') + response = self.__prepare_request('POST', url, json.dumps(to_jsonify)) + return self._check_response(response) + # ################### # ### Objects ### # ###################