|
1 | | - |
2 | 1 | # 🚀 Darktrace Python SDK |
3 | 2 |
|
4 | 3 |  |
5 | 4 |  |
6 | 5 |  |
7 | 6 |
|
8 | | - |
9 | 7 | > **A modern, Pythonic SDK for the Darktrace Threat Visualizer API.** |
10 | 8 |
|
11 | | - |
12 | 9 | --- |
13 | 10 |
|
| 11 | +## 🆕 Latest Updates (v0.9.0) |
14 | 12 |
|
15 | | -## 🆕 Latest Updates (v0.8.55) |
| 13 | +### New Features |
| 14 | +- **Connection Pooling**: Automatic HTTP connection pooling via `requests.Session()` for 4x faster requests on reused connections |
| 15 | +- **Context Manager Support**: Use `with DarktraceClient(...) as client:` for proper resource cleanup |
| 16 | +- **Automatic Retry Logic**: Transient failures (5xx, 429, connection errors) are automatically retried (3 retries with exponential backoff: 3s, 6s, 12s) |
| 17 | +- **SSRF Protection**: URL scheme validation blocks dangerous schemes (`file://`, `ftp://`, `data://`, `javascript://`) |
| 18 | +- **Configurable Timeout**: New `timeout` parameter on `DarktraceClient` |
16 | 19 |
|
17 | | -- **Feature: Add 13 missing parameters to devicesummary endpoint** - Added support for `device_name`, `ip_address`, `end_timestamp`, `start_timestamp`, `devicesummary_by`, `devicesummary_by_value`, `device_type`, `network_location`, `network_location_id`, `peer_id`, `source`, and `status` parameters to align with Darktrace API specification |
18 | | -- **Documentation: Update devicesummary documentation** - Added examples and parameter descriptions for new filtering options |
19 | | -- **Note: devicesummary HTTP 500 limitation confirmed** - Documentation updated to clarify that all devicesummary parameters return HTTP 500 with API token authentication (Darktrace backend limitation, not SDK bug) |
| 20 | +### Improvements |
| 21 | +- **Error Handling**: `ModelBreaches` methods now properly re-raise exceptions instead of returning error dicts |
| 22 | +- **SSL Verification**: Enabled by default for security (verify_ssl=True) |
20 | 23 |
|
21 | | -## 📝 Previous Updates (v0.8.54) |
| 24 | +### Bug Fixes |
| 25 | +- Fixed IntelFeed `fulldetails` parameter name in examples |
22 | 26 |
|
23 | | -- **Fix: Multi-parameter devicesearch query format (fixes #45)** - Changed query parameter joining from explicit ' AND ' to space separation per Darktrace API specification |
24 | | -- **Fix: ensure host URL includes protocol (default to https if missing)** |
| 27 | +> For previous updates, see [GitHub Releases](https://github.com/LegendEvent/darktrace-sdk/releases) or [CHANGELOG.md](CHANGELOG.md). |
25 | 28 |
|
26 | 29 | --- |
27 | 30 |
|
|
31 | 34 | - **Extensive API Coverage**: Most endpoints, parameters, and actions from the official Darktrace API Guide are implemented. |
32 | 35 | - **Modular & Maintainable**: Each endpoint group is a separate Python module/class. |
33 | 36 | - **Easy Authentication**: Secure HMAC-SHA1 signature generation and token management. |
| 37 | +- **SSL Verification**: SSL certificate verification is enabled by default for secure connections. |
34 | 38 | - **Async-Ready**: Designed for easy extension to async workflows. |
35 | 39 | - **Type Hints & Docstrings**: Full typing and documentation for all public methods. |
36 | 40 | - **Comprehensive Documentation**: Detailed documentation for every module and endpoint. |
37 | 41 |
|
38 | 42 | --- |
39 | 43 |
|
| 44 | +## 🔒 SSL Certificate Verification |
| 45 | + |
| 46 | +**SSL verification is enabled by default (`verify_ssl=True`)** for secure connections to your Darktrace instance. |
| 47 | + |
| 48 | +For development or testing environments with self-signed certificates, you can disable verification: |
| 49 | + |
| 50 | +```python |
| 51 | +client = DarktraceClient( |
| 52 | + host="https://your-darktrace-instance", |
| 53 | + public_token="YOUR_PUBLIC_TOKEN", |
| 54 | + private_token="YOUR_PRIVATE_TOKEN", |
| 55 | + verify_ssl=False # Only for development/testing |
| 56 | +) |
| 57 | +``` |
| 58 | + |
| 59 | +> ⚠️ **Warning**: Disabling SSL verification exposes your connection to man-in-the-middle attacks. Never disable in production environments. |
| 60 | +
|
| 61 | +### Using Self-Signed Certificates with verify_ssl=True |
| 62 | + |
| 63 | +For production environments with self-signed certificates, add the certificate to your system trust store instead of disabling verification: |
| 64 | + |
| 65 | +```bash |
| 66 | +# 1. Get the certificate from your Darktrace instance |
| 67 | +openssl s_client -showcerts -connect your-darktrace-instance:443 </dev/null 2>/dev/null | openssl x509 -outform PEM > ~/darktrace-cert.pem |
| 68 | + |
| 69 | +# 2. Copy to system CA store (Linux/Ubuntu/Debian) |
| 70 | +sudo cp ~/darktrace-cert.pem /usr/local/share/ca-certificates/darktrace-cert.crt |
| 71 | +sudo update-ca-certificates |
| 72 | + |
| 73 | +# 3. Now verify_ssl=True will work |
| 74 | +``` |
| 75 | + |
| 76 | +**Alternative (no sudo required):** |
| 77 | +```bash |
| 78 | +# Create a custom CA bundle and set environment variable |
| 79 | +cat /etc/ssl/certs/ca-certificates.crt ~/darktrace-cert.pem > ~/.custom-ca-bundle.pem |
| 80 | +export REQUESTS_CA_BUNDLE=~/.custom-ca-bundle.pem |
| 81 | +``` |
| 82 | + |
| 83 | +--- |
| 84 | + |
40 | 85 | ## 📦 Installation |
41 | 86 |
|
42 | 87 | ```bash |
@@ -64,13 +109,21 @@ pip install . |
64 | 109 | ```python |
65 | 110 | from darktrace import DarktraceClient |
66 | 111 |
|
67 | | -# Initialize the client |
| 112 | +# Initialize the client (SSL verification enabled by default) |
68 | 113 | client = DarktraceClient( |
69 | 114 | host="https://your-darktrace-instance", |
70 | 115 | public_token="YOUR_PUBLIC_TOKEN", |
71 | 116 | private_token="YOUR_PRIVATE_TOKEN" |
72 | 117 | ) |
73 | 118 |
|
| 119 | +# For development with self-signed certificates, disable SSL verification: |
| 120 | +# client = DarktraceClient( |
| 121 | +# host="https://your-darktrace-instance", |
| 122 | +# public_token="YOUR_PUBLIC_TOKEN", |
| 123 | +# private_token="YOUR_PRIVATE_TOKEN", |
| 124 | +# verify_ssl=False # Not recommended for production |
| 125 | +# ) |
| 126 | + |
74 | 127 | # Access endpoint groups |
75 | 128 | devices = client.devices |
76 | 129 | all_devices = devices.get() |
|
0 commit comments