From 9ed9e88b6eaffd8725abccb6710b49bc2f41a188 Mon Sep 17 00:00:00 2001 From: Louis Brunner Date: Tue, 28 Jan 2025 13:32:32 +0000 Subject: [PATCH] fix(api): avoid auth warnings when using older versions of Core (#211) Co-authored-by: Dominic Reber <71256590+domire8@users.noreply.github.com> --- python/CHANGELOG.md | 1 + python/examples/with_api_key.py | 8 +++++--- python/src/aica_api/client.py | 15 +++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/python/CHANGELOG.md b/python/CHANGELOG.md index 8f45511..9f2701b 100644 --- a/python/CHANGELOG.md +++ b/python/CHANGELOG.md @@ -15,6 +15,7 @@ Release Versions: ## Upcoming changes - feat(python): add support for the upcoming auth update (#207) +- fix(api): avoid auth warnings when using older versions of Core (#211) ## 3.0.0 diff --git a/python/examples/with_api_key.py b/python/examples/with_api_key.py index 21e6202..a5c4aaa 100644 --- a/python/examples/with_api_key.py +++ b/python/examples/with_api_key.py @@ -6,7 +6,9 @@ api_key=os.getenv('AICA_API_KEY'), ) -assert client.check() +print(f"Check: {"pass" if client.check() else "failed"}") +print(f'Core Version: {client.core_version()}') +print(f'Protocol: {client.protocol()}') print(f'Application state: {client.get_application_state().text}') -print(f'Application state: {client.load_component("def").text}') -print(client.wait_for_component('abc', 'loaded')) +print(f'Load component: {client.load_component("def").text}') +print(f'Wait for component: {client.wait_for_component('abc', 'loaded', 5)}') diff --git a/python/src/aica_api/client.py b/python/src/aica_api/client.py index 23197e2..bbf9d90 100644 --- a/python/src/aica_api/client.py +++ b/python/src/aica_api/client.py @@ -66,12 +66,10 @@ def __raw_endpoint(self, endpoint: str) -> str: def __ensure_token(self) -> None: """Authenticate with the API and store the result in self.__token.""" - err = ' The function call may fail due to lack of authentication.' has_version, is_compatible = self._check_version( None, '>=4.3.0', - err_incompatible=err, - err_undefined=err, + err_undefined=' The function call may fail due to lack of authentication.', ) if not has_version or not is_compatible: return @@ -128,7 +126,7 @@ def _check_version( requirement: str, *, err_undefined: str = '', - err_incompatible: str = '', + err_incompatible: Optional[str] = None, ) -> tuple[bool, bool]: fname = f'The function {name}' if name is not None else 'This function' if self._core_version is None and self.core_version() is None: @@ -139,10 +137,11 @@ def _check_version( return False, False if not semver.match(self._core_version, requirement): - self._logger.error( - f'{fname} requires AICA Core version {requirement}, ' - f'but the current AICA Core version is {self._core_version}.{err_incompatible}' - ) + if err_incompatible is not None: + self._logger.error( + f'{fname} requires AICA Core version {requirement}, ' + f'but the current AICA Core version is {self._core_version}.{err_incompatible}' + ) return True, False return True, True