Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump sphinx from 6.2.1 to 7.0.0 #476

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
21e305b
chore(deps): bump rich from 13.3.4 to 13.3.5
dependabot[bot] Apr 28, 2023
4f5c1b3
chore(deps): bump requests from 2.29.0 to 2.30.0
dependabot[bot] May 5, 2023
92e29e6
chore(deps-dev): bump types-requests from 2.28.11.17 to 2.30.0.0
dependabot[bot] May 5, 2023
02178fc
fix: retry on 500s
thehappydinoa May 1, 2023
e9d2a6f
build(dev-deps): bump types-requests from 2.28.11.17 to 2.29.0.0
thehappydinoa May 1, 2023
dc6b371
chore: update gitignore
thehappydinoa May 2, 2023
4d65d11
chore: add scripts to exclude list
thehappydinoa May 5, 2023
1c968c9
feat: maximize api calls for subdomains command
thehappydinoa May 5, 2023
e1d4be2
feat(ci): make pre-commit faster
thehappydinoa May 5, 2023
b0489ec
fix(tests): mock sleep timer
thehappydinoa May 5, 2023
64be8d1
feat(api): respect the retry-after header
thehappydinoa May 5, 2023
d87e576
chore: add comment
thehappydinoa May 5, 2023
d203597
fix(cli): remove csv option as format
thehappydinoa May 5, 2023
0dc3f00
feat(cli): add basic autocomplete
thehappydinoa May 5, 2023
e49de6f
feat(cli): add field auto complete for certs and hosts
thehappydinoa May 7, 2023
44eee5c
docs: add autocomplete setup
thehappydinoa May 7, 2023
a0a5699
docs: update autocomplete instructions
thehappydinoa May 7, 2023
ef610db
docs: update autocomplete notes
thehappydinoa May 8, 2023
646f901
chore: add update autocomplete script
thehappydinoa May 8, 2023
a70a9d7
chore: update autocomplete functionality
thehappydinoa May 8, 2023
ac1f050
chore(cli): remove fields for subdomains command
thehappydinoa May 8, 2023
066e0e5
build: bump version
thehappydinoa May 8, 2023
eee8825
build(doc-deps): pin urllib3 to versions less than 2
thehappydinoa May 8, 2023
15cb2cb
build(doc-deps): pin urllib3 to versions less than 2.0.0
thehappydinoa May 8, 2023
db3d4b3
chore(deps): bump sphinx from 6.2.1 to 7.0.0
dependabot[bot] May 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ exclude =
# This contains our built documentation
build,
# This contains builds of flake8 that we don't want to check
dist
dist,
# This contains various user scripts
scripts
per-file-ignores =
tests/*.py:E501,D100,D101,D102,D103,D104,D107,
__init__.py:F401,F403,
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A clear and concise description of what you expected to happen.
**Device (please complete the following information):**

- OS [e.g. debian, macOS]:
- Censys Python Version [e.g. 2.1.0]: <!-- $ censys --version -->
- Censys Python Version [e.g. 2.2.1]: <!-- $ censys --version -->
- Shell [e.g. bash, zsh]: <!-- $ echo $SHELL -->

**Additional context**
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ dmypy.json
# Config
*.cfg

# Scripts
scripts/*.py

# Output
censys-query-output.*
censys-view-*
*.json
*.csv
*.txt
*.xml

# Autocomplete
!censys/cli/data/*_autocomplete.json
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,30 @@ repos:
pass_filenames: false
language: system
types: [python]
- id: system
name: pytest
entry: poetry run pytest --cov --cov-fail-under=100
pass_filenames: false
language: system
types: [python]
- id: system
name: flake8
entry: poetry run flake8 .
pass_filenames: false
language: system
types: [python]
require_serial: true
args: [--darglint-ignore-regex, .*] # Skip docstring checks
- id: system
name: mypy
entry: poetry run mypy censys
pass_filenames: false
language: system
types: [python]
require_serial: true
- id: system
name: update autocomplete
entry: bash scripts/update_autocomplete.sh
pass_filenames: false
language: system
types: []
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-organge.svg?logo=git&logoColor=organge)](http://makeapullrequest.com)
[![License](https://img.shields.io/github/license/censys/censys-python?logo=apache)](https://github.com/censys/censys-python/blob/main/LICENSE)

An easy-to-use and lightweight API wrapper for Censys APIs ([censys.io](https://censys.io/)). Python 3.7.2+ is currently supported.
An easy-to-use and lightweight API wrapper for Censys APIs ([censys.io](https://censys.io/)). Python 3.7.2+ is currently supported. This library has been tested on Python 3.7 and 3.x (Currently version 3.11).

> **Notice:** The Censys Search v1 endpoints are deprecated as of Nov. 30, 2021. Please begin using v2 endpoints to query hosts and certificates and check out our [support center](https://support.censys.io/hc/en-us/sections/360013076551-Censys-Search-2-0) for resources.

Expand All @@ -19,7 +19,9 @@ An easy-to-use and lightweight API wrapper for Censys APIs ([censys.io](https://
- [Manage assets, events, and seeds in Censys ASM](https://censys-python.readthedocs.io/en/stable/usage-asm.html)
- [Command-line interface](https://censys-python.readthedocs.io/en/stable/cli.html)

<!-- markdownlint-disable MD033 -->
<a href="https://asciinema.org/a/500416" target="_blank"><img src="https://asciinema.org/a/500416.svg" width="600"/></a>
<!-- markdownlint-enable MD033 -->

## Getting Started

Expand All @@ -35,6 +37,22 @@ To upgraded using `pip`.
pip install --upgrade censys
```

Or, you can install the library from source using `poetry`.

```sh
git clone https://github.com/censys/censys-python.git
cd censys-python/
poetry install
```

Optionally, you can enable tab completion for the CLI by adding this line to your `~/.bashrc`, `~/.zshrc`, or equivalent.

> Please note that autocomplete is supported for field names in the `search` command.

```sh
eval "$(register-python-argcomplete censys)"
```

To configure your search credentials run `censys config` or set both `CENSYS_API_ID` and `CENSYS_API_SECRET` environment variables.

```sh
Expand Down
6 changes: 6 additions & 0 deletions censys/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
"""Interact with the Censys Search API through the command line."""
import sys

import argcomplete

from .args import get_parser
from censys.common.version import __version__

Expand All @@ -10,6 +13,9 @@ def main():
"""Main cli function."""
parser = get_parser()

# Adds autocomplete
argcomplete.autocomplete(parser)

# Executes by subcommand
args = parser.parse_args()

Expand Down
47 changes: 43 additions & 4 deletions censys/cli/commands/search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Censys search CLI."""
import argparse
import json
import sys
import webbrowser
from pathlib import Path
from typing import Any, Dict, List
from urllib.parse import urlencode

Expand All @@ -12,6 +14,43 @@

Results = List[dict]

DATA_DIR = Path(__file__).parent.parent / "data"
HOSTS_AUTOCOMPLETE = DATA_DIR / "hosts_autocomplete.json"
CERTIFICATES_AUTOCOMPLETE = DATA_DIR / "certificates_autocomplete.json"


def fields_completer(
prefix: str, parsed_args: argparse.Namespace, **kwargs
) -> List[str]:
"""Fields completer.

Args:
prefix (str): Prefix to complete.
parsed_args (Namespace): Argparse Namespace.
**kwargs: Keyword arguments.

Returns:
List[str]: List of fields.
"""
index_type = parsed_args.index_type
autocomplete_json = {}
if index_type == "hosts":
with HOSTS_AUTOCOMPLETE.open() as autocomplete_file:
autocomplete_json = json.load(autocomplete_file)
elif index_type == "certificates":
with CERTIFICATES_AUTOCOMPLETE.open() as autocomplete_file:
autocomplete_json = json.load(autocomplete_file)
else:
return []

autocomplete_data = autocomplete_json.get("data", [])
fields = [field["value"] for field in autocomplete_data]

if not prefix:
# Returns first 20 fields if no prefix is provided
return fields[:20]
return fields


def cli_search(args: argparse.Namespace):
"""Search subcommand.
Expand Down Expand Up @@ -109,7 +148,7 @@ def include(parent_parser: argparse._SubParsersAction, parents: dict):
"query",
type=str,
help="a string written in Censys Search syntax",
)
).completer = fields_completer

index_metavar = "|".join(V2_INDEXES)
index_default = "hosts"
Expand All @@ -127,8 +166,8 @@ def include(parent_parser: argparse._SubParsersAction, parents: dict):
"--format",
type=str,
default="screen",
choices=["screen", "json", "csv"],
metavar="screen|json|csv",
choices=["screen", "json"],
metavar="screen|json",
help=argparse.SUPPRESS,
)
search_parser.add_argument(
Expand Down Expand Up @@ -189,6 +228,6 @@ def include(parent_parser: argparse._SubParsersAction, parents: dict):
type=str,
nargs="+",
help="additional fields to return in the matched certificates",
)
).completer = fields_completer

search_parser.set_defaults(func=cli_search)
4 changes: 3 additions & 1 deletion censys/cli/commands/subdomains.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def cli_subdomains(args: argparse.Namespace): # pragma: no cover
certificate_query = f"names: {args.domain}"

with err_console.status(f"Querying {args.domain} subdomains"):
query = client.search(certificate_query, fields=["names"], pages=args.pages)
query = client.search(
certificate_query, per_page=100, pages=args.pages
) # 100 is the max per page

# Flatten the result, and remove duplicates
for hits in query:
Expand Down
Loading