@@ -141,6 +141,8 @@ def login(
141
141
elif host is None : # Always do a fallback to Serverless Hopsworks if not defined
142
142
host = constants .HOSTS .APP_HOST
143
143
144
+ is_app = (host == constants .HOSTS .APP_HOST )
145
+
144
146
# If port same as default, get HOPSWORKS_HOST environment variable
145
147
if port == 443 and "HOPSWORKS_PORT" in os .environ :
146
148
port = os .environ ["HOPSWORKS_PORT" ]
@@ -167,12 +169,12 @@ def login(
167
169
"Could not find api key file on path: {}" .format (api_key_file )
168
170
)
169
171
# 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 :
171
173
try :
172
174
_hw_connection = _hw_connection (
173
175
host = host , port = port , api_key_file = api_key_path
174
176
)
175
- _connected_project = _prompt_project (_hw_connection , project )
177
+ _connected_project = _prompt_project (_hw_connection , project , is_app )
176
178
print (
177
179
"\n Logged in to project, explore it here "
178
180
+ _connected_project .get_url ()
@@ -184,7 +186,7 @@ def login(
184
186
# API Key may be invalid, have the user supply it again
185
187
os .remove (api_key_path )
186
188
187
- if api_key is None and host == constants . HOSTS . APP_HOST :
189
+ if api_key is None and is_app :
188
190
print (
189
191
"Copy your Api Key (first register/login): https://c.app.hopsworks.ai/account/api/generated"
190
192
)
@@ -200,7 +202,7 @@ def login(
200
202
201
203
try :
202
204
_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 )
204
206
except RestAPIError as e :
205
207
logout ()
206
208
raise e
@@ -252,11 +254,14 @@ def _get_cached_api_key_path():
252
254
return api_key_path
253
255
254
256
255
- def _prompt_project (valid_connection , project ):
257
+ def _prompt_project (valid_connection , project , is_app ):
256
258
saas_projects = valid_connection .get_projects ()
257
259
if project is None :
258
260
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
260
265
elif len (saas_projects ) == 1 :
261
266
return saas_projects [0 ]
262
267
else :
0 commit comments