Skip to content

Commit ded8152

Browse files
authored
Merge pull request #132 from DomainTools/IDEV-282
[IDEV-282] Bugbash
2 parents cb4a147 + f02ad49 commit ded8152

File tree

9 files changed

+158
-123
lines changed

9 files changed

+158
-123
lines changed

domaintools/cli/api.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

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

1110
from domaintools.api import API
1211
from domaintools.exceptions import ServiceException
@@ -73,6 +72,9 @@ def args_to_dict(*args) -> Dict:
7372
for i in range(0, len(args), 2):
7473
key = args[i].replace("--", "")
7574
value = args[i + 1].strip()
75+
# replace all the "-" to "_" to make it a valid kwargs
76+
# we replace all CLI parameters to use "-" instead of underscore.
77+
key = key.replace("-", "_")
7678
argument_dict[key] = value
7779
except:
7880
pass
@@ -124,6 +126,13 @@ def _get_domains_from_source(cls, source: str) -> Dict[str, str]:
124126
domains.extend([row.get("domain") or "" for row in reader])
125127
else:
126128
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+
127136
except FileNotFoundError:
128137
raise typer.BadParameter(f"File '{source}' not found.")
129138

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

194203
if isinstance(out_file, _io.TextIOWrapper):
195204
# use rich `print` command to prettify the ouput in sys.stdout
196-
typer.echo(output)
205+
print(response)
197206
else:
198207
# if it's a file then write
199208
out_file.write(output if output.endswith("\n") else output + "\n")
200-
time.sleep(0.5)
201-
202-
name = typer.style(name, fg=typer.colors.CYAN, bold=True)
209+
time.sleep(0.25)
203210
except Exception as e:
204211
if isinstance(e, ServiceException):
205212
code = typer.style(getattr(e, "code", 400), fg=typer.colors.BRIGHT_RED)
@@ -213,7 +220,7 @@ def run(cls, name: str, params: Optional[Dict] = {}, **kwargs):
213220

214221
reason = typer.style(_reason, bg=typer.colors.RED)
215222

216-
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}"
217224
typer.echo(message=err_msg_format)
218225
else:
219226
typer.echo(message=e)

