-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api_client: implement workspaces() query
- Loading branch information
Showing
15 changed files
with
375 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.. _api_client: | ||
|
||
========== | ||
API client | ||
========== | ||
|
||
.. autoclass:: qiskit_aqt_provider.api_client.portal_client.PortalClient | ||
:members: | ||
:show-inheritance: | ||
:inherited-members: | ||
|
||
.. autoclass:: qiskit_aqt_provider.api_client.models.Workspaces | ||
:members: | ||
:show-inheritance: | ||
:exclude-members: __init__, __new__, model_fields, model_computed_fields, model_config | ||
|
||
.. autoclass:: qiskit_aqt_provider.api_client.models.Workspace | ||
:members: | ||
:show-inheritance: | ||
:exclude-members: __init__, __new__, model_fields, model_computed_fields, model_config | ||
|
||
.. autoclass:: qiskit_aqt_provider.api_client.models.Resource | ||
:members: | ||
:show-inheritance: | ||
:exclude-members: __init__, __new__, model_fields, model_computed_fields, model_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# (C) Copyright Alpine Quantum Technologies GmbH 2024 | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
import os | ||
from typing import Final, Optional | ||
|
||
import httpx | ||
|
||
from . import models | ||
from .versions import make_user_agent | ||
|
||
DEFAULT_PORTAL_URL: Final = httpx.URL("https://arnica.aqt.eu") | ||
"""Default URL for the remote portal.""" | ||
|
||
|
||
class PortalClient: | ||
"""Client for the AQT portal API.""" | ||
|
||
USER_AGENT_NAME: Final = "aqt-portal-client" | ||
|
||
def __init__( | ||
self, *, token: str, user_agent_extra: Optional[str] = None, timeout: Optional[float] = 10.0 | ||
) -> None: | ||
"""Initialize a new client for the AQT remote computing portal API. | ||
The portal base URL can be overridden using the ``AQT_PORTAL_URL`` | ||
environment variable. | ||
Args: | ||
token: authentication token. | ||
user_agent_extra: data appended to the default user-agent string. | ||
timeout: HTTP timeout, in seconds. | ||
""" | ||
self.portal_url = httpx.URL(os.environ.get("AQT_PORTAL_URL", DEFAULT_PORTAL_URL)) | ||
|
||
user_agent = make_user_agent(self.USER_AGENT_NAME, extra=user_agent_extra) | ||
headers = {"User-Agent": user_agent} | ||
|
||
if token: | ||
headers["Authorization"] = f"Bearer {token}" | ||
|
||
self._http_client = httpx.Client( | ||
base_url=self.portal_url.join("/api/v1"), | ||
headers=headers, | ||
timeout=timeout, | ||
follow_redirects=True, | ||
) | ||
|
||
def workspaces(self) -> models.Workspaces: | ||
"""List the workspaces visible to the used token. | ||
Raises: | ||
httpx.NetworkError: connection to the remote portal failed. | ||
httpx.HTTPStatusError: something went wrong with the request to the remote portal. | ||
""" | ||
with self._http_client as client: | ||
response = client.get("/workspaces") | ||
|
||
response.raise_for_status() | ||
return models.Workspaces.model_validate(response.json()) |
Oops, something went wrong.