From ec74833fac9b1542d88ed5a49b7702438c451070 Mon Sep 17 00:00:00 2001 From: Maxim Kolyubyakin Date: Tue, 28 Mar 2023 10:40:16 +0200 Subject: [PATCH] LITE-26809 Extension can specify proxied Connect Public API endpoints * `proxied_connect_api` @property in `WebApp` * `proxied_connect_api` is passed to `SetupRequest` --- connect/eaas/runner/handlers/web.py | 4 ++++ connect/eaas/runner/workers/web.py | 1 + poetry.lock | 12 ++++++------ pyproject.toml | 2 +- tests/conftest.py | 1 + tests/handlers/test_web.py | 5 +++++ tests/workers/test_web.py | 12 ++++++++++++ 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/connect/eaas/runner/handlers/web.py b/connect/eaas/runner/handlers/web.py index 2207045..40dd841 100644 --- a/connect/eaas/runner/handlers/web.py +++ b/connect/eaas/runner/handlers/web.py @@ -80,6 +80,10 @@ def __init__(self, config: ConfigHelper): def ui_modules(self): return self.get_application().get_ui_modules() + @property + def proxied_connect_api(self): + return self.get_application().get_proxied_connect_api() + @property def app(self): if not self._app: diff --git a/connect/eaas/runner/workers/web.py b/connect/eaas/runner/workers/web.py index 08b5b85..f469179 100644 --- a/connect/eaas/runner/workers/web.py +++ b/connect/eaas/runner/workers/web.py @@ -60,6 +60,7 @@ def get_setup_request(self): icon=self.handler.icon, audience=self.handler.audience, runner_version=get_version(), + proxied_connect_api=self.handler.proxied_connect_api, ), ) logger.debug(f'Sending setup request: {pformat(msg)}') diff --git a/poetry.lock b/poetry.lock index 2f2512d..d082bf4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "anvil-uplink" @@ -255,14 +255,14 @@ test = ["flake8 (==3.7.8)", "hypothesis (==3.55.3)"] [[package]] name = "connect-eaas-core" -version = "27.7" +version = "27.8" description = "Connect Eaas Core" category = "main" optional = false python-versions = ">=3.8,<4" files = [ - {file = "connect_eaas_core-27.7-py3-none-any.whl", hash = "sha256:5805ebf98073ef5e85eb5e966ab01a6b4f3eb8c2b938c310422f2e86a0b0768c"}, - {file = "connect_eaas_core-27.7.tar.gz", hash = "sha256:e8fe3a4a933e27e8568b265d7d33dc14a5b9c87d87b9aa8ddbb36d382ff7d939"}, + {file = "connect_eaas_core-27.8-py3-none-any.whl", hash = "sha256:52d46aac6e786c637b184eb5d10489ef3033e8d1f0dbb5416bf782c73908d4fb"}, + {file = "connect_eaas_core-27.8.tar.gz", hash = "sha256:eff4990e80da04516e51f2836aaa81c8c6d3456bf8d1a123ba6a9dacbd029bdb"}, ] [package.dependencies] @@ -1518,7 +1518,7 @@ files = [ ] [package.dependencies] -greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and platform_machine == \"aarch64\" or python_version >= \"3\" and platform_machine == \"ppc64le\" or python_version >= \"3\" and platform_machine == \"x86_64\" or python_version >= \"3\" and platform_machine == \"amd64\" or python_version >= \"3\" and platform_machine == \"AMD64\" or python_version >= \"3\" and platform_machine == \"win32\" or python_version >= \"3\" and platform_machine == \"WIN32\""} +greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\")"} [package.extras] aiomysql = ["aiomysql", "greenlet (!=0.4.17)"] @@ -1784,4 +1784,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = ">=3.8,<4" -content-hash = "056d8aea4cd1b1dec05d7e7b3652c7b513d2a479bdb3725bff719ea40d318963" +content-hash = "4b2618d23b76567c8db2766668e9e0d78a841b68be3348b37dbf29ee0f253564" diff --git a/pyproject.toml b/pyproject.toml index b9d38af..5dbf941 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ connect-openapi-client = ">=25.16" logzio-python-handler = "^3.0.0" backoff = "^1.11.1" uvloop = "^0.16.0" -connect-eaas-core = ">=27.7,<28" +connect-eaas-core = ">=27.8,<28" httpx = "^0.23.0" rich = "^12.5.1" pyfiglet = "^0.8.post1" diff --git a/tests/conftest.py b/tests/conftest.py index 4222ad2..27d0e0f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -97,6 +97,7 @@ def settings_payload(): for evt_type in BACKGROUND_EVENT_TYPES ], 'model_type': 'setup_response', + 'proxied_connect_api': [], } diff --git a/tests/handlers/test_web.py b/tests/handlers/test_web.py index affb6f5..2d545ce 100644 --- a/tests/handlers/test_web.py +++ b/tests/handlers/test_web.py @@ -104,6 +104,10 @@ def get_ui_modules(cls): }, } + @classmethod + def get_proxied_connect_api(cls): + return ['/abc'] + mocker.patch.object( WebApp, 'load_application', @@ -126,6 +130,7 @@ def get_ui_modules(cls): assert handler.icon == descriptor['icon'] assert handler.audience == descriptor['audience'] assert handler.should_start is True + assert handler.proxied_connect_api == ['/abc'] @pytest.mark.parametrize('static_root', ('static', None)) diff --git a/tests/workers/test_web.py b/tests/workers/test_web.py index 7575101..4910c6f 100644 --- a/tests/workers/test_web.py +++ b/tests/workers/test_web.py @@ -64,6 +64,8 @@ async def test_extension_settings(mocker, ws_server, unused_port, settings_paylo }, } + proxied_connect_api = ['/public/v1/endpoint'] + @account_settings_page('Settings', '/static/settings.html') class MyExtension(WebApplicationBase): @classmethod @@ -76,6 +78,10 @@ def get_descriptor(cls): 'changelog_url': 'https://change.log', } + @classmethod + def get_proxied_connect_api(cls): + return proxied_connect_api + mocker.patch.object( WebApp, 'load_application', @@ -120,6 +126,7 @@ def get_descriptor(cls): 'changelog_url': 'https://change.log', }, runner_version='24.1', + proxied_connect_api=proxied_connect_api, ), ) @@ -265,6 +272,7 @@ def test_url(self): 'changelog_url': 'https://change.log', }, runner_version='24.1', + proxied_connect_api=[], ), ), ) @@ -421,6 +429,7 @@ def test_url(self): 'changelog_url': 'https://change.log', }, runner_version='24.1', + proxied_connect_api=[], ), ), ) @@ -564,6 +573,7 @@ def test_url(self): 'changelog_url': 'https://change.log', }, runner_version='24.1', + proxied_connect_api=[], ), ), ) @@ -784,6 +794,7 @@ def on_shutdown(cls, logger, config): 'changelog_url': 'https://change.log', }, runner_version='24.1', + proxied_connect_api=[], ), ) @@ -894,6 +905,7 @@ async def on_shutdown(cls, logger, config): 'changelog_url': 'https://change.log', }, runner_version='24.1', + proxied_connect_api=[], ), )