Skip to content

Commit

Permalink
Add discovery routes
Browse files Browse the repository at this point in the history
  • Loading branch information
fenrisl authored and hezanathos committed Nov 22, 2022
1 parent 190e812 commit 684509e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions cbw_api_toolbox/__routes__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ROUTE_COMPLIANCE_ASSETS = "/api/v3/compliance/servers"
ROUTE_COMPLIANCE_RULES = "/api/v3/compliance/rules"
ROUTE_CVE_ANNOUNCEMENTS = "/api/v3/vulnerabilities/cve_announcements"
ROUTE_DISCOVERY = "/api/v3/assets/discoveries"
ROUTE_DOCKER_IMAGES = "/api/v3/assets/docker_images"
ROUTE_GROUPS = "/api/v3/assets/groups"
ROUTE_HOSTS = "/api/v3/hosts"
Expand Down
25 changes: 25 additions & 0 deletions cbw_api_toolbox/cbw_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from cbw_api_toolbox.__routes__ import ROUTE_COMPLIANCE_RULES
from cbw_api_toolbox.__routes__ import ROUTE_COMPLIANCE_ASSETS
from cbw_api_toolbox.__routes__ import ROUTE_CVE_ANNOUNCEMENTS
from cbw_api_toolbox.__routes__ import ROUTE_DISCOVERY
from cbw_api_toolbox.__routes__ import ROUTE_DOCKER_IMAGES
from cbw_api_toolbox.__routes__ import ROUTE_GROUPS
from cbw_api_toolbox.__routes__ import ROUTE_HOSTS
Expand Down Expand Up @@ -803,3 +804,27 @@ def server_reboot(self, server_id, params=None):
return None

return self._cbw_parser(response)

def discoveries(self, params=None):
"""GET request to /api/v3/assets/discoveries to get a list of all discoveries"""
response = self._get_pages("GET", [ROUTE_DISCOVERY], params)

return response

def relaunch_discovery(self, discovery_id):
"""PUT request to /api/v3/assets/discoveries/<discovery_id>/relaunch to get a specific discovery"""
response = self._request("PUT", [ROUTE_DISCOVERY, discovery_id, "relaunch"])
if not response.ok:
logging.error("Error::{}".format(response.text))
return None

return self._cbw_parser(response)

def delete_discovery(self, discovery_id):
"""DELETE request to /api/v3/assets/discoveries/<discovery_id> to get a specific discovery"""
response = self._request("DELETE", [ROUTE_DISCOVERY, discovery_id])
if not response.ok:
logging.error("Error::{}".format(response.text))
return None

return self._cbw_parser(response)
11 changes: 11 additions & 0 deletions examples/discoveries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""GET request to /api/v3/assets/discoveries to get a list of all discoveries"""

import os
from configparser import ConfigParser
from cbw_api_toolbox.cbw_api import CBWApi

CONF = ConfigParser()
CONF.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'api.conf'))
CLIENT = CBWApi(CONF.get('cyberwatch', 'url'), CONF.get('cyberwatch', 'api_key'), CONF.get('cyberwatch', 'secret_key'))

CLIENT.discoveries()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
description='CyberWatch Api Tools.',
long_description=open('README.md').read().strip(),
long_description_content_type="text/markdown",
version='2.2.5',
version='2.3',
author='CyberWatch SAS',
author_email='[email protected]',
license='MIT',
Expand Down

0 comments on commit 684509e

Please sign in to comment.