Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSK-2782] Allow GiskardClient to read api key from env #1809

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions giskard/client/giskard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def _limit_str_size(json, field, limit=255):


class GiskardClient:
def __init__(self, url: str, key: str, hf_token: str = None):
def __init__(self, url: str, key: str = None, hf_token: str = None):
self.host_url = url
self.key = key
self.key = key or os.getenv("GSK_API_KEY")
self.hf_token = hf_token
base_url = urljoin(url, "/api/v2/")

Expand All @@ -138,6 +138,9 @@ def __init__(self, url: str, key: str, hf_token: str = None):

self._session.mount(url, adapter)

if self.key is None:
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking here, but could you put this check earlier ? like line 133

It's good practice to validate as soon as you can, then do the logic

raise RuntimeError("You must provide an API key for the client to connect to the hub")

self._session.auth = BearerAuth(key)

if hf_token:
Expand Down