Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit d14fbb2

Browse files
Bring up to date with production
2 parents 809ec82 + 30a23e8 commit d14fbb2

31 files changed

+766
-518
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,34 @@ jobs:
4040
cache: 'pip'
4141

4242
################################################################################################
43-
# B. Test repo.
44-
- name: "4. Run Frontend tests."
43+
# B. Prettify, lint, and test repo.
44+
- name: "4. Preparing"
4545
run: |
4646
echo "::notice::Running react-scripts tests."
4747
export CI=true
4848
npm install cross-env npm-run-all -g
4949
npm install
50-
npm run test:frontend
50+
- name: "5. Verifying backend code is pretty"
51+
run: |
52+
npm run prettier:backend
53+
- name: "6. Verifying frontend code is pretty"
54+
run: |
55+
npm run prettier:frontend
56+
- name: "7. Linting frontend"
57+
run: npm run lint:frontend
58+
- name: "8. Run Frontend tests"
59+
run: npm run test:frontend
60+
- name: "9. Run Backend linting"
61+
run: |
62+
npm run lint:backend
5163
5264
################################################################################################
5365
# C. Ensure no vulnerabilities.
54-
- name: "5. Test: there should be no Python vulnerabilities."
66+
- name: "10. Test: there should be no Python vulnerabilities."
5567
run: |
5668
echo "::notice::Checking for vulnerabilities in backend Python app dependencies."
5769
npm run test:backend
58-
- name: "6. Test: there should be no HIGH Node.js vulnerabilities."
70+
- name: "11. Test: there should be no HIGH Node.js vulnerabilities."
5971
run: |
6072
echo "::notice::Checking for high vulnerabilities in frontend Node.js app dependencies."
6173
cd frontend
@@ -69,7 +81,7 @@ jobs:
6981
else
7082
echo "::notice::No HIGH vulnerabilities found on frontend app."
7183
fi
72-
- name: "7. Test: there should be no CRITICAL Node.js vulnerabilities."
84+
- name: "12. Test: there should be no CRITICAL Node.js vulnerabilities."
7385
run: |
7486
echo "::notice::Checking for critical vulnerabilities in frontend Node.js app dependencies."
7587
cd frontend

backend/app/routes.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
1+
"""
2+
This module sets defines the routes for your Flask application
3+
"""
4+
15
import os
2-
from flask import Blueprint, jsonify
36
import base64
47
import json
8+
from flask import Blueprint, jsonify
59

6-
bp = Blueprint('routes', __name__)
10+
bp = Blueprint("routes", __name__)
711

8-
service_relationship ="redis_session"
12+
SERVICE_RELATIONSHIP = "redis_session"
913

10-
API_PREFIX = '/api/v1'
14+
API_PREFIX = "/api/v1"
1115

12-
@bp.route(f'{API_PREFIX}/environment')
16+
17+
@bp.route(f"{API_PREFIX}/environment")
1318
def environment():
14-
return jsonify(type=getPlatformEnvironment(), session_storage=getSessionStorageType())
19+
"""
20+
Returns the environment type and sessions storage type as json
21+
"""
22+
return jsonify(
23+
type=get_platform_environment(), session_storage=get_session_storage_type()
24+
)
25+
1526

16-
@bp.route('/api/')
27+
@bp.route("/api/")
1728
def home():
29+
"""
30+
Returns a welcome message for the home route.
31+
"""
1832
return "Hello from the Python backend!"
1933

20-
def getSessionStorageType():
21-
platform_relationships_data = os.environ.get('PLATFORM_RELATIONSHIPS')
22-
34+
35+
def get_session_storage_type():
36+
"""
37+
Returns the type of session storage from the PLATFORM_RELATIONSHIPS environment variable.
38+
If the variable is not set or if it does not contain the SERVICE_RELATIONSHIP, it returns "file"
39+
If the variable is set and contains the SERVICE_RELATIONSHIP, it returns "redis".
40+
If there is an error decoding the PLATFORM_RELATIONSHIPS variable, it returns "file".
41+
"""
42+
platform_relationships_data = os.environ.get("PLATFORM_RELATIONSHIPS")
43+
2344
if not platform_relationships_data:
24-
return 'file'
45+
return "file"
2546

2647
try:
27-
platform_relationships = json.loads(base64.b64decode(platform_relationships_data))
28-
29-
if service_relationship in platform_relationships:
30-
return 'redis'
31-
else:
32-
return 'file'
48+
platform_relationships = json.loads(
49+
base64.b64decode(platform_relationships_data)
50+
)
51+
52+
if SERVICE_RELATIONSHIP in platform_relationships:
53+
return "redis"
54+
55+
return "file"
3356
except (json.JSONDecodeError, TypeError, ValueError):
3457
# Catching potential exceptions due to invalid JSON or other issues
35-
return 'file'
58+
return "file"
3659

