MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_or_create_secret_key

Method get_or_create_secret_key

auth_manager.py:860–881  ·  view source on GitHub ↗

Get or create a persistent Flask SECRET_KEY.

(self)

Source from the content-addressed store, hash-verified

858 # =========================================================================
859
860 def get_or_create_secret_key(self) -> str:
861 """Get or create a persistent Flask SECRET_KEY."""
862 try:
863 with self._get_auth_conn() as conn:
864 cursor = conn.cursor()
865 cursor.execute("SELECT value FROM app_secrets WHERE key = 'flask_secret_key'")
866 row = cursor.fetchone()
867 if row:
868 return row['value']
869
870 # Generate and store a new secret key
871 secret_key = secrets.token_hex(32)
872 cursor.execute(
873 "INSERT INTO app_secrets (key, value) VALUES (?, ?)",
874 ('flask_secret_key', secret_key)
875 )
876 conn.commit()
877 return secret_key
878 except Exception as e:
879 logger.error(f"Failed to get/create secret key: {e}")
880 # Fallback to a random key (won't persist across restarts)
881 return secrets.token_hex(32)
882
883 # =========================================================================
884 # DB HELPER METHODS

Callers 1

webapp_modern.pyFile · 0.80

Calls 6

_get_auth_connMethod · 0.95
cursorMethod · 0.80
commitMethod · 0.80
errorMethod · 0.80
executeMethod · 0.45
fetchoneMethod · 0.45

Tested by

no test coverage detected