Skip to content

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

Merged
merged 10 commits into from
Aug 14, 2025
Merged

Conversation

officialasishkumar
Copy link
Member

No description provided.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@Copilot Copilot AI review requested due to automatic review settings August 10, 2025 23:43
Copy link

keploy bot commented Aug 10, 2025

To generate Unit Tests for this PR, please click here.

Copy link

@Copilot Copilot AI left a 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

app = Flask(__name__)

# --- JWT and User Setup (Unchanged) ---
app.config["JWT_SECRET_KEY"] = "super-secret-key"
Copy link
Preview

Copilot AI Aug 10, 2025

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.

Suggested change
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.

Comment on lines 7 to 17
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"]
Copy link
Preview

Copilot AI Aug 10, 2025

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.

Suggested change
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.

Comment on lines 58 to 65
while True:
try:
conn = mysql.connector.connect(**DB_CFG)
cur = conn.cursor(buffered=True)
break
except mysql.connector.Error:
time.sleep(1)

Copy link
Preview

Copilot AI Aug 10, 2025

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.

Suggested change
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.

Comment on lines 30 to 36
# 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
Copy link
Preview

Copilot AI Aug 10, 2025

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.

Suggested change
# 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.

Comment on lines 30 to 36
# 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
Copy link
Preview

Copilot AI Aug 10, 2025

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.

Suggested change
# 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>
Copy link
Contributor

@Achanandhi-M Achanandhi-M left a 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>
@Sarthak160 Sarthak160 merged commit 3a76bcd into keploy:main Aug 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants