/DarkTrace-API

Primary LanguagePythonMIT LicenseMIT

Introduction

This Python class DarkTrace acts as a wrapper for interacting with the DarkTrace API. DarkTrace is a cyber AI security platform. This wrapper simplifies the API calls to DarkTrace by handling authentication and request signing.

Please note that using this code may require certain permissions and configurations on your DarkTrace system. Make sure that you are authorized to interact with the DarkTrace APIs and that your system is properly configured.

Dependencies

  • Python 3.6+
  • requests library
  • hashlib and hmac (usually available with Python standard library)

To install the requests library, use pip pip install requests

Usage

Initialization

First, you need to initialize the DarkTrace class with the IP address of your DarkTrace system, the API token, and the private key:

from darktrace import DarkTrace ip_address = "your_darktrace_ip" api_token = "your_api_token" private_key = "your_private_key" darktrace = DarkTrace(ip=ip_address, token=api_token, private=private_key)

Replace your_darktrace_ip, your_api_token, and your_private_key with the actual values.

Making API Calls

Once initialized, you can use the api_call method to make calls to the DarkTrace API. The api_call method takes in the type of API call (as a string) and a dictionary of parameters.

For example:

parameters = {"param1": "value1", "param2": "value2"} response = darktrace.api_call("endpoint", parameters) print(response)

Here, "endpoint" should be replaced with the actual API endpoint you want to call, and parameters should be a dictionary containing the parameters for the call.

Error Handling

If an error occurs during the API call, an exception will be raised with a message describing the issue. It is recommended to use try/except blocks for proper error handling:

try: response = darktrace.api_call("endpoint", parameters) print(response) except Exception as e: print(f"Error: {str(e)}")

Security Note

This code disables SSL verification (verify=False) when making API calls. This is generally not recommended for production systems as it can expose you to security vulnerabilities. It is recommended to use SSL verification in production systems by providing the path to the certificate:

response = self.session.get(url, verify='/path/to/certificate', headers=headers)

License

This script is released under the MIT License. Feel free to use and modify it according to your needs.

Disclaimer

This code is provided as-is, and it is important to review and understand it before using it in production environments. The author is not responsible for any unintended consequences of using this code.