Skip to content

Commit d263f96

Browse files
committed
IDEV-2011: Move list of feed products in constants.py
1 parent ca8ebca commit d263f96

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

domaintools/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from hmac import new as hmac
44
import re
55

6-
from domaintools.constants import Endpoint, ENDPOINT_TO_SOURCE_MAP, OutputFormat
6+
from domaintools.constants import Endpoint, ENDPOINT_TO_SOURCE_MAP, FEEDS_PRODUCTS_LIST, OutputFormat
77
from domaintools._version import current as version
88
from domaintools.results import (
99
GroupedIterable,
@@ -19,7 +19,7 @@
1919
filter_by_field,
2020
DTResultFilter,
2121
)
22-
from domaintools.utils import get_feeds_products_list, validate_feeds_parameters
22+
from domaintools.utils import validate_feeds_parameters
2323

2424

2525
AVAILABLE_KEY_SIGN_HASHES = ["sha1", "sha256", "md5"]
@@ -133,7 +133,7 @@ def _results(self, product, path, cls=Results, **kwargs):
133133

134134
def handle_api_key(self, product, path, parameters, header_authentication):
135135
if self.https and not self.always_sign_api_key:
136-
if product in get_feeds_products_list() and header_authentication:
136+
if product in FEEDS_PRODUCTS_LIST and header_authentication:
137137
parameters["X-Api-Key"] = self.key
138138
else:
139139
parameters["api_key"] = self.key

domaintools/base_results.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from datetime import datetime
1010
from httpx import Client
1111

12-
from domaintools.constants import OutputFormat, HEADER_ACCEPT_KEY_CSV_FORMAT
12+
from domaintools.constants import FEEDS_PRODUCTS_LIST, OutputFormat, HEADER_ACCEPT_KEY_CSV_FORMAT
1313
from domaintools.exceptions import (
1414
BadRequestException,
1515
InternalServerErrorException,
@@ -20,7 +20,6 @@
2020
IncompleteResponseException,
2121
RequestUriTooLongException,
2222
)
23-
from domaintools.utils import get_feeds_products_list
2423

2524

2625
try: # pragma: no cover
@@ -93,7 +92,7 @@ def _make_request(self):
9392
patch_data = self.kwargs.copy()
9493
patch_data.update(self.api.extra_request_params)
9594
return session.patch(url=self.url, json=patch_data)
96-
elif self.product in get_feeds_products_list():
95+
elif self.product in FEEDS_PRODUCTS_LIST:
9796
parameters = deepcopy(self.kwargs)
9897
parameters.pop("output_format", None)
9998
parameters.pop(
@@ -139,8 +138,7 @@ def data(self):
139138
self.setStatus(results.status_code, results)
140139
if (
141140
self.kwargs.get("format", "json") == "json"
142-
and self.product
143-
not in get_feeds_products_list() # Special handling of feeds products' data to preserve the result in jsonline format
141+
and self.product not in FEEDS_PRODUCTS_LIST # Special handling of feeds products' data to preserve the result in jsonline format
144142
):
145143
self._data = results.json()
146144
else:
@@ -157,7 +155,7 @@ def data(self):
157155
return self._data
158156

159157
def check_limit_exceeded(self):
160-
if self.kwargs.get("format", "json") == "json" and self.product not in get_feeds_products_list():
158+
if self.kwargs.get("format", "json") == "json" and self.product not in FEEDS_PRODUCTS_LIST:
161159
if "response" in self._data and "limit_exceeded" in self._data["response"] and self._data["response"]["limit_exceeded"] is True:
162160
return True, self._data["response"]["message"]
163161
# TODO: handle html, xml response errors better.

domaintools/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ class OutputFormat(Enum):
2222
Endpoint.FEED.value: Source.API,
2323
Endpoint.DOWNLOAD.value: Source.S3,
2424
}
25+
26+
FEEDS_PRODUCTS_LIST = [
27+
"newly-active-domains-feed-(api)",
28+
"newly-active-domains-feed-(s3)",
29+
"newly-observed-domains-feed-(api)",
30+
"newly-observed-domains-feed-(s3)",
31+
"domain-registration-data-access-protocol-feed-(api)",
32+
"domain-registration-data-access-protocol-feed-(s3)",
33+
"real-time-domain-discovery-feed-(api)",
34+
"real-time-domain-discovery-feed-(s3)",
35+
]

domaintools/utils.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,6 @@ def convert_str_to_dateobj(string_date: str, date_format: Optional[str] = "%Y-%m
172172
return datetime.strptime(string_date, date_format)
173173

174174

175-
def get_feeds_products_list():
176-
return [
177-
"newly-active-domains-feed-(api)",
178-
"newly-active-domains-feed-(s3)",
179-
"newly-observed-domains-feed-(api)",
180-
"newly-observed-domains-feed-(s3)",
181-
"domain-registration-data-access-protocol-feed-(api)",
182-
"domain-registration-data-access-protocol-feed-(s3)",
183-
"real-time-domain-discovery-feed-(api)",
184-
"real-time-domain-discovery-feed-(s3)",
185-
]
186-
187-
188175
def validate_feeds_parameters(params):
189176
sessionID = params.get("sessionID")
190177
after = params.get("after")

domaintools_async/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
from httpx import AsyncClient
77

88
from domaintools.base_results import Results
9-
from domaintools.constants import OutputFormat, HEADER_ACCEPT_KEY_CSV_FORMAT
9+
from domaintools.constants import FEEDS_PRODUCTS_LIST, OutputFormat, HEADER_ACCEPT_KEY_CSV_FORMAT
1010
from domaintools.exceptions import ServiceUnavailableException
11-
from domaintools.utils import get_feeds_products_list
1211

1312

1413
class _AIter(object):
@@ -52,7 +51,7 @@ async def _make_async_request(self, session):
5251
patch_data = self.kwargs.copy()
5352
patch_data.update(self.api.extra_request_params)
5453
results = await session.patch(url=self.url, json=patch_data)
55-
elif self.product in get_feeds_products_list():
54+
elif self.product in FEEDS_PRODUCTS_LIST:
5655
parameters = deepcopy(self.kwargs)
5756
parameters.pop("output_format", None)
5857
parameters.pop(

0 commit comments

Comments
 (0)