Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ $ aignostics qupath install [OPTIONS]
* `--version TEXT`: Version of QuPath to install. Do not change this unless you know what you are doing. [default: 0.6.0-rc5]
* `--path DIRECTORY`: Path to install QuPath to. If not specified, the default installation path will be used.Do not change this unless you know what you are doing. [default: (~/Library/Application Support/aignostics)]
* `--reinstall / --no-reinstall`: Reinstall QuPath even if it is already installed. This will overwrite the existing installation. [default: reinstall]
* `--platform-system TEXT`: Override the system to assume for the installation. This is useful for testing purposes. [default: Darwin]
* `--platform-machine TEXT`: Override the machine architecture to assume for the installation. This is useful for testing purposes. [default: arm64]
* `--platform-system TEXT`: Override the system to assume for the installation. This is useful for testing purposes. [default: Linux]
* `--platform-machine TEXT`: Override the machine architecture to assume for the installation. This is useful for testing purposes. [default: x86_64]
* `--help`: Show this message and exit.

### `aignostics qupath launch`
Expand Down
3 changes: 3 additions & 0 deletions src/aignostics/platform/_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def get_token(use_cache: bool = True, use_device_flow: bool = False) -> str:
# 1. Do not want to use the cached token
# 2. The cached token is expired
# 3. No token was cached yet


token = _authenticate(use_device_flow)
claims = verify_and_decode_token(token)

Expand Down Expand Up @@ -186,6 +188,7 @@ def _authenticate(use_device_flow: bool) -> str:
RuntimeError: If authentication fails.
AssertionError: If the returned token doesn't have the expected format.
"""
# have another setting which says no authentication
if refresh_token := settings().refresh_token:
token = _access_token_from_refresh_token(refresh_token)
elif _can_open_browser() and not use_device_flow:
Expand Down
2 changes: 2 additions & 0 deletions src/aignostics/platform/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@
return Client._api_client_uncached

def token_provider() -> str:
# # given some setting do not inject token_provider into client
return None

Check warning on line 295 in src/aignostics/platform/_client.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Return a value of type "str" instead of "NoneType" or update function "token_provider" type hint.

See more on https://sonarcloud.io/project/issues?id=aignostics_python-sdk&issues=AZr6K5nQb9H2Y8bN-V3m&open=AZr6K5nQb9H2Y8bN-V3m&pullRequest=282
return get_token(use_cache=cache_token)

Check warning on line 296 in src/aignostics/platform/_client.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Delete this unreachable code or refactor the code to make it reachable.

See more on https://sonarcloud.io/project/issues?id=aignostics_python-sdk&issues=AZr6K5nQb9H2Y8bN-V3n&open=AZr6K5nQb9H2Y8bN-V3n&pullRequest=282
Comment on lines +294 to 296
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The token_provider() function incorrectly returns None, preventing token retrieval and causing all API calls to fail.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The token_provider() function at src/aignostics/platform/_client.py:277-279 contains an active return None statement, making the subsequent get_token() call unreachable. This violates the -> str type contract and causes _OAuth2TokenProviderConfiguration to receive None, leading to missing authentication headers in all API requests. Consequently, all API calls will fail with 401 Unauthorized errors.

💡 Suggested Fix

Remove the return None statement from token_provider() at src/aignostics/platform/_client.py:277-279 to allow the get_token() function to execute and return the actual token.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/aignostics/platform/_client.py#L277-L279

Potential issue: The `token_provider()` function at
`src/aignostics/platform/_client.py:277-279` contains an active `return None` statement,
making the subsequent `get_token()` call unreachable. This violates the `-> str` type
contract and causes `_OAuth2TokenProviderConfiguration` to receive `None`, leading to
missing authentication headers in all API requests. Consequently, all API calls will
fail with 401 Unauthorized errors.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 3751515


ca_file = os.getenv("REQUESTS_CA_BUNDLE") # point to .cer file of proxy if defined
config = _OAuth2TokenProviderConfiguration(
Expand Down
8 changes: 8 additions & 0 deletions src/aignostics/platform/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@
values["device_url"] = DEVICE_URL_DEV
values["jws_json_url"] = JWS_JSON_URL_DEV
values["client_id_interactive"] = CLIENT_ID_INTERACTIVE_DEV
case x if x == "http://localhost:8000":

Check failure on line 546 in src/aignostics/platform/_settings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "http://localhost:8000" 5 times.

See more on https://sonarcloud.io/project/issues?id=aignostics_python-sdk&issues=AZr6K5kJb9H2Y8bN-V3l&open=AZr6K5kJb9H2Y8bN-V3l&pullRequest=282
values["audience"] = "abcfsofihaosfih"
values["authorization_base_url"] = "abc"
values["token_url"] = "http://localhost:8000"
values["redirect_uri"] = "http://localhost:8000"
values["device_url"] = "http://localhost:8000"
values["jws_json_url"] = "http://localhost:8000"
values["client_id_interactive"] = "abc"
case _:
raise ValueError(UNKNOWN_ENDPOINT_URL)

Expand Down
2 changes: 2 additions & 0 deletions tests/constants_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
SPOT_3_WIDTH = 4016
SPOT_3_HEIGHT = 3952

# adapt to the DB seed

match os.getenv("AIGNOSTICS_PLATFORM_ENVIRONMENT", "production"):
case "production":
TEST_APPLICATION_ID = "test-app"
Expand Down
Loading