Skip to content

Commit 936f006

Browse files
authored
Merge branch 'main' into DEP-245-delete-users
2 parents e6b48cf + 7b688b2 commit 936f006

14 files changed

Lines changed: 41 additions & 49 deletions

File tree

.github/workflows/engagement-api-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
testing:
5353
needs: setup-job
5454
env:
55-
FLASK_ENV: "testing"
55+
ENV: "testing"
5656
DATABASE_TEST_URL: "postgresql://postgres:postgres@localhost:5432/postgres"
5757
SITE_URL: "http://localhost:3000"
5858

CHANGELOG.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
- Added success and error messages to provide feedback on the deletion process.
77
- Reworked the user details component to rearrange the existing layout and accommodate the new delete button, while ensuring a clear and intuitive user experience.
88

9+
## April 1, 2026
10+
11+
- **Chore** Change trigger for environment detection [🎟️ DEP-242](https://citz-gdx.atlassian.net/browse/DEP-242)
12+
- Updated Helm templates to set a new environment variable `ENV` in the API deployment, which is then used by the API to determine the current environment (dev/test/prod).
13+
- The env variable is loaded in config.py and is available as current_app.config['ENVIRONMENT'] for use in the API codebase.
14+
- Also added REACT_APP_ENV variable to the web deployment and updated the web app to use this variable for environment detection on the frontend as well. This is curently used to determine whether to show the EnvironmentBanner that warns users that they are in a non-prod environment, but can be used for other environment-specific frontend logic as needed.
15+
916
## March 31, 2026
1017

1118
- **Chore** OpenShift and Helm value changes from MET to DEP [🎟️ DEP-231](https://citz-gdx.atlassian.net/browse/DEP-231)

api/sample.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# For more information on these values, please see the documentation
33
# or api/src/api/config.py
44

5-
# Changes Flask's run mode and the set of env vars are used to configure the app. You should not need to change this here.
6-
FLASK_ENV=development
5+
# Used to control certain production-specific behaviours
6+
ENV=dev
77

8-
USE_DEBUG=True # Enable a dev-friendly debug mode
8+
FLASK_DEBUG=True # Enable a dev-friendly debug mode
99
TESTING= # Handle errors normally (False) or raise exceptions (True)
1010

1111
# CORS Settings

api/src/api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _deprecated_print(*args, **kwargs):
7777
)
7878

7979

80-
def create_app(run_mode=os.getenv('FLASK_ENV', 'development')):
80+
def create_app(run_mode=os.getenv('ENV', 'prod')):
8181
"""Create flask app."""
8282
from api.resources import API_BLUEPRINT # pylint: disable=import-outside-toplevel
8383

@@ -104,7 +104,7 @@ def create_app(run_mode=os.getenv('FLASK_ENV', 'development')):
104104
app.register_blueprint(API_BLUEPRINT)
105105

106106
# Setup jwt for keycloak
107-
if os.getenv('FLASK_ENV', 'production') != 'testing':
107+
if os.getenv('ENV', 'production') != 'testing':
108108
setup_jwt_manager(app, jwt)
109109

110110
# Database connection initialize

api/src/api/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@ def get_named_config(environment: Union[str, None]) -> 'Config':
4646
:raises: KeyError if the requested configuration is not found.
4747
"""
4848
config_mapping = {
49+
'dev': DevConfig,
4950
'development': DevConfig,
51+
'test': DevConfig,
5052
'default': ProdConfig,
5153
'staging': ProdConfig,
54+
'prod': ProdConfig,
5255
'production': ProdConfig,
5356
'testing': TestConfig,
5457
'docker': DockerConfig,
5558
}
5659
try:
5760
print(f'Loading configuration: {environment}...')
58-
return config_mapping.get(environment or 'production', ProdConfig)()
61+
return config_mapping.get(environment or 'prod', ProdConfig)()
5962
except KeyError as e:
6063
raise KeyError(f'Configuration "{environment}" not found.') from e
6164

@@ -91,7 +94,7 @@ def __init__(self) -> None:
9194
setattr(self, f'JWT_OIDC_{key}', value)
9295

9396
# Enable live reload and interactive API debugger for developers
94-
os.environ['FLASK_DEBUG'] = str(self.USE_DEBUG)
97+
os.environ['FLASK_DEBUG'] = str(self.DEBUG)
9598

9699
@property
97100
# pylint: disable=invalid-name
@@ -116,7 +119,7 @@ def SQLALCHEMY_DATABASE_URI(self) -> str:
116119

117120
# If enabled, the interactive debugger will be shown for any
118121
# unhandled Exceptions, and the server will be reloaded when code changes.
119-
USE_DEBUG = env_truthy('FLASK_DEBUG', default=False)
122+
DEBUG = env_truthy('FLASK_DEBUG', default=False)
120123

121124
# SQLAlchemy settings
122125
# Echoes the SQL queries generated - useful for debugging

api/src/api/services/engagement_service.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""Service for engagement management."""
22

3+
import os
34
from datetime import datetime, timezone
45
from http import HTTPStatus
5-
import os
66
from typing import Mapping, Optional, Sequence, Union
77

88
from sqlalchemy.exc import SQLAlchemyError
99
from sqlalchemy.orm import selectinload
10-
from flask import current_app
10+
from flask import current_app, has_app_context
1111
from flask_restx import abort
1212
from marshmallow import ValidationError
1313

@@ -550,7 +550,13 @@ def delete(cls, engagement_id: int):
550550
one_of_roles = (Role.SUPER_ADMIN.value, Role.UNPUBLISH_ENGAGEMENT.value)
551551
authorization.check_auth(one_of_roles=one_of_roles)
552552

553-
current_env = os.getenv('FLASK_ENV', 'production').lower()
553+
current_env = (
554+
(current_app.config.get('ENVIRONMENT') if has_app_context() else '') or
555+
os.getenv('ENV') or
556+
os.getenv('DEPLOYMENT_ENV') or
557+
'prod'
558+
).strip().lower()
559+
554560
if current_env in ('prod', 'production'):
555561
abort(HTTPStatus.FORBIDDEN, 'Cannot delete an engagement in production environment')
556562

api/tests/unit/services/test_engagement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_delete_failure_engagement_published(session, mocker):
132132

133133
def test_delete_failure_production_environment(db, monkeypatch, mocker):
134134
"""Engagement delete should be blocked in production (403 Forbidden)."""
135-
monkeypatch.setenv('FLASK_ENV', 'production')
135+
monkeypatch.setenv('ENV', 'prod')
136136
mocker.patch.object(authorization, 'check_auth', return_value=True)
137137

138138
with pytest.raises(Forbidden) as excinfo:

notify-api/src/notify_api/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_named_config(config_name: str = 'production'):
3939
4040
:raise: KeyError: if an unknown configuration is requested
4141
"""
42-
if config_name in ['production', 'staging', 'default']:
42+
if config_name in ['production', 'prod', 'staging', 'default']:
4343
config = ProdConfig()
4444
elif config_name == 'testing':
4545
config = TestConfig()
@@ -54,6 +54,7 @@ class _Config(): # pylint: disable=too-few-public-methods
5454
"""Base class configuration that should set reasonable defaults for all the other configurations."""
5555

5656
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
57+
ENVIRONMENT = os.getenv('ENV', 'production')
5758

5859
# GC Notify
5960
GC_NOTIFY_API_KEY = os.getenv('GC_NOTIFY_API_KEY')

openshift/api/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata:
88
app-group: engagement-app
99
data:
1010
# Engagement API configuration
11+
ENV: {{ .Values.environment | quote }}
1112
CORS_ORIGINS: {{ .Values.site.url }}
1213
DEFAULT_TENANT_SHORT_NAME: {{ .Values.tenant.shortName }}
1314
ACCESS_REQUEST_EMAIL_TEMPLATE_ID: {{ .Values.email.templateID.accessRequest }}

openshift/web/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata:
88
environment: {{ .Values.environment }}
99
data:
1010
ENV: "{{ .Values.environment }}"
11+
REACT_APP_ENVIRONMENT: "{{ .Values.environment }}"
1112
# This data gets turned into config.js by the nginx config
1213
# Common
1314
REACT_APP_PUBLIC_URL: "{{ .Values.site.url }}"

0 commit comments

Comments
 (0)