ananyajoshi commited on
Commit
2c8d3ee
·
verified ·
1 Parent(s): be469a4

key_store: try both Supabase download endpoint forms for robustness

Browse files
Files changed (1) hide show
  1. app/services/key_store.py +17 -8
app/services/key_store.py CHANGED
@@ -160,14 +160,23 @@ def load_config(tag: str) -> Optional[dict]:
160
  """
161
  if not (is_configured() and tag):
162
  return None
163
- try:
164
- url = f"{_base_url()}/storage/v1/object/{_BUCKET}/{_object_path(tag)}"
165
- status, body = _http("GET", url, _auth_headers())
166
- if not (200 <= status < 300) or not body:
167
- return None
168
- return decrypt_payload(tag, body)
169
- except Exception: # noqa: BLE001 - fail-safe
170
- return None
 
 
 
 
 
 
 
 
 
171
 
172
 
173
  def delete_config(tag: str) -> bool:
 
160
  """
161
  if not (is_configured() and tag):
162
  return None
163
+ obj = _object_path(tag)
164
+ # Supabase exposes private downloads at two equivalent paths depending on
165
+ # version; try the authenticated form first, then the plain one.
166
+ candidates = (
167
+ f"/storage/v1/object/authenticated/{_BUCKET}/{obj}",
168
+ f"/storage/v1/object/{_BUCKET}/{obj}",
169
+ )
170
+ for path in candidates:
171
+ try:
172
+ status, body = _http("GET", f"{_base_url()}{path}", _auth_headers())
173
+ except Exception: # noqa: BLE001 - fail-safe; try the next candidate
174
+ continue
175
+ if 200 <= status < 300 and body:
176
+ payload = decrypt_payload(tag, body)
177
+ if payload is not None:
178
+ return payload
179
+ return None
180
 
181
 
182
  def delete_config(tag: str) -> bool: