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

VadeCloud: Additional custom header to platform requests #469

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 VadeCloud/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]

## 2023-10-31 - 1.1.1

### Changed

- Add additional user-agent to work with api

## 2023-10-12 - 1.0.5

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion VadeCloud/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
"name": "Vade Cloud",
"slug": "vade-cloud",
"uuid": "203d043e-a1ea-4b5c-81ef-6fc0f8a6a9d3",
"version": "1.1"
"version": "1.1.1"
}
4 changes: 4 additions & 0 deletions VadeCloud/vadecloud_modules/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ def __init__(
password: str,
nb_retries: int = 5,
ratelimit_per_minute: int = 20,
default_headers: dict[str, str] | None = None,
):
super().__init__()
self.auth: ApiKeyAuthentication = ApiKeyAuthentication(hostname, login, password)
self.auth.authenticate()

if default_headers is not None:
self.headers.update(default_headers)

self.mount(
"https://",
LimiterAdapter(
Expand Down
10 changes: 9 additions & 1 deletion VadeCloud/vadecloud_modules/client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@


class ApiKeyAuthentication(AuthBase):
def __init__(self, hostname: str, login: str, password: str):
def __init__(self, hostname: str, login: str, password: str, default_headers: dict[str, str] | None = None):
self.__hostname = hostname
self.__login = login
self.__password = password
self.__http_session = requests.Session()

self.default_headers: dict[str, str] = default_headers or {}

if default_headers is not None:
self.__http_session.headers.update(default_headers)

Check warning on line 16 in VadeCloud/vadecloud_modules/client/auth.py

View check run for this annotation

Codecov / codecov/patch

VadeCloud/vadecloud_modules/client/auth.py#L16

Added line #L16 was not covered by tests

self.__http_session.mount(
"https://",
HTTPAdapter(
Expand All @@ -28,6 +34,7 @@
response = self.__http_session.post(
url=f"{self.__hostname}/rest/v3.0/login/login",
headers={
**self.default_headers,
"Content-type": "application/json",
"Accept": "application/json",
},
Expand Down Expand Up @@ -55,4 +62,5 @@

def __call__(self, request):
request.headers["x-vrc-authorization"] = self.get_authorization_header()

return request
15 changes: 15 additions & 0 deletions VadeCloud/vadecloud_modules/trigger_vade_cloud_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def client(self):
login=self.connector.module.configuration.login,
password=self.connector.module.configuration.password,
ratelimit_per_minute=self.connector.configuration.ratelimit_per_minute,
default_headers=self.connector._http_default_headers,
)
return client

Expand Down Expand Up @@ -248,6 +249,20 @@ def __init__(self, *args, **kwargs):
self.context_lock = Lock()
self.consumers = {}

@cached_property
def _http_default_headers(self) -> dict[str, str]:
"""
Return the default headers for the HTTP requests used in this connector.

Returns:
dict[str, str]:
"""
return {
"User-Agent": "sekoiaio-connector/{0}-{1}".format(
self.module.manifest.get("slug"), self.module.manifest.get("version")
),
}

def start_consumers(self):
consumers = {}

Expand Down
Loading