diff --git a/.gitlab/ci/job.php.gitlab-ci.yml b/.gitlab/ci/job.php.gitlab-ci.yml index a964d98410455729ccb6d2347d7692e8b652b6fc..259b76f63bdcda1d944a4f79ab75db2c22fced1b 100644 --- a/.gitlab/ci/job.php.gitlab-ci.yml +++ b/.gitlab/ci/job.php.gitlab-ci.yml @@ -370,7 +370,8 @@ php8.1_release-build: - echo "${CI_PROJECT_TITLE}" >> "${PHP_WEBAPP_DIR}/README.txt" - echo "${DOC_URL}" >> "${PHP_WEBAPP_DIR}/README.txt" - echo "APP_ENV=prod" > "${PHP_WEBAPP_DIR}/.env.local" - - sed -i "s/major.minor.patch/${CI_COMMIT_TAG}/" "${PHP_WEBAPP_DIR}/config/services.yaml" + - sed -i "s/version_major.minor.patch/${CI_COMMIT_TAG}/" "${PHP_WEBAPP_DIR}/.env" +# - sed -i "s/version_major.minor.patch/${CI_COMMIT_TAG}/" "${PHP_WEBAPP_DIR}/config/services.yaml" - cat "${PHP_WEBAPP_DIR}/config/services.yaml" - mkdir -p "${CI_PROJECT_DIR}/build-result/${BUILD_NAME}" - mkdir -p "${CI_PROJECT_DIR}/build-result/${BUILD_NAME}/bin" diff --git a/webapp/.env b/webapp/.env index 2cedfe03580c91d30641ac3d3801cfa1b5e2b38b..e96407719fcc47c6eeb5b16c637d29c3e6508ddc 100644 --- a/webapp/.env +++ b/webapp/.env @@ -18,6 +18,7 @@ # - APP_SECRET Application secret to generate CSRF tokens # - DATABASE_URL Database configuration (PostgreSQL) # - MAILER_DSN SMTP configuration +######################################################################################################################## # - WEBAPP_DEFAULT_URI Default URI used to generate URLs in a non-HTTP context # - WEBAPP_EMAIL_FROM Sender's email address to send emails from the web application # - WEBAPP_EMAIL_ALERTING_TO Email address for alert notifications (web application not working properly, ...) @@ -30,6 +31,7 @@ ####################################################################################################################### # - WEBAPP_USER_CONFIG_RESET_PASSWORD_TOKEN_LIFETIME Lifetime of reset password token in seconds (default: 1200 = 20 minutes). # - WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH Minimum user password length (default: 12) +# - WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY Public display of software version (default: true) ####################################################################################################################### ###> symfony/framework-bundle ### @@ -80,6 +82,7 @@ WEBAPP_SESSION_LIFETIME=3600 WEBAPP_TIMEZONE='Europe/Paris' WEBAPP_USER_CONFIG_PASSWORD_RESET_TOKEN_LIFETIME=1200 WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH=12 +WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY=true ####################################################################### # Webapp - List of allowed domains and IP to prevent HTTP Host header attacks @@ -100,3 +103,15 @@ WEBAPP_TRUSTED_HOSTS='' # Only allow incoming requests for all subdomains of example.org # WEBAPP_TRUSTED_HOSTS='^(.+\.)?example\.org$' ################################################################################################## + + +####################################################################################################################### +####################################################################################################################### + +# We strongly recommend leaving the following environment variables unchanged +SOFTWARE_NAME='Comptoir' +SOFTWARE_RELEASE='version_major.minor.patch' + ################################################################################################## + # Do not modify if you have not identified + # the technical implications: HTTP headers using theses values, ... + ################################################################################################## diff --git a/webapp/.env.dev b/webapp/.env.dev index 4d4e575bc0ee0cc60dd9bd16b6410d95af145ca5..8df8b80aeb3e4b399dcc5b6b97c58b2ff3e2975b 100644 --- a/webapp/.env.dev +++ b/webapp/.env.dev @@ -62,4 +62,15 @@ MAILER_DSN=smtp://127.0.0.1:1025 # error 500 ---> Connection could not be established with host "0.0.0.0:9091": # stream_socket_client(): unable to connect to 0.0.0.0:9091 (Connection refused) ################################################################################################## -####################################################################### + + + +####################################################################################################################### +####################################################################################################################### + +# We strongly recommend leaving the following environment variables unchanged +SOFTWARE_NAME='Comptoir-DEV-Software' + ################################################################################################## + # Do not modify if you have not identified + # the technical implications: HTTP headers using this value, ... + ################################################################################################## diff --git a/webapp/.env.prod b/webapp/.env.prod index 1399c50831b6b0742a52bf99f830f74cf8461eed..87a717977ca4b579f3f78ee66d3e5f3b7b29229e 100644 --- a/webapp/.env.prod +++ b/webapp/.env.prod @@ -18,7 +18,8 @@ # - APP_SECRET Application secret to generate CSRF tokens # - DATABASE_URL Database configuration (PostgreSQL) # - MAILER_DSN SMTP configuration -######################################################################################################################## - WEBAPP_DEFAULT_URI Default URI used to generate URLs in a non-HTTP context +######################################################################################################################## +# - WEBAPP_DEFAULT_URI Default URI used to generate URLs in a non-HTTP context # - WEBAPP_EMAIL_FROM Sender's email address to send emails from the web application # - WEBAPP_EMAIL_ALERTING_TO Email address for alert notifications (web application not working properly, ...) # - WEBAPP_NAME Name of web application displayed to users @@ -30,6 +31,7 @@ ####################################################################################################################### # - WEBAPP_USER_CONFIG_RESET_PASSWORD_TOKEN_LIFETIME Lifetime of reset password token in seconds (default: 1200 = 20 minutes). # - WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH Minimum user password length (default: 12) +# - WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY Public display of software version (default: true) ####################################################################################################################### # Environment @@ -106,4 +108,7 @@ WEBAPP_USER_CONFIG_PASSWORD_RESET_TOKEN_LIFETIME=1200 # Minimum user password length WEBAPP_USER_CONFIG_MIN_PASSWORD_LENGTH=12 +# Public display of software version (default: true) +WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY=true + ####################################################################################################################### diff --git a/webapp/.env.test b/webapp/.env.test index 96bb211a1ec1edc53d1782e77eb65d1aa11bace9..06c4e2b0f4632e4034fd844bc14a2702bfb68591 100644 --- a/webapp/.env.test +++ b/webapp/.env.test @@ -18,3 +18,16 @@ WEBAPP_I18N_DEFAULT_LOCALE='en' ####################################################################### MAILER_DSN=null://null ####################################################################### + + + +####################################################################################################################### +####################################################################################################################### + +# We strongly recommend leaving the following environment variables unchanged +# We strongly recommend leaving the following environment variables unchanged +SOFTWARE_NAME='Comptoir-TEST-Software' + ################################################################################################## + # Do not modify if you have not identified + # the technical implications: HTTP headers using this value, ... + ################################################################################################## diff --git a/webapp/config/packages/twig.yaml b/webapp/config/packages/twig.yaml index d2037706e35f940b181a8e11568e4844b4a7935a..c590937a737aa83f8c50404fa64dcb708b790754 100644 --- a/webapp/config/packages/twig.yaml +++ b/webapp/config/packages/twig.yaml @@ -2,6 +2,10 @@ twig: file_name_pattern: '*.twig' globals: app_name: '%env(WEBAPP_NAME)%' + app_shortname: '%env(WEBAPP_SHORTNAME)%' + software_name: '%env(SOFTWARE_NAME)%' + software_release: '%env(SOFTWARE_RELEASE)%' + software_release_allow_public_display: '%env(bool:WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY)%' when@test: twig: diff --git a/webapp/config/services.yaml b/webapp/config/services.yaml index 15e886a459e1c22a311057da70e455054ca1b2ac..c7d3e9f2a3a7dbf0d7b5653368074d1ddfe7f9a6 100644 --- a/webapp/config/services.yaml +++ b/webapp/config/services.yaml @@ -10,7 +10,10 @@ parameters: app.shortname: '%env(WEBAPP_SHORTNAME)%' app.email.alerting_to: '%env(WEBAPP_EMAIL_ALERTING_TO)%' app.email.from: '%env(WEBAPP_EMAIL_FROM)%' - app.software.name: 'Comptoir' + app.software.name: '%env(SOFTWARE_NAME)%' + app.software.release: '%env(SOFTWARE_RELEASE)%' + app.software.release.display.public: '%env(bool:WEBAPP_SOFTWARE_VERSION_DISPLAYED_PUBLICLY)%' + services: # default configuration for services in *this* file _defaults: diff --git a/webapp/src/Controller/HealthCheckController.php b/webapp/src/Controller/HealthCheckController.php index d095ec536e0b603c3667b567d11ea26bb874b1a6..d6b3449bc05c77df1ec607f1e3cc9cb13fe85f4a 100644 --- a/webapp/src/Controller/HealthCheckController.php +++ b/webapp/src/Controller/HealthCheckController.php @@ -37,7 +37,10 @@ class HealthCheckController extends AbstractController )] public function healthCheck(Request $request, Connection $dbConnection): Response { + $displayRelease = $this->getParameter('app.software.release.display.public'); + $softwareRelease = $this->getParameter('app.software.release'); $softwareName = $this->getParameter('app.software.name'); + $httpCode = Response::HTTP_OK; $dbStatusCode = "SUCCESSFUL"; try { @@ -47,10 +50,13 @@ public function healthCheck(Request $request, Connection $dbConnection): Respons $dbStatusCode = "FAILED"; } - $slugSoftwareName = strtolower((new AsciiSlugger())->slug("$softwareName")->toString()) ; - $headers = [ - "x-$slugSoftwareName-database-status" => "DB_CONNECTION_$dbStatusCode", - ]; + $slugSoftwareName = strtolower((new AsciiSlugger())->slug("$softwareName")->toString()); + $headers = []; + $headers["x-$slugSoftwareName-database-status"] = "DB_CONNECTION_$dbStatusCode"; + if($displayRelease === true){ + $headers["x-$slugSoftwareName-version"] = $softwareRelease; + } + if ($request->getMethod() === "HEAD") { return new Response(status: $httpCode, headers: $headers); } else { diff --git a/webapp/templates/healthcheck.html.twig b/webapp/templates/healthcheck.html.twig index 2169c4796b17bc247e8b452c254b2249604efeb2..e9c9b3869a86cb8093597bc1e4c1be000a0baef8 100644 --- a/webapp/templates/healthcheck.html.twig +++ b/webapp/templates/healthcheck.html.twig @@ -5,6 +5,7 @@ {% block body %} + {% set db_status_cssClass = 'table-danger' %} {% set db_status_i18n = 'public.health-check.status.failed'|trans %} {% if dbStatusCode == 'SUCCESSFUL' %} @@ -34,4 +35,11 @@ </table> </div> + + <hr> + + {% if software_release_allow_public_display == true %} + {{ software_name }} <strong>{{ software_release }} </strong> + {% endif %} + {% endblock %}