|  | 
|  | 1 | +""" | 
|  | 2 | +This module sets defines the routes for your Flask application | 
|  | 3 | +""" | 
|  | 4 | + | 
| 1 | 5 | import os | 
| 2 |  | -from flask import Blueprint, jsonify | 
| 3 | 6 | import base64 | 
| 4 | 7 | import json | 
|  | 8 | +from flask import Blueprint, jsonify | 
| 5 | 9 | 
 | 
| 6 |  | -bp = Blueprint('routes', __name__) | 
|  | 10 | +bp = Blueprint("routes", __name__) | 
| 7 | 11 | 
 | 
| 8 |  | -service_relationship ="redis_session" | 
|  | 12 | +SERVICE_RELATIONSHIP = "redis_session" | 
| 9 | 13 | 
 | 
| 10 |  | -API_PREFIX = '/api/v1' | 
|  | 14 | +API_PREFIX = "/api/v1" | 
| 11 | 15 | 
 | 
| 12 |  | -@bp.route(f'{API_PREFIX}/environment') | 
|  | 16 | + | 
|  | 17 | +@bp.route(f"{API_PREFIX}/environment") | 
| 13 | 18 | 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 | + | 
| 15 | 26 | 
 | 
| 16 |  | -@bp.route('/api/') | 
|  | 27 | +@bp.route("/api/") | 
| 17 | 28 | def home(): | 
|  | 29 | +    """ | 
|  | 30 | +    Returns a welcome message for the home route. | 
|  | 31 | +    """ | 
| 18 | 32 |     return "Hello from the Python backend!" | 
| 19 | 33 | 
 | 
| 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 | + | 
| 23 | 44 |     if not platform_relationships_data: | 
| 24 |  | -        return 'file' | 
|  | 45 | +        return "file" | 
| 25 | 46 | 
 | 
| 26 | 47 |     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" | 
| 33 | 56 |     except (json.JSONDecodeError, TypeError, ValueError): | 
| 34 | 57 |         # Catching potential exceptions due to invalid JSON or other issues | 
| 35 |  | -        return 'file' | 
|  | 58 | +        return "file" | 
| 36 | 59 | 
 | 
| 37 | 60 | 
 | 
| 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") | 
0 commit comments