2020from cryptography .hazmat .primitives import hashes
2121from cryptography .hazmat .primitives .kdf .pbkdf2 import PBKDF2HMAC
2222from sqlalchemy import text
23+ import sqlalchemy as sa
2324
2425# First-Party
2526from mcpgateway .config import settings
@@ -133,6 +134,7 @@ def reencrypt_with_pbkdf2hmac(argon2id_bundle: str) -> Optional[str]:
133134 except Exception as e :
134135 raise ValueError ("Invalid Argon2id bundle" ) from e
135136
137+
136138def _reflect (conn ):
137139 """Reflect relevant tables.
138140
@@ -147,6 +149,7 @@ def _reflect(conn):
147149 a2a_agents = sa .Table ("a2a_agents" , md , autoload_with = conn )
148150 return {"gateways" : gateways , "a2a_agents" : a2a_agents }
149151
152+
150153def _is_json (col ):
151154 """Check if a column is of JSON type.
152155
@@ -158,6 +161,7 @@ def _is_json(col):
158161 """
159162 return isinstance (col .type , sa .JSON )
160163
164+
161165def _looks_argon2_bundle (val : Optional [str ]) -> bool :
162166 """Heuristic for Argon2id bundle format (JSON with kdf=argon2id).
163167
@@ -255,11 +259,13 @@ def _upgrade_json_client_secret(conn, table):
255259 except json .JSONDecodeError as e :
256260 logger .warning ("Skipping %s.id=%s: invalid JSON (%s)" , table , rid , e )
257261 continue
258- if not isinstance (cfg , dict ): continue
262+ if not isinstance (cfg , dict ):
263+ continue
259264
260265 old = cfg .get ("client_secret" )
261266 new = _upgrade_value (old ) # your helper
262- if not new : continue
267+ if not new :
268+ continue
263269
264270 cfg ["client_secret" ] = new
265271 value = cfg if _is_json (t .c .oauth_config ) else json .dumps (cfg )
@@ -285,11 +291,13 @@ def _downgrade_json_client_secret(conn, table):
285291 except json .JSONDecodeError as e :
286292 logger .warning ("Skipping %s.id=%s: invalid JSON (%s)" , table , rid , e )
287293 continue
288- if not isinstance (cfg , dict ): continue
294+ if not isinstance (cfg , dict ):
295+ continue
289296
290297 old = cfg .get ("client_secret" )
291298 new = _downgrade_value (old ) # your helper
292- if not new : continue
299+ if not new :
300+ continue
293301
294302 cfg ["client_secret" ] = new
295303 value = cfg if _is_json (t .c .oauth_config ) else json .dumps (cfg )
0 commit comments