Skip to content

Commit 7d748eb

Browse files
committed
IDEV-1996: Add code improvements.
1 parent d2bb3e6 commit 7d748eb

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

domaintools/api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
filter_by_field,
2020
DTResultFilter,
2121
)
22-
from domaintools.utils import validate_feeds_required_parameters
22+
from domaintools.utils import validate_feeds_parameters
2323

2424

2525
AVAILABLE_KEY_SIGN_HASHES = ["sha1", "sha256", "md5"]
@@ -1091,7 +1091,7 @@ def nad(self, **kwargs):
10911091

10921092
def domainrdap(self, **kwargs):
10931093
"""Returns changes to global domain registration information, populated by the Registration Data Access Protocol (RDAP)"""
1094-
validate_feeds_required_parameters(kwargs)
1094+
validate_feeds_parameters(kwargs)
10951095
endpoint = kwargs.pop("endpoint", Endpoint.FEED.value)
10961096
source = ENDPOINT_TO_SOURCE_MAP.get(endpoint)
10971097

@@ -1104,10 +1104,11 @@ def domainrdap(self, **kwargs):
11041104

11051105
def domaindiscovery(self, **kwargs):
11061106
"""Returns new domains as they are either discovered in domain registration information, observed by our global sensor network, or reported by trusted third parties"""
1107-
validate_feeds_required_parameters(kwargs)
1107+
validate_feeds_parameters(kwargs)
11081108
endpoint = kwargs.pop("endpoint", Endpoint.FEED.value)
11091109
source = ENDPOINT_TO_SOURCE_MAP.get(endpoint)
11101110
if endpoint == Endpoint.DOWNLOAD.value or kwargs.get("output_format", OutputFormat.JSONL.value) != OutputFormat.CSV.value:
1111+
# headers param is allowed only in Feed API and CSV format
11111112
kwargs.pop("headers", None)
11121113

11131114
return self._results(

domaintools/cli/commands/feeds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from domaintools.cli.api import DTCLICommand
77
from domaintools.cli.utils import get_cli_helptext_by_name
88
from domaintools.cli import constants as c
9-
from domaintools.constants import Endpoint
9+
from domaintools.constants import Endpoint, OutputFormat
1010

1111

1212
@dt_cli.command(
@@ -226,7 +226,7 @@ def feeds_domaindiscovery(
226226
"jsonl",
227227
"-f",
228228
"--format",
229-
help="Output format in {'jsonl'}",
229+
help=f"Output format in [{OutputFormat.JSONL.value}, {OutputFormat.CSV.value}]",
230230
callback=DTCLICommand.validate_feeds_format_input,
231231
),
232232
endpoint: str = typer.Option(

domaintools/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from datetime import datetime
2-
32
from typing import Optional
43

4+
from domaintools.constants import Endpoint, OutputFormat
5+
56
import re
67

78

@@ -182,9 +183,13 @@ def get_feeds_products_list():
182183
]
183184

184185

185-
def validate_feeds_required_parameters(params):
186+
def validate_feeds_parameters(params):
186187
sessionID = params.get("sessionID")
187188
after = params.get("after")
188189
before = params.get("before")
189190
if not (sessionID or after or before):
190191
raise ValueError("sessionID or after or before must be defined")
192+
193+
format = params.get("output_format")
194+
if params.get("endpoint") == Endpoint.DOWNLOAD.value and format == OutputFormat.CSV.value:
195+
raise ValueError(f"{format} format is not available in {Endpoint.DOWNLOAD.value} API.")

0 commit comments

Comments
 (0)