diff --git a/VadeCloud/CHANGELOG.md b/VadeCloud/CHANGELOG.md index 9ce877b3c..dd92b09dc 100644 --- a/VadeCloud/CHANGELOG.md +++ b/VadeCloud/CHANGELOG.md @@ -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 diff --git a/VadeCloud/manifest.json b/VadeCloud/manifest.json index e8d6e7886..5a04851b5 100644 --- a/VadeCloud/manifest.json +++ b/VadeCloud/manifest.json @@ -31,5 +31,5 @@ "name": "Vade Cloud", "slug": "vade-cloud", "uuid": "203d043e-a1ea-4b5c-81ef-6fc0f8a6a9d3", - "version": "1.1" + "version": "1.1.1" } \ No newline at end of file diff --git a/VadeCloud/vadecloud_modules/client/__init__.py b/VadeCloud/vadecloud_modules/client/__init__.py index 50d3b8acd..d48df7c41 100644 --- a/VadeCloud/vadecloud_modules/client/__init__.py +++ b/VadeCloud/vadecloud_modules/client/__init__.py @@ -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( diff --git a/VadeCloud/vadecloud_modules/client/auth.py b/VadeCloud/vadecloud_modules/client/auth.py index f55fa3643..1b544fc1c 100644 --- a/VadeCloud/vadecloud_modules/client/auth.py +++ b/VadeCloud/vadecloud_modules/client/auth.py @@ -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) + self.__http_session.mount( "https://", HTTPAdapter( @@ -28,6 +34,7 @@ def authenticate(self): 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", }, @@ -55,4 +62,5 @@ def account_id(self): def __call__(self, request): request.headers["x-vrc-authorization"] = self.get_authorization_header() + return request diff --git a/VadeCloud/vadecloud_modules/trigger_vade_cloud_logs.py b/VadeCloud/vadecloud_modules/trigger_vade_cloud_logs.py index 92d7ca758..3bd682207 100644 --- a/VadeCloud/vadecloud_modules/trigger_vade_cloud_logs.py +++ b/VadeCloud/vadecloud_modules/trigger_vade_cloud_logs.py @@ -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 @@ -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 = {}