Skip to content

Commit bfcae8a

Browse files
authored
Merge pull request #89 from SEKOIA-IO/feature/vg_add_user_agent_header
Feature: User-Agent header in connector
2 parents 3592042 + 9edca82 commit bfcae8a

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.7.0] - 2023-11-07
11+
12+
### Added
13+
14+
- Add property to connector with `User-Agent` header to third party services
15+
1016
## [1.6.2] - 2023-11-06
1117

1218
### Fixed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55
[tool.poetry]
66
name = "sekoia-automation-sdk"
77

8-
version = "1.6.2"
8+
version = "1.7.0"
99
description = "SDK to create Sekoia.io playbook modules"
1010
license = "MIT"
1111
readme = "README.md"

sekoia_automation/connector/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ def _retry(self):
101101
def _connector_user_agent(self) -> str:
102102
return f"sekoiaio-connector-{self.configuration.intake_key}"
103103

104+
@cached_property
105+
def http_default_headers(self) -> dict[str, str]:
106+
"""
107+
Contains dict of predefined headers.
108+
109+
This headers might be used by connector in requests to third party services.
110+
111+
Returns:
112+
dict[str, str]:
113+
"""
114+
return {
115+
"User-Agent": "sekoiaio-connector/{}-{}".format(
116+
self.module.manifest.get("slug"),
117+
self.module.manifest.get("version"),
118+
),
119+
}
120+
104121
def _send_chunk(
105122
self,
106123
batch_api: str,

tests/connectors/test_connector.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ def test_connector(storage, mocked_trigger_logs):
3636
test_connector.stop()
3737

3838

39+
def test_check_http_default_headers(test_connector):
40+
test_connector.module._manifest = {
41+
"slug": "dummyslug",
42+
"version": "dummyversion",
43+
}
44+
45+
assert test_connector.http_default_headers == {
46+
"User-Agent": "sekoiaio-connector/dummyslug-dummyversion"
47+
}
48+
49+
3950
def test_forward_events(test_connector):
4051
test_connector.forward_events(events=EVENTS)
4152
test_connector.send_event.assert_called_once()

0 commit comments

Comments
 (0)