Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robzor92 committed May 8, 2024
1 parent da77322 commit e77d8af
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions python/hopsworks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def login(
elif host is None: # Always do a fallback to Serverless Hopsworks if not defined
host = constants.HOSTS.APP_HOST

is_app = (host == constants.HOSTS.APP_HOST)

# If port same as default, get HOPSWORKS_HOST environment variable
if port == 443 and "HOPSWORKS_PORT" in os.environ:
port = os.environ["HOPSWORKS_PORT"]
Expand All @@ -167,12 +169,12 @@ def login(
"Could not find api key file on path: {}".format(api_key_file)
)
# If user connected to Serverless Hopsworks, and the cached .hw_api_key exists, then use it.
elif os.path.exists(api_key_path) and host == constants.HOSTS.APP_HOST:
elif os.path.exists(api_key_path) and is_app:
try:
_hw_connection = _hw_connection(
host=host, port=port, api_key_file=api_key_path
)
_connected_project = _prompt_project(_hw_connection, project)
_connected_project = _prompt_project(_hw_connection, project, is_app)
print(
"\nLogged in to project, explore it here "
+ _connected_project.get_url()
Expand All @@ -184,7 +186,7 @@ def login(
# API Key may be invalid, have the user supply it again
os.remove(api_key_path)

if api_key is None and host == constants.HOSTS.APP_HOST:
if api_key is None and is_app:
print(
"Copy your Api Key (first register/login): https://c.app.hopsworks.ai/account/api/generated"
)
Expand All @@ -200,7 +202,7 @@ def login(

try:
_hw_connection = _hw_connection(host=host, port=port, api_key_value=api_key)
_connected_project = _prompt_project(_hw_connection, project)
_connected_project = _prompt_project(_hw_connection, project, is_app)
except RestAPIError as e:
logout()
raise e
Expand Down Expand Up @@ -252,11 +254,14 @@ def _get_cached_api_key_path():
return api_key_path


def _prompt_project(valid_connection, project):
def _prompt_project(valid_connection, project, is_app):
saas_projects = valid_connection.get_projects()
if project is None:
if len(saas_projects) == 0:
return None
if is_app:
raise ProjectException("Could not find any project")
else:
return None
elif len(saas_projects) == 1:
return saas_projects[0]
else:
Expand Down

0 comments on commit e77d8af

Please sign in to comment.