From 15405ed4d01455965b9d4a8fa4aef4ac1af10458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Sevestre?= Date: Mon, 3 Oct 2022 17:13:12 +0200 Subject: [PATCH 1/3] feat(legacy): allow to pass custom headers --- lumapps/api/base_client.py | 3 +++ tests/legacy/test_client.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lumapps/api/base_client.py b/lumapps/api/base_client.py index 545000e6..d4b00ee8 100644 --- a/lumapps/api/base_client.py +++ b/lumapps/api/base_client.py @@ -50,6 +50,7 @@ def __init__( prune: bool = False, no_verify: bool = False, proxy_info: Optional[Dict[str, Any]] = None, + extra_http_headers: Optional[Dict] = None, ): """ Args: @@ -73,6 +74,8 @@ def __init__( self._endpoints = None self._client = None self._headers: dict = {} + if extra_http_headers: + self._headers.update(extra_http_headers) if api_info is None: api_info = {} api_info.setdefault("name", LUMAPPS_NAME) diff --git a/tests/legacy/test_client.py b/tests/legacy/test_client.py index 83d6c4b2..3139426b 100644 --- a/tests/legacy/test_client.py +++ b/tests/legacy/test_client.py @@ -37,3 +37,9 @@ def dummy_get_content_by_slug(_, desired_slug, fields="id"): slug = "first-project-items-are-due-1-goals-and-deliverables-2-project-members-3-due-dates-if-you-need" new_slug = cli.get_available_slug(slug) assert new_slug == slug + "-10" + + +def test_custom_headers(): + headers = {"my-header": "on"} + cli = LumAppsClient("a", "b", token="FAKE", extra_http_headers=headers) + assert "my-header" in cli.client.headers From 1b83955998bff9249f5f47a30a11b95de77e9a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Sevestre?= Date: Mon, 3 Oct 2022 17:42:42 +0200 Subject: [PATCH 2/3] feat(headers): disable analytics by default --- lumapps/api/base_client.py | 2 +- lumapps/latest/client/application.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lumapps/api/base_client.py b/lumapps/api/base_client.py index d4b00ee8..576cfe65 100644 --- a/lumapps/api/base_client.py +++ b/lumapps/api/base_client.py @@ -73,7 +73,7 @@ def __init__( self._token = None self._endpoints = None self._client = None - self._headers: dict = {} + self._headers: dict = {"x-lumapps-analytics": "off"} if extra_http_headers: self._headers.update(extra_http_headers) if api_info is None: diff --git a/lumapps/latest/client/application.py b/lumapps/latest/client/application.py index b6d3dfb0..eba25feb 100644 --- a/lumapps/latest/client/application.py +++ b/lumapps/latest/client/application.py @@ -58,7 +58,11 @@ def request(self, request: Request, **_: Any) -> Response: request.method, f"{self.organization_url}/{request.url.lstrip('/')}", params=request.params, - headers={**request.headers, "User-Agent": "lumapps-sdk"}, + headers={ + **request.headers, + "User-Agent": "lumapps-sdk", + "x-lumapps-analytics": "off", + }, json=request.json, ) return Response( From a66476433ba8e2ed0f7b3b79b240b0bfc946e4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Sevestre?= Date: Mon, 3 Oct 2022 18:21:40 +0200 Subject: [PATCH 3/3] fix(poetry): fix importlib-metadata --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 2116edb3..e2c8451f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ requests-oauthlib = "^1.3.0" [tool.poetry.dev-dependencies] flake8 = "^3.8.3" +importlib-metadata = "<5.0" coverage = "^5.1" pytest = "^6.0.2" pytest-mock = "^3.3.1"