3760

38-
def getPlatformEnvironment():
39-
return os.environ.get('PLATFORM_ENVIRONMENT_TYPE', 'local')
61+
def get_platform_environment():
62+
"""
63+
Returns the type of the environment from PLATFORM_ENVIRONMENT_TYPE environment variable.
64+
If the variable is not set, it returns "local".
65+
"""
66+
return os.environ.get("PLATFORM_ENVIRONMENT_TYPE", "local")

backend/main.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
1-
from flask import Flask
1+
"""
2+
This module sets up the Flask application and its configurations.
3+
4+
It initializes the Flask app, sets up CORS, loads environment variables,
5+
configures session management (commented out, pending Redis implementation),
6+
registers the routes, and runs the app with the specified port and debug settings.
7+
"""
8+
29
import os
3-
# from flask_session import Session
10+
from flask import Flask
411
from flask_cors import CORS
5-
from app import routes
612
from dotenv import load_dotenv
13+
from app import routes
14+
15+
# from flask_session import Session
16+
17+
18+
def create_app():
19+
"""
20+
Create and configure an instance of the Flask application.
721
8-
def createApp():
22+
Environment variables are loaded, the Flask app is initialized, and
23+
Redis configuration for sessions is set up if available. Routes are
24+
also registered with the application instance before it is returned.
25+
"""
926
# Bring in environment variables
1027
load_dotenv()
1128

1229
# Initialize app
13-
app = Flask(__name__)
30+
flask_app = Flask(__name__)
1431

1532
# Use Redis for Sessions if available
1633
# if 'implement redis but consider how to handle in local dev environment':
1734
# app.config['SESSION_TYPE'] = 'redis' # Session storage type
1835
# app.config['SESSION_PERMANENT'] = False # Make the sessions non-permanent
1936
# app.config['SESSION_USE_SIGNER'] = True # Securely sign the session cookie
2037
# app.config['SESSION_KEY_PREFIX'] = 'session:' # Prefix for storing session data in Redis
21-
# app.config['SESSION_REDIS'] = redis.StrictRedis(host='localhost', port=6379, db=0) # Redis configuration
38+
# app.config['SESSION_REDIS'] = redis.StrictRedis(host='localhost', port=6379, db=0)
2239

2340
# sess = Session()
2441
# sess.init_app(app)
2542

43+
flask_app.register_blueprint(routes.bp)
2644

27-
app.register_blueprint(routes.bp)
45+
return flask_app
2846

29-
return app
3047

31-
app = createApp()
48+
app = create_app()
3249
CORS(app)
3350

3451
if __name__ == "__main__":
35-
flask_environment = os.environ.get('FLASK_ENV', 'local')
52+
flask_environment = os.environ.get("FLASK_ENV", "local")
3653
enable_debug = flask_environment != "production"
37-
web_port = os.environ.get('PORT', 8000)
54+
web_port = os.environ.get("PORT", 8000)
3855
app.run(port=web_port, debug=enable_debug)

backend/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ toml==0.10.2
4040
urllib3==2.0.7
4141
webencodings==0.5.1
4242
Werkzeug==3.0.1
43+
pylint==3.0.2
44+
black==23.3.0

backend/scripts/lint_backend.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
python3 -m venv env
4+
source env/bin/activate
5+
pip install --upgrade pip
6+
pip install -r requirements.txt
7+
8+
pylint main.py app/**/*.py
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
python3 -m venv env
4+
source env/bin/activate
5+
pip install --upgrade pip
6+
pip install -r requirements.txt
7+
8+
black . --diff --color --check

frontend/.eslintrc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"extends": [
3-
"react-app",
4-
"plugin:testing-library/react"
5-
],
6-
"plugins": ["testing-library"]
7-
}
2+
"extends": ["react-app", "plugin:testing-library/react"],
3+
"plugins": ["testing-library"]
4+
}

frontend/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
coverage

frontend/.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"build": "react-scripts build",
2828
"test": "react-scripts test",
2929
"eject": "react-scripts eject",
30-
"lint": "eslint src --ext .js,.jsx,.ts,.tsx"
30+
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
31+
"pretty": "prettier . --check",
32+
"pretty:fix": "prettier . --write"
3133
},
3234
"eslintConfig": {
3335
"extends": [

0 commit comments

Comments
 (0)