Skip to content

Commit 1fe6caa

Browse files
authored
Merge pull request #44 from thehappydinoa/adh/update-docs
Update Docs
2 parents 79a1e5f + 7c42412 commit 1fe6caa

File tree

8 files changed

+80
-87
lines changed

8 files changed

+80
-87
lines changed

.readthedocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ python:
1919
version: 3.7
2020
install:
2121
- requirements: docs/requirements.txt
22+
- method: pip
23+
path: .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ All contributions (no matter how small) are always welcome.
3535

3636
```bash
3737
$ git clone git@github.com:censys/censys-python.git
38-
$ pip install -e .[dev]
38+
$ pip install -e ".[dev]"
3939
```
4040

4141
## Testing

censys/cli.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ class CensysAPISearch:
3535
This class searches the Censys API, taking in options from the command line and
3636
returning the results to a CSV or JSON file, or to stdout.
3737
38-
Kwargs:
39-
format (str): Format of results: CSV, JSON, or stdout.
40-
start_page (int): Page number to start from.
41-
max_pages (int): The maximum number of pages of results to return.
42-
api_secret (str): An API secret provided by Censys.
43-
api_id (str): An API ID provided by Censys.
38+
Args:
39+
api_id (str, optional): The API ID provided by Censys.
40+
api_secret (str, optional): The API secret provided by Censys.
41+
start_page (int, optional): Page number to start from. Defaults to 1.
42+
max_pages (int, optional): The maximum number of pages. Defaults to 10.
4443
"""
4544

4645
csv_fields: Fields = list()
@@ -49,7 +48,6 @@ class CensysAPISearch:
4948
def __init__(self, **kwargs):
5049
self.api_user = kwargs.get("api_id")
5150
self.api_pass = kwargs.get("api_secret")
52-
5351
self.start_page = kwargs.get("start_page", 1)
5452
self.max_pages = kwargs.get("max_pages", 10)
5553

@@ -88,8 +86,8 @@ def _write_json(file_path: str, search_results: Results) -> bool:
8886
This method writes the search results to a new file in JSON format.
8987
9088
Args:
91-
file_path (str): name of the file to write to on the disk.
92-
search_results (Results): list of search results from API query.
89+
file_path (str): Name of the file to write to on the disk.
90+
search_results (Results): A list of results from the query.
9391
9492
Returns:
9593
bool: True if wrote to file successfully.
@@ -193,9 +191,9 @@ def _process_search(
193191
This method provides a common way to process searches from the API.
194192
195193
Args:
196-
query: The string to send to the API as a query.
197-
search_index: The data set to be queried - IPv4, Website, or Certificates.
198-
fields: A list of fields to be returned for each result.
194+
query (str): The string to send to the API as a query.
195+
search_index (Index): The data set to be queried.
196+
fields (Fields): A list of fields to be returned for each result.
199197
200198
Returns:
201199
Results: A list of results from the query.
@@ -226,10 +224,11 @@ def search_ipv4(self, **kwargs) -> Results:
226224
"""
227225
A method to search the IPv4 data set via the API.
228226
229-
Kwargs:
230-
query: The string search query.
231-
fields: The fields that should be returned with a query.
232-
overwrite: Overwrite the default list of fields with the given fields.
227+
Args:
228+
query (str): The string search query.
229+
fields (list, optional): The fields that should be returned with a query.
230+
overwrite (bool, optional): Whether to overwrite or append default fields
231+
with user fields. Defaults to False.
233232
234233
Returns:
235234
Results: A list of results from the query.
@@ -270,10 +269,10 @@ def search_certificates(self, **kwargs) -> Results:
270269
A method to search the Certificates data set via the API.
271270
272271
Args:
273-
kwargs:
274-
query: The string search query.
275-
fields: The fields that should be returned with a query.
276-
overwrite: Overwrite the default list of fields with the given fields.
272+
query (str): The string search query.
273+
fields (list, optional): The fields that should be returned with a query.
274+
overwrite (bool, optional): Whether to overwrite or append default fields
275+
with user fields. Defaults to False.
277276
278277
Returns:
279278
Results: A list of results from the query.
@@ -311,10 +310,10 @@ def search_websites(self, **kwargs) -> Results:
311310
A method to search the Websites (Alexa Top 1M) data set via the API.
312311
313312
Args:
314-
kwargs:
315-
query: The string search query.
316-
fields: The fields that should be returned with a query.
317-
overwrite: Overwrite the default list of fields with the given fields.
313+
query (str): The string search query.
314+
fields (list, optional): The fields that should be returned with a query.
315+
overwrite (bool, optional): Whether to overwrite or append default fields
316+
with user fields. Defaults to False.
318317
319318
Returns:
320319
Results: A list of results from the query.
@@ -347,9 +346,9 @@ class CensysHNRI:
347346
"""
348347
This class searches the Censys API, check the user's current IP for risks.
349348
350-
Kwargs:
351-
api_secret (str): An API secret provided by Censys.
352-
api_id (str): An API ID provided by Censys.
349+
Args:
350+
api_id (str, optional): The API ID provided by Censys.
351+
api_secret (str, optional): The API secret provided by Censys.
353352
"""
354353

