-
Notifications
You must be signed in to change notification settings - Fork 55
feat: add flask-mysql app #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
To generate Unit Tests for this PR, please click here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new Flask application that integrates with MySQL database functionality, featuring JWT authentication and comprehensive MySQL protocol testing endpoints.
- Introduces a Flask-MySQL demo application with JWT authentication and database operations
- Implements Docker containerization with health checks and Keploy integration for testing
- Creates endpoints specifically designed to test different aspects of MySQL protocol communication
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
flask-mysql/requirements.txt | Defines Python dependencies for Flask, JWT, and MySQL connectivity |
flask-mysql/docker-compose.yml | Configures MySQL database service with health checks and networking |
flask-mysql/demo.py | Main Flask application with JWT auth and MySQL protocol testing endpoints |
flask-mysql/Dockerfile | Container configuration with Keploy integration and health monitoring |
flask-mysql/demo.py
Outdated
app = Flask(__name__) | ||
|
||
# --- JWT and User Setup (Unchanged) --- | ||
app.config["JWT_SECRET_KEY"] = "super-secret-key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JWT secret key is hardcoded and predictable. This poses a serious security risk in production. Use an environment variable or secure secret management system instead.
app.config["JWT_SECRET_KEY"] = "super-secret-key" | |
app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY", "super-secret-key") |
Copilot uses AI. Check for mistakes.
flask-mysql/docker-compose.yml
Outdated
MYSQL_ROOT_PASSWORD: rootpass | ||
MYSQL_DATABASE: demo | ||
MYSQL_USER: demo | ||
MYSQL_PASSWORD: demopass | ||
|
||
networks: | ||
- keploy-network | ||
ports: # expose to host → 127.0.0.1:3306 | ||
- "3306:3306" | ||
healthcheck: | ||
test: ["CMD", "mysqladmin", "ping", "-pdemopass"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Database passwords are hardcoded in the compose file. Consider using Docker secrets or environment files to manage sensitive credentials securely.
MYSQL_ROOT_PASSWORD: rootpass | |
MYSQL_DATABASE: demo | |
MYSQL_USER: demo | |
MYSQL_PASSWORD: demopass | |
networks: | |
- keploy-network | |
ports: # expose to host → 127.0.0.1:3306 | |
- "3306:3306" | |
healthcheck: | |
test: ["CMD", "mysqladmin", "ping", "-pdemopass"] | |
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | |
MYSQL_DATABASE: ${MYSQL_DATABASE} | |
MYSQL_USER: ${MYSQL_USER} | |
MYSQL_PASSWORD: ${MYSQL_PASSWORD} | |
networks: | |
- keploy-network | |
ports: # expose to host → 127.0.0.1:3306 | |
- "3306:3306" | |
healthcheck: | |
test: ["CMD", "mysqladmin", "ping", "-p${MYSQL_PASSWORD}"] |
Copilot uses AI. Check for mistakes.
flask-mysql/demo.py
Outdated
while True: | ||
try: | ||
conn = mysql.connector.connect(**DB_CFG) | ||
cur = conn.cursor(buffered=True) | ||
break | ||
except mysql.connector.Error: | ||
time.sleep(1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The infinite retry loop for database connection has no timeout or maximum retry limit. This could cause the application to hang indefinitely if the database never becomes available.
while True: | |
try: | |
conn = mysql.connector.connect(**DB_CFG) | |
cur = conn.cursor(buffered=True) | |
break | |
except mysql.connector.Error: | |
time.sleep(1) | |
MAX_DB_RETRIES = 10 | |
retry_count = 0 | |
while retry_count < MAX_DB_RETRIES: | |
try: | |
conn = mysql.connector.connect(**DB_CFG) | |
cur = conn.cursor(buffered=True) | |
break | |
except mysql.connector.Error: | |
retry_count += 1 | |
time.sleep(1) | |
else: | |
raise RuntimeError(f"Could not connect to the database after {MAX_DB_RETRIES} attempts.") |
Copilot uses AI. Check for mistakes.
flask-mysql/Dockerfile
Outdated
# Expose port 5000 for Flask | ||
EXPOSE 5000 | ||
|
||
# ---- START NEW HEALTHCHECK ---- | ||
# Add a healthcheck to ensure the app is running before considering it "up" | ||
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 \ | ||
CMD curl -f http://localhost:5000/ || exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The healthcheck uses port 5000 but the application runs on port 5001 according to line 177 in demo.py. This will cause the healthcheck to always fail.
# Expose port 5000 for Flask | |
EXPOSE 5000 | |
# ---- START NEW HEALTHCHECK ---- | |
# Add a healthcheck to ensure the app is running before considering it "up" | |
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 \ | |
CMD curl -f http://localhost:5000/ || exit 1 | |
# Expose port 5001 for Flask | |
EXPOSE 5001 | |
# ---- START NEW HEALTHCHECK ---- | |
# Add a healthcheck to ensure the app is running before considering it "up" | |
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 \ | |
CMD curl -f http://localhost:5001/ || exit 1 |
Copilot uses AI. Check for mistakes.
flask-mysql/Dockerfile
Outdated
# Expose port 5000 for Flask | ||
EXPOSE 5000 | ||
|
||
# ---- START NEW HEALTHCHECK ---- | ||
# Add a healthcheck to ensure the app is running before considering it "up" | ||
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 \ | ||
CMD curl -f http://localhost:5000/ || exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dockerfile exposes port 5000 but the Flask application runs on port 5001. This port mismatch will prevent external access to the application.
# Expose port 5000 for Flask | |
EXPOSE 5000 | |
# ---- START NEW HEALTHCHECK ---- | |
# Add a healthcheck to ensure the app is running before considering it "up" | |
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 \ | |
CMD curl -f http://localhost:5000/ || exit 1 | |
# Expose port 5001 for Flask | |
EXPOSE 5001 | |
# ---- START NEW HEALTHCHECK ---- | |
# Add a healthcheck to ensure the app is running before considering it "up" | |
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 \ | |
CMD curl -f http://localhost:5001/ || exit 1 |
Copilot uses AI. Check for mistakes.
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
No description provided.