diff --git a/CHANGELOG.md b/CHANGELOG.md index 753c69e..59bd5d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========= +8.18.3 +------ + +- Move `__version__` to `parsedmarc.constants` +- Create a constant `USER_AGENT` +- Use the HTTP `User-Agent` header value `parsedmarc/version` for all HTTP requests + 8.18.2 ------ diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index faa1f56..2169136 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -34,12 +34,13 @@ from parsedmarc.mail import ( MSGraphConnection, GmailConnection, ) + +from parsedmarc.constants import __version__ from parsedmarc.utils import get_base_domain, get_ip_address_info from parsedmarc.utils import is_outlook_msg, convert_outlook_msg from parsedmarc.utils import parse_email from parsedmarc.utils import timestamp_to_human, human_timestamp_to_datetime -__version__ = "8.18.2" logger.debug("parsedmarc v{0}".format(__version__)) diff --git a/parsedmarc/constants.py b/parsedmarc/constants.py new file mode 100644 index 0000000..80e0a50 --- /dev/null +++ b/parsedmarc/constants.py @@ -0,0 +1,2 @@ +__version__ = "8.18.3" +USER_AGENT = f"parsedmarc/{__version__}" diff --git a/parsedmarc/splunk.py b/parsedmarc/splunk.py index cf6a1e0..3e218fb 100644 --- a/parsedmarc/splunk.py +++ b/parsedmarc/splunk.py @@ -5,7 +5,7 @@ import json import urllib3 import requests -from parsedmarc import __version__ +from parsedmarc.constants import USER_AGENT from parsedmarc.log import logger from parsedmarc.utils import human_timestamp_to_unix_timestamp @@ -51,7 +51,7 @@ class HECClient(object): self._common_data = dict(host=self.host, source=self.source, index=self.index) self.session.headers = { - "User-Agent": "parsedmarc/{0}".format(__version__), + "User-Agent": USER_AGENT, "Authorization": "Splunk {0}".format(self.access_token), } diff --git a/parsedmarc/utils.py b/parsedmarc/utils.py index 60c7071..571cca5 100644 --- a/parsedmarc/utils.py +++ b/parsedmarc/utils.py @@ -37,7 +37,7 @@ import requests from parsedmarc.log import logger import parsedmarc.resources.dbip import parsedmarc.resources.maps - +from parsedmarc.constants import USER_AGENT parenthesis_regex = re.compile(r"\s*\(.*\)\s*") @@ -345,7 +345,8 @@ def get_service_from_reverse_dns_base_domain( if not (offline or always_use_local_file) and len(reverse_dns_map) == 0: try: logger.debug(f"Trying to fetch reverse DNS map from {url}...") - response = requests.get(url) + headers = {"User-Agent", USER_AGENT} + response = requests.get(url, headers=headers) response.raise_for_status() csv_file.write(response.text) csv_file.seek(0) diff --git a/parsedmarc/webhook.py b/parsedmarc/webhook.py index b54ab65..37477e6 100644 --- a/parsedmarc/webhook.py +++ b/parsedmarc/webhook.py @@ -1,6 +1,6 @@ import requests -from parsedmarc import logger +from parsedmarc import logger, USER_AGENT class WebhookClient(object): @@ -21,7 +21,7 @@ class WebhookClient(object): self.timeout = timeout self.session = requests.Session() self.session.headers = { - "User-Agent": "parsedmarc", + "User-Agent": USER_AGENT, "Content-Type": "application/json", } diff --git a/pyproject.toml b/pyproject.toml index fc7e537..6f84e9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,7 +76,7 @@ parsedmarc = "parsedmarc.cli:_main" Homepage = "https://domainaware.github.io/parsedmarc" [tool.hatch.version] -path = "parsedmarc/__init__.py" +path = "parsedmarc/constants.py" [tool.hatch.build.targets.sdist] include = [