Skip to content

Commit 44f2e3a

Browse files
committed
IDEV-2011: Implement cli support for API header authentication for Real-Time Threat Intelligence Feeds and modify nod and nad parameters.
1 parent 8ce6548 commit 44f2e3a

File tree

2 files changed

+78
-34
lines changed

2 files changed

+78
-34
lines changed

domaintools/cli/api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
from typing import Optional, Dict, Tuple
99
from rich.progress import Progress, SpinnerColumn, TextColumn
1010

11-
from domaintools.constants import Endpoint, OutputFormat
1211
from domaintools.api import API
13-
from domaintools.exceptions import ServiceException
12+
from domaintools.constants import Endpoint, OutputFormat
1413
from domaintools.cli.utils import get_file_extension
14+
from domaintools.exceptions import ServiceException
15+
from domaintools._version import current as version
1516

1617

1718
class DTCLICommand:
1819
API_SUCCESS_STATUS = 200
19-
APP_PARTNER_NAME = "python_wrapper_cli_2.0.0"
20+
APP_PARTNER_NAME = f"python_wrapper_cli_{version}"
2021

2122
@staticmethod
2223
def print_api_version(value: bool):

domaintools/cli/commands/feeds.py

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import typer
32

43

@@ -23,20 +22,6 @@ def feeds_nad(
2322
"--credfile",
2423
help="Optional file with API username and API key, one per line.",
2524
),
26-
rate_limit: bool = typer.Option(
27-
False,
28-
"-l",
29-
"--rate-limit",
30-
help="Rate limit API calls against the API based on per minute limits.",
31-
),
32-
format: str = typer.Option(
33-
"json",
34-
"-f",
35-
"--format",
36-
help="Output format in {'list', 'json', 'xml', 'html'}",
37-
callback=DTCLICommand.validate_format_input,
38-
),
39-
out_file: typer.FileTextWrite = typer.Option(sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"),
4025
no_verify_ssl: bool = typer.Option(
4126
False,
4227
"--no-verify-ssl",
@@ -47,6 +32,25 @@ def feeds_nad(
4732
"--no-sign-api-key",
4833
help="Skip signing of api key",
4934
),
35+
header_authentication: bool = typer.Option(
36+
True,
37+
"--no-header-auth",
38+
help="Don't use header authentication",
39+
),
40+
output_format: str = typer.Option(
41+
"jsonl",
42+
"-f",
43+
"--format",
44+
help=f"Output format in [{OutputFormat.JSONL.value}, {OutputFormat.CSV.value}]",
45+
callback=DTCLICommand.validate_feeds_format_input,
46+
),
47+
endpoint: str = typer.Option(
48+
Endpoint.FEED.value,
49+
"-e",
50+
"--endpoint",
51+
help=f"Valid endpoints: [{Endpoint.FEED.value}, {Endpoint.DOWNLOAD.value}]",
52+
callback=DTCLICommand.validate_endpoint_input,
53+
),
5054
sessionID: str = typer.Option(
5155
None,
5256
"--session-id",
@@ -56,17 +60,29 @@ def feeds_nad(
5660
None,
5761
"--after",
5862
help="Start of the time window, relative to the current time in seconds, for which data will be provided",
63+
callback=DTCLICommand.validate_after_or_before_input,
64+
),
65+
before: str = typer.Option(
66+
None,
67+
"--before",
68+
help="The end of the query window in seconds, relative to the current time, inclusive",
69+
callback=DTCLICommand.validate_after_or_before_input,
5970
),
6071
domain: str = typer.Option(
6172
None,
6273
"-d",
6374
"--domain",
6475
help="A string value used to filter feed results",
6576
),
77+
headers: bool = typer.Option(
78+
False,
79+
"--headers",
80+
help="Adds a header to the first line of response when text/csv is set in header parameters",
81+
),
6682
top: str = typer.Option(
6783
None,
6884
"--top",
69-
help="Number of results to return in the response payload",
85+
help="Number of results to return in the response payload. This is ignored in download endpoint",
7086
),
7187
):
7288
DTCLICommand.run(name=c.FEEDS_NAD, params=ctx.params)
@@ -86,20 +102,6 @@ def feeds_nod(
86102
"--credfile",
87103
help="Optional file with API username and API key, one per line.",
88104
),
89-
rate_limit: bool = typer.Option(
90-
False,
91-
"-l",
92-
"--rate-limit",
93-
help="Rate limit API calls against the API based on per minute limits.",
94-
),
95-
format: str = typer.Option(
96-
"json",
97-
"-f",
98-
"--format",
99-
help="Output format in {'list', 'json', 'xml', 'html'}",
100-
callback=DTCLICommand.validate_format_input,
101-
),
102-
out_file: typer.FileTextWrite = typer.Option(sys.stdout, "-o", "--out-file", help="Output file (defaults to stdout)"),
103105
no_verify_ssl: bool = typer.Option(
104106
False,
105107
"--no-verify-ssl",
@@ -110,6 +112,25 @@ def feeds_nod(
110112
"--no-sign-api-key",
111113
help="Skip signing of api key",
112114
),
115+
header_authentication: bool = typer.Option(
116+
True,
117+
"--no-header-auth",
118+
help="Don't use header authentication",
119+
),
120+
output_format: str = typer.Option(
121+
"jsonl",
122+
"-f",
123+
"--format",
124+
help=f"Output format in [{OutputFormat.JSONL.value}, {OutputFormat.CSV.value}]",
125+
callback=DTCLICommand.validate_feeds_format_input,
126+
),
127+
endpoint: str = typer.Option(
128+
Endpoint.FEED.value,
129+
"-e",
130+
"--endpoint",
131+
help=f"Valid endpoints: [{Endpoint.FEED.value}, {Endpoint.DOWNLOAD.value}]",
132+
callback=DTCLICommand.validate_endpoint_input,
133+
),
113134
sessionID: str = typer.Option(
114135
None,
115136
"--session-id",
@@ -119,17 +140,29 @@ def feeds_nod(
119140
None,
120141
"--after",
121142
help="Start of the time window, relative to the current time in seconds, for which data will be provided",
143+
callback=DTCLICommand.validate_after_or_before_input,
144+
),
145+
before: str = typer.Option(
146+
None,
147+
"--before",
148+
help="The end of the query window in seconds, relative to the current time, inclusive",
149+
callback=DTCLICommand.validate_after_or_before_input,
122150
),
123151
domain: str = typer.Option(
124152
None,
125153
"-d",
126154
"--domain",
127155
help="A string value used to filter feed results",
128156
),
157+
headers: bool = typer.Option(
158+
False,
159+
"--headers",
160+
help="Adds a header to the first line of response when text/csv is set in header parameters",
161+
),
129162
top: str = typer.Option(
130163
None,
131164
"--top",
132-
help="Number of results to return in the response payload",
165+
help="Number of results to return in the response payload. This is ignored in download endpoint",
133166
),
134167
):
135168
DTCLICommand.run(name=c.FEEDS_NOD, params=ctx.params)
@@ -159,6 +192,11 @@ def feeds_domainrdap(
159192
"--no-sign-api-key",
160193
help="Skip signing of api key",
161194
),
195+
header_authentication: bool = typer.Option(
196+
True,
197+
"--no-header-auth",
198+
help="Don't use header authentication",
199+
),
162200
endpoint: str = typer.Option(
163201
Endpoint.FEED.value,
164202
"-e",
@@ -222,6 +260,11 @@ def feeds_domaindiscovery(
222260
"--no-sign-api-key",
223261
help="Skip signing of api key",
224262
),
263+
header_authentication: bool = typer.Option(
264+
True,
265+
"--no-header-auth",
266+
help="Don't use header authentication",
267+
),
225268
output_format: str = typer.Option(
226269
"jsonl",
227270
"-f",

0 commit comments

Comments
 (0)