Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: User-Agent header in connector #89

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions sekoia_automation/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/connectors/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading