Skip to content

Commit

Permalink
chore: fix sample queries
Browse files Browse the repository at this point in the history
  • Loading branch information
thehappydinoa committed Jun 5, 2023
1 parent c6151cd commit dc45928
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions censys/search/v2/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CensysHosts(CensysSearchAPIv2):
Simple host search.
>>> for page in h.search("service.service_name: HTTP"):
>>> for page in h.search("services.service_name: HTTP"):
>>> print(page)
[
{
Expand All @@ -42,7 +42,7 @@ class CensysHosts(CensysSearchAPIv2):
Simple host aggregate.
>>> h.aggregate("service.service_name: HTTP", "services.port", num_buckets=5)
>>> h.aggregate("services.service_name: HTTP", "services.port", num_buckets=5)
{
'total_omitted': 591527370,
'buckets': [
Expand All @@ -54,7 +54,7 @@ class CensysHosts(CensysSearchAPIv2):
],
'potential_deviation': 3985101,
'field': 'services.port',
'query': 'service.service_name: HTTP',
'query': 'services.service_name: HTTP',
'total': 172588754
}
Expand Down
6 changes: 3 additions & 3 deletions examples/search/aggregate_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The aggregate method constructs a report using a query, an aggregation field, and the
# number of buckets to bin.
report = c.v2.hosts.aggregate(
"service.service_name: HTTP",
"services.service_name: HTTP",
"services.port",
num_buckets=5,
)
Expand All @@ -22,13 +22,13 @@
# {"key": "22", "count": 13276559},
# {"key": "30005", "count": 12487489},
# ],
# "query": "service.service_name: HTTP",
# "query": "services.service_name: HTTP",
# "field": "services.port",
# }

# You can also specify whether to include virtual hosts in the report.
report = c.v2.hosts.aggregate(
"service.service_name: HTTP",
"services.service_name: HTTP",
"services.port",
num_buckets=5,
virtual_hosts="INCLUDE",
Expand Down
6 changes: 3 additions & 3 deletions examples/search/search_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
h = CensysHosts()

# Single page of search results
query = h.search("service.service_name: HTTP", per_page=5)
query = h.search("services.service_name: HTTP", per_page=5)
print(query())

# Multiple pages of search results
query = h.search("service.service_name: HTTP", per_page=5, pages=2)
query = h.search("services.service_name: HTTP", per_page=5, pages=2)
for page in query:
for host in page:
print(host)

# View all results
query = h.search("service.service_name: HTTP", per_page=5, pages=2)
query = h.search("services.service_name: HTTP", per_page=5, pages=2)
print(query.view_all())

# Search for virtual hosts
Expand Down
2 changes: 1 addition & 1 deletion examples/search/view_all_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
h = CensysHosts()

# Search for hosts with a specific service
query = h.search("service.service_name: FTP", per_page=1, pages=2)
query = h.search("services.service_name: FTP", per_page=1, pages=2)
# View all results
all_hosts = query.view_all()
print(all_hosts)
28 changes: 14 additions & 14 deletions tests/cli/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_write_screen(self):
self.responses.add(
responses.GET,
V2_URL
+ "/hosts/search?q=service.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE",
+ "/hosts/search?q=services.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE",
status=200,
json=SEARCH_HOSTS_JSON,
)
Expand All @@ -119,7 +119,7 @@ def test_write_screen(self):
[
"censys",
"search",
"service.service_name: HTTP",
"services.service_name: HTTP",
"--index-type",
"hosts",
"--pages",
Expand All @@ -142,7 +142,7 @@ def test_search_virtual_hosts(self):
self.responses.add(
responses.GET,
V2_URL
+ "/hosts/search?q=service.service_name%3A+HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=ONLY",
+ "/hosts/search?q=services.service_name%3A+HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=ONLY",
status=200,
json=SEARCH_HOSTS_JSON,
)
Expand All @@ -151,7 +151,7 @@ def test_search_virtual_hosts(self):
[
"censys",
"search",
"service.service_name: HTTP",
"services.service_name: HTTP",
"--index-type",
"hosts",
"--pages",
Expand All @@ -176,7 +176,7 @@ def test_search_sort_order(self):
self.responses.add(
responses.GET,
V2_URL
+ "/hosts/search?q=service.service_name%3A+HTTP&per_page=100&sort=RANDOM&virtual_hosts=EXCLUDE",
+ "/hosts/search?q=services.service_name%3A+HTTP&per_page=100&sort=RANDOM&virtual_hosts=EXCLUDE",
status=200,
json=SEARCH_HOSTS_JSON,
)
Expand All @@ -185,7 +185,7 @@ def test_search_sort_order(self):
[
"censys",
"search",
"service.service_name: HTTP",
"services.service_name: HTTP",
"--index-type",
"hosts",
"--pages",
Expand All @@ -210,7 +210,7 @@ def test_write_json(self):
self.responses.add(
responses.GET,
V2_URL
+ "/hosts/search?q=service.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE",
+ "/hosts/search?q=services.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE",
status=200,
json=SEARCH_HOSTS_JSON,
)
Expand All @@ -219,7 +219,7 @@ def test_write_json(self):
[
"censys",
"search",
"service.service_name: HTTP",
"services.service_name: HTTP",
"--index-type",
"hosts",
"--pages",
Expand Down Expand Up @@ -258,7 +258,7 @@ def test_write_csv_fail(self):
[
"censys",
"search",
"service.service_name: HTTP",
"services.service_name: HTTP",
"--index-type",
"hosts",
"--pages",
Expand Down Expand Up @@ -287,14 +287,14 @@ def test_midway_fail(self, status_code: int, json_response: dict):
self.responses.add(
responses.GET,
V2_URL
+ "/hosts/search?q=service.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE",
+ "/hosts/search?q=services.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE",
status=200,
json=SEARCH_HOSTS_JSON,
)
self.responses.add(
responses.GET,
V2_URL
+ f"/hosts/search?q=service.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE&cursor={next_cursor}",
+ f"/hosts/search?q=services.service_name: HTTP&per_page=100&sort=RELEVANCE&virtual_hosts=EXCLUDE&cursor={next_cursor}",
status=status_code,
json=json_response,
)
Expand All @@ -303,7 +303,7 @@ def test_midway_fail(self, status_code: int, json_response: dict):
[
"censys",
"search",
"service.service_name: HTTP",
"services.service_name: HTTP",
"--index-type",
"hosts",
"--pages",
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_open_hosts(self):
[
"censys",
"search",
"service.service_name: HTTP",
"services.service_name: HTTP",
"--index-type",
"hosts",
"--open",
Expand All @@ -375,7 +375,7 @@ def test_open_hosts(self):
# Actual call/error raising
with pytest.raises(SystemExit, match="0"):
cli_main()
query_str = urlencode({"q": "service.service_name: HTTP", "resource": "hosts"})
query_str = urlencode({"q": "services.service_name: HTTP", "resource": "hosts"})
# Assertions
mock_open.assert_called_with(f"https://search.censys.io/search?{query_str}")

Expand Down
Loading

0 comments on commit dc45928

Please sign in to comment.