Skip to content

Commit e77d8af

Browse files
committed
fix
1 parent da77322 commit e77d8af

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

python/hopsworks/__init__.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def login(
141141
elif host is None: # Always do a fallback to Serverless Hopsworks if not defined
142142
host = constants.HOSTS.APP_HOST
143143

144+
is_app = (host == constants.HOSTS.APP_HOST)
145+
144146
# If port same as default, get HOPSWORKS_HOST environment variable
145147
if port == 443 and "HOPSWORKS_PORT" in os.environ:
146148
port = os.environ["HOPSWORKS_PORT"]
@@ -167,12 +169,12 @@ def login(
167169
"Could not find api key file on path: {}".format(api_key_file)
168170
)
169171
# If user connected to Serverless Hopsworks, and the cached .hw_api_key exists, then use it.
170-
elif os.path.exists(api_key_path) and host == constants.HOSTS.APP_HOST:
172+
elif os.path.exists(api_key_path) and is_app:
171173
try:
172174
_hw_connection = _hw_connection(
173175
host=host, port=port, api_key_file=api_key_path
174176
)
175-
_connected_project = _prompt_project(_hw_connection, project)
177+
_connected_project = _prompt_project(_hw_connection, project, is_app)
176178
print(
177179
"\nLogged in to project, explore it here "
178180
+ _connected_project.get_url()
@@ -184,7 +186,7 @@ def login(
184186
# API Key may be invalid, have the user supply it again
185187
os.remove(api_key_path)
186188

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

201203
try:
202204
_hw_connection = _hw_connection(host=host, port=port, api_key_value=api_key)
203-
_connected_project = _prompt_project(_hw_connection, project)
205+
_connected_project = _prompt_project(_hw_connection, project, is_app)
204206
except RestAPIError as e:
205207
logout()
206208
raise e
@@ -252,11 +254,14 @@ def _get_cached_api_key_path():
252254
return api_key_path
253255

254256

255-
def _prompt_project(valid_connection, project):
257+
def _prompt_project(valid_connection, project, is_app):
256258
saas_projects = valid_connection.get_projects()
257259
if project is None:
258260
if len(saas_projects) == 0:
259-
return None
261+
if is_app:
262+
raise ProjectException("Could not find any project")
263+
else:
264+
return None
260265
elif len(saas_projects) == 1:
261266
return saas_projects[0]
262267
else:

0 commit comments

Comments
 (0)