From 607a091a5f8668186e7d01e10354acc59e6c7a62 Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Mon, 2 Jun 2025 16:43:26 -0400 Subject: [PATCH] 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 --- CHANGELOG.md | 7 +++++++ parsedmarc/__init__.py | 3 ++- parsedmarc/constants.py | 2 ++ parsedmarc/splunk.py | 4 ++-- parsedmarc/utils.py | 5 +++-- parsedmarc/webhook.py | 4 ++-- pyproject.toml | 2 +- 7 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 parsedmarc/constants.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 753c69e3..59bd5d38 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 faa1f565..21691364 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 00000000..80e0a502 --- /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 cf6a1e04..3e218fb2 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 60c70717..571cca59 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 b54ab650..37477e68 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 fc7e537f..6f84e9ac 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 = [