Skip to content

Commit 130df4c

Browse files
authored
Rename main class (#2)
* Add DEBUG logging to the API This commit adds debug logs for the request and response. This can be useful later for debugging purposes when this SDK is being used. * Rename main class This commit renames the main class that we use from `Api` to `Nightfall` because it makes it a bit more clear about what is going on when you are using this library in another module.
1 parent 33d4140 commit 130df4c

File tree

7 files changed

+39
-17
lines changed

7 files changed

+39
-17
lines changed

CHANGELOG

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ Changelog
33

44
Here you can see the full list of changes between each Nightfall release.
55

6+
Version 0.4.0
7+
-------------
8+
9+
UNRELEASED
10+
11+
- Add debug logs to Nightfall module
12+
- Change primary class name from ``Api`` to ``Nightfall`` to make things a bit
13+
more clear when this library is used in other programs and allow ``from
14+
nightfall import Nightfall``
15+
16+
.. warning::
17+
This is a breaking change, since the previous version of this SDK
18+
imported Nightfall using ``from nightfall.api import Api``
19+
620
Version 0.3.0
721
-------------
822

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ pip install nightfall
1515
Make a new [API Token](https://app.nightfall.ai/api/) and [Detection Rule Set](https://app.nightfall.ai/detection-engine/detection-rules) in Nightfall and store the values as environment variables.
1616

1717
```
18-
from nightfall import Api
18+
from nightfall import Nightfall
1919
20-
nightfall = Api(
20+
nightfall = Nightfall(
2121
os.getenv('NIGHTFALL_TOKEN'),
2222
os.getenv('NIGHTFALL_CONDITION_SET')
2323
)
2424
2525
response = nightfall.scan(['test string'])
2626
27-
findings = response.json()
28-
print(findings)
27+
print(response)
2928
```
3029

3130
## Contributing

docs/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
API
22
===
33

4-
API Object
5-
----------
4+
Nightfall Object
5+
----------------
66

77
.. automodule:: nightfall.api
88
:members:

docs/quickstart.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ Import Nightfall and start using methods:
2222

2323
::
2424

25-
from nightfall import Api
25+
from nightfall import Nightfall
2626

27-
nightfall = Api(
27+
nightfall = Nightfall(
2828
os.getenv('NIGHTFALL_TOKEN'),
2929
os.getenv('NIGHTFALL_CONDITION_SET')
3030
)
3131

3232
response = nightfall.scan(['test string'])
3333

34-
findings = response.json()
35-
print(findings)
34+
print(response)

nightfall/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
:copyright: (c) 2021 Nightfall
88
:license: MIT, see LICENSE for more details.
99
"""
10+
from .api import Nightfall

nightfall/api.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import requests
1111
import logging
1212

13-
class Api():
13+
class Nightfall():
1414
"""A python interface for the Nightfall API.
1515
1616
.. data:: MAX_PAYLOAD_SIZE
@@ -25,7 +25,7 @@ class Api():
2525
MAX_NUM_ITEMS = 50_000
2626

2727
def __init__(self, token, condition_set):
28-
"""Instantiate a new nightfall.Api object.
28+
"""Instantiate a new Nightfall object.
2929
3030
:param token: Your Nightfall API token.
3131
:param condition_set: Your Nightfall Condition Set UUID
@@ -37,6 +37,8 @@ def __init__(self, token, condition_set):
3737
'Content-Type': 'application/json',
3838
'x-api-key': self.token
3939
}
40+
self.logger = logging.getLogger(__name__)
41+
4042

4143
def make_payloads(self, data):
4244
"""Turn a list of strings into a list of acceptable payloads.
@@ -101,10 +103,17 @@ def scan(self, data):
101103
headers=self._headers,
102104
data=json.dumps(payload)
103105
)
106+
107+
# Logs for Debugging
108+
self.logger.debug(f"HTTP Request URL: {response.request.url}")
109+
self.logger.debug(f"HTTP Request Body: {response.request.body}")
110+
self.logger.debug(f"HTTP Request Headers: {response.request.headers}")
111+
112+
self.logger.debug(f"HTTP Status Code: {response.status_code}")
113+
self.logger.debug(f"HTTP Response Headers: {response.headers}")
114+
self.logger.debug(f"HTTP Response Text: {response.text}")
115+
104116
response.raise_for_status()
105117
responses += response.json()
106118

107119
return responses
108-
109-
110-

tests/nightfall/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import unittest
44
import requests
55

6-
from nightfall.api import Api
6+
from nightfall.api import Nightfall
77

88
class TestNightfallApi(unittest.TestCase):
99

1010
def setUp(self):
11-
self.client = Api(
11+
self.client = Nightfall(
1212
os.getenv('NIGHTFALL_TOKEN'),
1313
os.getenv('NIGHTFALL_CONDITION_SET')
1414
)

0 commit comments

Comments
 (0)