Skip to content

Commit 582d855

Browse files
committed
fix!: update the view_host_events to return a dict instead of just a list
1 parent 8fd1d86 commit 582d855

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

censys/search/v2/hosts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def view_host_events(
259259
per_page: Optional[int] = None,
260260
cursor: Optional[str] = None,
261261
reversed: Optional[bool] = None,
262-
) -> List[dict]:
262+
) -> dict:
263263
"""Fetches a list of events for the specified IP address.
264264
265265
Args:
@@ -275,7 +275,7 @@ def view_host_events(
275275
that is, return events in reversed chronological order.
276276
277277
Returns:
278-
List[dict]: A list of events.
278+
dict: A list of events.
279279
"""
280280
args = {"per_page": per_page, "cursor": cursor, "reversed": reversed}
281281
if start_time:
@@ -285,7 +285,7 @@ def view_host_events(
285285

286286
return self._get(f"/v2/experimental/{self.INDEX_NAME}/{ip}/events", args)[
287287
"result"
288-
]["events"]
288+
]
289289

290290
def list_hosts_with_tag(self, tag_id: str) -> List[str]:
291291
"""Returns a list of hosts which are tagged with the specified tag.

examples/search/view_host_events.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111
from datetime import date
1212

1313
events = h.view_host_events(
14-
"1.1.1.1", start_time=date(2022, 1, 1), end_time=date(2022, 1, 31)
14+
"1.1.1.1", per_page=1, start_time=date(2022, 1, 1), end_time=date(2022, 1, 31)
1515
)
1616
print(events)
17-
# [
18-
# {
19-
# "timestamp": "2022-01-01T00:00:01.713Z",
20-
# "service_observed": {
21-
# "id": {"port": 80, "service_name": "HTTP", "transport_protocol": "TCP"},
22-
# "observed_at": "2021-12-31T23:59:39.910804158Z",
23-
# "perspective_id": "PERSPECTIVE_NTT",
24-
# "changed_fields": [
25-
# {"field_name": "http.request.uri"},
26-
# {"field_name": "http.response.headers.Cf-Ray.headers"},
27-
# {"field_name": "http.response.headers.Location.headers"},
28-
# {"field_name": "banner"},
29-
# ],
30-
# },
31-
# "_event": "service_observed",
32-
# },
33-
# ...
34-
# ]
17+
# {
18+
# 'ip': '1.1.1.1',
19+
# 'events': [
20+
# {
21+
# 'timestamp': '2022-01-01T00:00:01.713Z',
22+
# 'service_observed': {
23+
# 'id': {'port': 80, 'service_name': 'HTTP', 'transport_protocol': 'TCP'},
24+
# 'observed_at': '2021-12-31T23:59:39.910804158Z',
25+
# 'perspective_id': 'PERSPECTIVE_NTT',
26+
# 'changed_fields': [{'field_name': 'http.request.uri'}, {'field_name': 'http.response.headers.Cf-Ray.headers'}, {'field_name': 'http.response.headers.Location.headers'}, {'field_name': 'banner'}, {'field_name': 'banner_hashes'}]
27+
# },
28+
# '_event': 'service_observed'
29+
# }
30+
# ],
31+
# 'links': {
32+
# 'next': 'AS-RtkcKDRPshfT6ojz5ubSuyen_J_J2s9VLmJf9WCg7_jGt0KdU2JvoYW9QXof1Cskvm-b41QyRiR38kWADJuUA_w8rAA5ZNv9llYarhmPv22nIf88JFGGhH0h6dRZ7kDy5RfsiUxNFXeMQQXz0BWYrcQ=='
33+
# }
34+
# }

tests/search/v2/test_hosts.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def test_view_host_diff(self):
820820
),
821821
]
822822
)
823-
def test_view_host_diff_params(self, kwargs, query_params):
823+
def test_view_host_diff_params(self, kwargs: dict, query_params: str):
824824
self.responses.add(
825825
responses.GET,
826826
f"{V2_URL}/hosts/{TEST_HOST}/diff?{query_params}",
@@ -830,18 +830,9 @@ def test_view_host_diff_params(self, kwargs, query_params):
830830
results = self.api.view_host_diff(TEST_HOST, **kwargs)
831831
assert results == VIEW_HOST_DIFF_JSON["result"]
832832

833-
def test_view_host_events(self):
834-
self.responses.add(
835-
responses.GET,
836-
f"{V2_URL}/experimental/hosts/{TEST_HOST}/events",
837-
status=200,
838-
json=VIEW_HOST_EVENTS_JSON,
839-
)
840-
results = self.api.view_host_events(TEST_HOST)
841-
assert results == VIEW_HOST_EVENTS_JSON["result"]["events"]
842-
843833
@parameterized.expand(
844834
[
835+
({}, ""),
845836
({"per_page": 50}, "per_page=50"),
846837
(
847838
{
@@ -856,12 +847,15 @@ def test_view_host_events(self):
856847
),
857848
]
858849
)
859-
def test_view_host_events_params(self, kwargs, query_params):
850+
def test_view_host_events_params(self, kwargs: dict, query_params: str):
851+
url = f"{V2_URL}/experimental/hosts/{TEST_HOST}/events"
852+
if query_params:
853+
url += "?" + query_params
860854
self.responses.add(
861855
responses.GET,
862-
f"{V2_URL}/experimental/hosts/{TEST_HOST}/events?{query_params}",
856+
url,
863857
status=200,
864858
json=VIEW_HOST_EVENTS_JSON,
865859
)
866860
results = self.api.view_host_events(TEST_HOST, **kwargs)
867-
assert results == VIEW_HOST_EVENTS_JSON["result"]["events"]
861+
assert results == VIEW_HOST_EVENTS_JSON["result"]

0 commit comments

Comments
 (0)