Selaa lähdekoodia

数据库连接。

tanlie 6 päivää sitten
vanhempi
säilyke
5d0119202f
2 muutettua tiedostoa jossa 37 lisäystä ja 1 poistoa
  1. 34 0
      README.md
  2. 3 1
      app/api/v1/user.py

+ 34 - 0
README.md

@@ -1,2 +1,36 @@
 # ginger
 
+Small Flask project. This README explains how to store the MySQL password securely using the OS keyring and how to verify it.
+
+## Secure DB password with keyring
+
+This project prefers reading `MYSQL_PASSWORD` from environment variables. If you don't want to store the password in `.env`, put it into the OS keyring (recommended for development machines).
+
+Service name used: `ginger_mysql`
+
+Examples:
+
+- macOS / Linux (python -c):
+
+  python -c "import keyring; keyring.set_password('ginger_mysql', 'root', '@@qinys12346..')"
+
+- Windows PowerShell:
+
+  python -c "import keyring; keyring.set_password('ginger_mysql', 'root', '@@qinys12346..')"
+
+To verify the stored password:
+
+  python -c "import keyring; print(keyring.get_password('ginger_mysql', 'root'))"
+
+## Alternative: environment variable
+
+You can also set `MYSQL_PASSWORD` in `.env` (not recommended to commit `.env`). The repository `.gitignore` already ignores `.env` files.
+
+## Test DB connection (dev only)
+
+Start the app and POST to `/db/test` (only works when DEBUG or TESTING is true) to create tables and insert a test user.
+
+## Notes
+
+- On CI or servers prefer a proper secret manager (Vault, AWS Secrets Manager, etc.) and inject secrets as env vars.
+- Do NOT commit real passwords to the repository.

+ 3 - 1
app/api/v1/user.py

@@ -4,10 +4,12 @@ auther: tanlie
 date: 2026/8/23
 """
 from app.libs.Redprint import Redprint
+from app.models.user import User
 
 api = Redprint("user")
 
 
 @api.route('/get_user', methods=['GET'])
 def get_user():
-    return 'tanlie'
+    user = User.query.filter_by(id=1).first()
+    return user.to_dict() if user else 'User not found'