diff --git a/CHANGELOG.md b/CHANGELOG.md index 93543c5..0779933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.7.0] - 2023-11-07 + +### Added + +- Add property to connector with `User-Agent` header to third party services + ## [1.6.2] - 2023-11-06 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index a45afe2..4888b3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "sekoia-automation-sdk" -version = "1.6.2" +version = "1.7.0" description = "SDK to create Sekoia.io playbook modules" license = "MIT" readme = "README.md" diff --git a/sekoia_automation/connector/__init__.py b/sekoia_automation/connector/__init__.py index 5fb55e5..eefab21 100644 --- a/sekoia_automation/connector/__init__.py +++ b/sekoia_automation/connector/__init__.py @@ -101,6 +101,23 @@ def _retry(self): def _connector_user_agent(self) -> str: return f"sekoiaio-connector-{self.configuration.intake_key}" + @cached_property + def http_default_headers(self) -> dict[str, str]: + """ + Contains dict of predefined headers. + + This headers might be used by connector in requests to third party services. + + Returns: + dict[str, str]: + """ + return { + "User-Agent": "sekoiaio-connector/{}-{}".format( + self.module.manifest.get("slug"), + self.module.manifest.get("version"), + ), + } + def _send_chunk( self, batch_api: str, diff --git a/tests/connectors/test_connector.py b/tests/connectors/test_connector.py index 67c49bd..7e85f1a 100644 --- a/tests/connectors/test_connector.py +++ b/tests/connectors/test_connector.py @@ -36,6 +36,17 @@ def test_connector(storage, mocked_trigger_logs): test_connector.stop() +def test_check_http_default_headers(test_connector): + test_connector.module._manifest = { + "slug": "dummyslug", + "version": "dummyversion", + } + + assert test_connector.http_default_headers == { + "User-Agent": "sekoiaio-connector/dummyslug-dummyversion" + } + + def test_forward_events(test_connector): test_connector.forward_events(events=EVENTS) test_connector.send_event.assert_called_once()