355354
HIGH_RISK_DEFINITION: List[str] = ["telnet", "redis", "postgres", "vnc"]
@@ -476,10 +475,7 @@ def search(args):
476475
args (Namespace): Argparse Namespace.
477476
"""
478477

479-
censys_args = {"query": args.query}
480-
481-
if args.fields:
482-
censys_args["fields"] = args.fields
478+
censys_args = {}
483479

484480
if args.start_page:
485481
censys_args["start_page"] = args.start_page
@@ -493,11 +489,16 @@ def search(args):
493489
if args.api_secret:
494490
censys_args["api_secret"] = args.api_secret
495491

496-
if args.overwrite:
497-
censys_args["overwrite"] = args.overwrite
498-
499492
censys = CensysAPISearch(**censys_args)
500493

494+
search_args = {"query": args.query}
495+
496+
if args.fields:
497+
search_args["fields"] = args.fields
498+
499+
if args.overwrite:
500+
search_args["overwrite"] = args.overwrite
501+
501502
indexes = {
502503
"ipv4": censys.search_ipv4,
503504
"certs": censys.search_certificates,
@@ -507,7 +508,7 @@ def search(args):
507508
index_type = args.index_type or args.query_type
508509

509510
index_func = indexes[index_type]
510-
results = index_func(**censys_args)
511+
results = index_func(**search_args)
511512

512513
try:
513514
censys.write_file(results, file_format=args.format, file_path=args.output)

docs/development.rst

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,8 @@ Clone the repository:
1919

2020
Install dependencies via ``pip``:
2121

22-
.. tabs::
23-
24-
.. tab:: with macOS
25-
26-
.. prompt:: bash $
22+
.. prompt:: bash $
2723

28-
pip install -e ".[dev]"
29-
30-
.. tab:: with Linux
31-
32-
.. prompt:: bash $
33-
34-
pip install -e .[dev]
24+
pip install -e ".[dev]"
3525

3626
Run the test suite with ``pytest``. More information about testing is available at :ref:`testing:Testing`.

docs/index.rst

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,11 @@ Welcome to Censys Python's documentation!
99
.. automodule:: censys
1010
:members:
1111

12-
Quick start
13-
-----------
14-
15-
Assuming you have Python already, install the package:
16-
17-
.. tabs::
18-
19-
.. tab:: from PyPi
20-
21-
.. prompt:: bash
22-
23-
pip install censys
24-
25-
.. tab:: from GitHub
26-
27-
.. prompt:: bash
28-
29-
pip install git+https://github.com/censys/censys-python@master
30-
31-
Configure your credentials:
32-
33-
.. tabs::
34-
35-
.. tab:: with CLI
36-
37-
.. prompt:: bash
38-
39-
censys config
40-
41-
.. tab:: with environment variables
42-
43-
.. prompt:: bash
44-
45-
export CENSYS_API_ID="XXX"
46-
export CENSYS_API_SECRET="XXX"
47-
48-
4912
.. toctree::
5013
:maxdepth: 1
5114
:caption: Table of Contents
5215

16+
quick-start
5317
usage
5418
cli
5519
censys

docs/quick-start.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Quick Start
2+
===========
3+
4+
Assuming you have Python already, install the package:
5+
6+
.. tabs::
7+
8+
.. tab:: from PyPi
9+
10+
.. prompt:: bash
11+
12+
pip install censys
13+
14+
.. tab:: from GitHub
15+
16+
.. prompt:: bash
17+
18+
pip install git+https://github.com/censys/censys-python@master
19+
20+
Configure your credentials:
21+
22+
.. tabs::
23+
24+
.. tab:: with CLI
25+
26+
.. prompt:: bash
27+
28+
censys config
29+
30+
.. tab:: with environment variables
31+
32+
.. prompt:: bash
33+
34+
export CENSYS_API_ID="XXX"
35+
export CENSYS_API_SECRET="XXX"

docs/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
sphinx
1+
sphinx>=3.2.1
22
sphinxcontrib-napoleon
3+
sphinxcontrib-autoprogram
34
sphinx-rtd-theme
45
sphinx-prompt
56
sphinx-tabs

docs/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To run the full test suite against your changes, simply run ``pytest``.
88

99
.. note::
1010

11-
Tests currently require credentials to be setup. More information about credentials is available at :ref:`index:Quick start`.
11+
Tests currently require credentials to be setup. More information about credentials is available at :ref:`quick-start:Quick Start`.
1212

1313
.. prompt:: bash
1414

0 commit comments

Comments
 (0)