Skip to content

Commit

Permalink
fix(api): avoid auth warnings when using older versions of Core (#211)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominic Reber <[email protected]>
  • Loading branch information
LouisBrunner and domire8 authored Jan 28, 2025
1 parent f02d22d commit 9ed9e88
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions python/examples/with_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}')
15 changes: 7 additions & 8 deletions python/src/aica_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 9ed9e88

Please sign in to comment.