domaintools/cli/commands/accounts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def account_information(
1919
creds_file: str = typer.Option(
2020
"~/.dtapi",
2121
"-c",
22-
"--cred_file",
22+
"--credfile",
2323
help="Optional file with API username and API key, one per line.",
2424
),
2525
rate_limit: bool = typer.Option(
@@ -36,7 +36,7 @@ def account_information(
3636
callback=DTCLICommand.validate_format_input,
3737
),
3838
out_file: typer.FileTextWrite = typer.Option(
39-
sys.stdout, "-o", "--out_file", help="Output file (defaults to stdout)"
39+
sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"
4040
),
4141
no_verify_ssl: bool = typer.Option(
4242
False,
@@ -58,7 +58,7 @@ def available_api_calls(
5858
creds_file: str = typer.Option(
5959
"~/.dtapi",
6060
"-c",
61-
"--cred_file",
61+
"--credfile",
6262
help="Optional file with API username and API key, one per line.",
6363
),
6464
rate_limit: bool = typer.Option(

domaintools/cli/commands/detects.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def iris_detect_monitors(
4747
creds_file: str = typer.Option(
4848
"~/.dtapi",
4949
"-c",
50-
"--cred_file",
50+
"--credfile",
5151
help="Optional file with API username and API key, one per line.",
5252
),
5353
rate_limit: bool = typer.Option(
@@ -64,7 +64,7 @@ def iris_detect_monitors(
6464
callback=DTCLICommand.validate_format_input,
6565
),
6666
out_file: typer.FileTextWrite = typer.Option(
67-
sys.stdout, "-o", "--out_file", help="Output file (defaults to stdout)"
67+
sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"
6868
),
6969
no_verify_ssl: bool = typer.Option(
7070
False,
@@ -101,7 +101,7 @@ def iris_detect_new_domains(
101101
),
102102
discovered_since: str = typer.Option(
103103
None,
104-
"--discovered_since",
104+
"--discovered-since",
105105
help="ISO 8601 datetime format: default None. Filter domains by when they were discovered.",
106106
),
107107
changed_since: str = typer.Option(
@@ -145,13 +145,13 @@ def iris_detect_new_domains(
145145
creds_file: str = typer.Option(
146146
"~/.dtapi",
147147
"-c",
148-
"--cred_file",
148+
"--credfile",
149149
help="Optional file with API username and API key, one per line.",
150150
),
151151
rate_limit: bool = typer.Option(
152152
False,
153153
"-l",
154-
"--rate_limit",
154+
"--rate-limit",
155155
help="Rate limit API calls against the API based on per minute limits.",
156156
),
157157
format: str = typer.Option(
@@ -162,7 +162,7 @@ def iris_detect_new_domains(
162162
callback=DTCLICommand.validate_format_input,
163163
),
164164
out_file: typer.FileTextWrite = typer.Option(
165-
sys.stdout, "-o", "--out_file", help="Output file (defaults to stdout)"
165+
sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"
166166
),
167167
no_verify_ssl: bool = typer.Option(
168168
False,
@@ -190,7 +190,7 @@ def iris_detect_watched_domains(
190190
),
191191
escalation_types: str = typer.Option(
192192
None,
193-
"--escalation_types",
193+
"--escalation-types",
194194
help="List of escalation types to filter domains by. Valid values are: {'blocked', 'google_safe'}",
195195
),
196196
escalated_since: str = typer.Option(
@@ -212,7 +212,7 @@ def iris_detect_watched_domains(
212212
),
213213
discovered_since: str = typer.Option(
214214
None,
215-
"--discovered_since",
215+
"--discovered-since",
216216
help="ISO 8601 datetime format: default None. Filter domains by when they were discovered.",
217217
),
218218
changed_since: str = typer.Option(
@@ -256,13 +256,13 @@ def iris_detect_watched_domains(
256256
creds_file: str = typer.Option(
257257
"~/.dtapi",
258258
"-c",
259-
"--cred_file",
259+
"--credfile",
260260
help="Optional file with API username and API key, one per line.",
261261
),
262262
rate_limit: bool = typer.Option(
263263
False,
264264
"-l",
265-
"--rate_limit",
265+
"--rate-limit",
266266
help="Rate limit API calls against the API based on per minute limits.",
267267
),
268268
format: str = typer.Option(
@@ -273,7 +273,7 @@ def iris_detect_watched_domains(
273273
callback=DTCLICommand.validate_format_input,
274274
),
275275
out_file: typer.FileTextWrite = typer.Option(
276-
sys.stdout, "-o", "--out_file", help="Output file (defaults to stdout)"
276+
sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"
277277
),
278278
no_verify_ssl: bool = typer.Option(
279279
False,
@@ -304,13 +304,13 @@ def iris_detect_manage_watchlist_domains(
304304
creds_file: str = typer.Option(
305305
"~/.dtapi",
306306
"-c",
307-
"--cred_file",
307+
"--credfile",
308308
help="Optional file with API username and API key, one per line.",
309309
),
310310
rate_limit: bool = typer.Option(
311311
False,
312312
"-l",
313-
"--rate_limit",
313+
"--rate-limit",
314314
help="Rate limit API calls against the API based on per minute limits.",
315315
),
316316
format: str = typer.Option(
@@ -321,7 +321,7 @@ def iris_detect_manage_watchlist_domains(
321321
callback=DTCLICommand.validate_format_input,
322322
),
323323
out_file: typer.FileTextWrite = typer.Option(
324-
sys.stdout, "-o", "--out_file", help="Output file (defaults to stdout)"
324+
sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"
325325
),
326326
no_verify_ssl: bool = typer.Option(
327327
False,
@@ -354,13 +354,13 @@ def iris_detect_escalate_domains(
354354
creds_file: str = typer.Option(
355355
"~/.dtapi",
356356
"-c",
357-
"--cred_file",
357+
"--credfile",
358358
help="Optional file with API username and API key, one per line.",
359359
),
360360
rate_limit: bool = typer.Option(
361361
False,
362362
"-l",
363-
"--rate_limit",
363+
"--rate-limit",
364364
help="Rate limit API calls against the API based on per minute limits.",
365365
),
366366
format: str = typer.Option(
@@ -371,7 +371,7 @@ def iris_detect_escalate_domains(
371371
callback=DTCLICommand.validate_format_input,
372372
),
373373
out_file: typer.FileTextWrite = typer.Option(
374-
sys.stdout, "-o", "--out_file", help="Output file (defaults to stdout)"
374+
sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"
375375
),
376376
no_verify_ssl: bool = typer.Option(
377377
False,
@@ -399,7 +399,7 @@ def iris_detect_ignored_domains(
399399
),
400400
escalation_types: str = typer.Option(
401401
None,
402-
"--escalation_types",
402+
"--escalation-types",
403403
help="List of escalation types to filter domains by. Valid values are: {'blocked', 'google_safe'}",
404404
),
405405
escalated_since: str = typer.Option(
@@ -421,7 +421,7 @@ def iris_detect_ignored_domains(
421421
),
422422
discovered_since: str = typer.Option(
423423
None,
424-
"--discovered_since",
424+
"--discovered-since",
425425
help="ISO 8601 datetime format: default None. Filter domains by when they were discovered.",
426426
),
427427
changed_since: str = typer.Option(
@@ -465,13 +465,13 @@ def iris_detect_ignored_domains(
465465
creds_file: str = typer.Option(
466466
"~/.dtapi",
467467
"-c",
468-
"--cred_file",
468+
"--credfile",
469469
help="Optional file with API username and API key, one per line.",
470470
),
471471
rate_limit: bool = typer.Option(
472472
False,
473473
"-l",
474-
"--rate_limit",
474+
"--rate-limit",
475475
help="Rate limit API calls against the API based on per minute limits.",
476476
),
477477
format: str = typer.Option(
@@ -482,7 +482,7 @@ def iris_detect_ignored_domains(
482482
callback=DTCLICommand.validate_format_input,
483483
),
484484
out_file: typer.FileTextWrite = typer.Option(
485-
sys.stdout, "-o", "--out_file", help="Output file (defaults to stdout)"
485+
sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"
486486
),
487487
no_verify_ssl: bool = typer.Option(
488488
False,

0 commit comments

Comments
 (0)