Skip to content

Commit eae9a74

Browse files
feat(api): Added Host Diff API (#235)
* feat(api): Host Diff API * chore(typing): Update typing for tests * chore(deps): Upgrade rich * chore(api): Enhance multithreaded API calls * fix(deps): Correct importlib-metadata versions * chore(docs): Add host diff example * chore(cli): Improve error handling and tests * chore(docs): Improve usage * fix(cli): Properly handle CLI errors * feat(dev-deps): Add blacken-docs * chore(dev-deps): Add pyupgrade * feat(cli): Improved config options * chore(deps): Update packages * chore: Remove extra whitespace * chore(ci): Show missing coverage * fix(test): Increase config coverage
1 parent 910c563 commit eae9a74

38 files changed

+590
-281
lines changed

.coveragerc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[run]
2-
include =
2+
include =
33
censys/*
4+
5+
[report]
6+
show_missing = true

.flake8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
max-line-length = 88
3-
exclude =
3+
exclude =
44
docs,
55
.venv,
66
# No need to traverse our git directory
@@ -11,7 +11,7 @@ exclude =
1111
build,
1212
# This contains builds of flake8 that we don't want to check
1313
dist
14-
per-file-ignores =
14+
per-file-ignores =
1515
tests/*.py:E501,D100,D101,D102,D103,D104,D107,
1616
__init__.py:F401,F403,
1717
censys/search/v2/certs.py:DAR101

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ dmypy.json
7575

7676
# IDE
7777
.vscode/
78+
.idea/
79+
80+
# Config
81+
*.cfg
82+
.pre-commit-config.yaml
7883

7984
# Output
8085
censys-query-output.*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Successfully authenticated
6868
- [Documentation](https://censys-python.rtfd.io)
6969
- [Discussions](https://github.com/censys/censys-python/discussions)
7070
- [Censys Homepage](https://censys.io/)
71+
- [Censys Search](https://search.censys.io/)
7172

7273
## Contributing
7374

censys/cli/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ def main():
1919

2020
try:
2121
args.func(args)
22-
except AttributeError:
23-
parser.print_help()
24-
parser.exit()
2522
except KeyboardInterrupt: # pragma: no cover
2623
sys.exit(1)
2724

censys/cli/args.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ def get_parser() -> argparse.ArgumentParser:
4646
default=False,
4747
help="display version",
4848
)
49-
parser.set_defaults()
49+
50+
def print_help(_: argparse.Namespace):
51+
"""Prints help."""
52+
parser.print_help()
53+
parser.exit()
54+
55+
parser.set_defaults(func=print_help)
5056

5157
subparsers = parser.add_subparsers()
5258

censys/cli/commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Censys CLI commands."""
22
from . import account, asm, config, hnri, search, view
33

4-
__all__ = ["asm", "config", "hnri", "search", "view", "account"]
4+
__all__ = ["account", "asm", "config", "hnri", "search", "view"]

censys/cli/commands/asm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def cli_add_seeds(args: argparse.Namespace):
6060
if args.input_file == "-":
6161
data = sys.stdin.read()
6262
else:
63-
with open(args.input_file, "r") as f:
63+
with open(args.input_file) as f:
6464
data = f.read()
6565
else:
6666
data = args.json

censys/cli/commands/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,24 @@ def cli_config(_: argparse.Namespace): # pragma: no cover
6060
client = CensysSearchAPIv2(api_id, api_secret)
6161
account = client.account()
6262
email = account.get("email")
63+
console.print(f"\nSuccessfully authenticated for {email}")
6364

6465
# Assumes that login was successfully
6566
config.set(DEFAULT, "api_id", api_id)
6667
config.set(DEFAULT, "api_secret", api_secret)
6768

6869
write_config(config)
69-
console.print(f"\nSuccessfully authenticated for {email}")
7070
sys.exit(0)
7171
except CensysUnauthorizedException:
7272
console.print("Failed to authenticate")
7373
sys.exit(1)
74+
except PermissionError as e:
75+
console.print(e)
76+
console.print(
77+
"Cannot write config file to directory. "
78+
+ "Please set the `CENSYS_CONFIG_PATH` environmental variable to a writeable location."
79+
)
80+
sys.exit(1)
7481

7582

7683
def include(parent_parser: argparse._SubParsersAction, parents: dict):

censys/cli/commands/hnri.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def include(parent_parser: argparse._SubParsersAction, parents: dict):
166166
parents=[parents["auth"]],
167167
)
168168
hnri_parser.add_argument(
169+
"-O",
169170
"--open",
170171
action="store_true",
171172
help="open your IP in browser",

0 commit comments

Comments
 (0)