Skip to content

Commit e5ef544

Browse files
committed
[IDEV-282] bugbash: add short-hand for source file param; add max limit of 100 to list of domains in a source file
1 parent 083a287 commit e5ef544

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

domaintools/cli/api.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
from typing import Optional, Dict, Tuple
88
from rich.progress import Progress, SpinnerColumn, TextColumn
9-
from rich import console
109

1110
from domaintools.api import API
1211
from domaintools.exceptions import ServiceException
1312
from domaintools.cli.utils import get_file_extension
1413

15-
console = console.Console()
16-
1714

1815
class DTCLICommand:
1916
API_SUCCESS_STATUS = 200
@@ -129,6 +126,13 @@ def _get_domains_from_source(cls, source: str) -> Dict[str, str]:
129126
domains.extend([row.get("domain") or "" for row in reader])
130127
else:
131128
domains.extend([domain.strip() for domain in src.readlines()])
129+
130+
total_domains_found = len(domains)
131+
if total_domains_found > 100:
132+
raise typer.BadParameter(
133+
f"Domains in source file exceeds the maximum count of 100. Current source file domain count: {total_domains_found}"
134+
)
135+
132136
except FileNotFoundError:
133137
raise typer.BadParameter(f"File '{source}' not found.")
134138

@@ -198,13 +202,11 @@ def run(cls, name: str, params: Optional[Dict] = {}, **kwargs):
198202

199203
if isinstance(out_file, _io.TextIOWrapper):
200204
# use rich `print` command to prettify the ouput in sys.stdout
201-
print(output)
205+
print(response)
202206
else:
203207
# if it's a file then write
204208
out_file.write(output if output.endswith("\n") else output + "\n")
205-
time.sleep(0.5)
206-
207-
name = typer.style(name, fg=typer.colors.CYAN, bold=True)
209+
time.sleep(0.25)
208210
except Exception as e:
209211
if isinstance(e, ServiceException):
210212
code = typer.style(getattr(e, "code", 400), fg=typer.colors.BRIGHT_RED)
@@ -218,7 +220,7 @@ def run(cls, name: str, params: Optional[Dict] = {}, **kwargs):
218220

219221
reason = typer.style(_reason, bg=typer.colors.RED)
220222

221-
err_msg_format = f"Error occured while fetching data from API: [{code}] Reason: {reason}"
223+
err_msg_format = f"Error occured while fetching data from the API: [{code}] Reason: {reason}"
222224
typer.echo(message=err_msg_format)
223225
else:
224226
typer.echo(message=e)

domaintools/cli/commands/iris.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def iris_investigate(
3030
),
3131
src_file: str = typer.Option(
3232
None,
33+
"-s",
3334
"--source-file",
34-
help="Comma-separated list of domains. Supports only {.csv, .txt} format",
35+
help="Comma-separated list of maximum 100 domains. Supports only {.csv, .txt} format",
3536
callback=DTCLICommand.validate_source_file_extension,
3637
),
3738
user: str = typer.Option(None, "-u", "--user", help="Domaintools API Username."),
@@ -81,8 +82,9 @@ def iris_enrich(
8182
domains: str = typer.Option(None, "-d", "--domains", help="Domains to use."),
8283
src_file: str = typer.Option(
8384
None,
85+
"-s",
8486
"--source-file",
85-
help="Comma-separated list of domains. Supports only {.csv, .txt} format",
87+
help="Comma-separated list of maximum 100 domains. Supports only {.csv, .txt} format",
8688
callback=DTCLICommand.validate_source_file_extension,
8789
),
8890
user: str = typer.Option(None, "-u", "--user", help="Domaintools API Username."),

0 commit comments

Comments
 (0)