File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
src/python/cocalc-api/tests Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -126,10 +126,30 @@ def validate_api_key_config(hub):
126126 For account-scoped keys, requires COCALC_PROJECT_ID to be set.
127127 For project-scoped keys, no additional configuration needed.
128128 """
129+ scope = None
130+ hub_error = None
131+
132+ # First, try the hub endpoint (works only for account-scoped keys)
129133 try :
130134 scope = hub .system .test ()
131135 except Exception as e :
132- pytest .fail (f"Failed to determine API key scope: { e } " )
136+ hub_error = e
137+
138+ # If hub check failed, fall back to the project endpoint so project-scoped keys work
139+ if scope is None :
140+ try :
141+ project_client = Project (
142+ api_key = hub .api_key ,
143+ host = hub .host ,
144+ project_id = os .environ .get ("COCALC_PROJECT_ID" ),
145+ )
146+ scope = project_client .system .test ()
147+ except Exception as project_error :
148+ pytest .fail (
149+ "Failed to determine API key scope using both hub and project endpoints:\n "
150+ f" hub error: { hub_error } \n "
151+ f" project error: { project_error } "
152+ )
133153
134154 is_account_scoped = "account_id" in scope
135155 is_project_scoped = "project_id" in scope
You can’t perform that action at this time.
0 commit comments