From 3df9034547267fa60549e73969f4798c966130ad Mon Sep 17 00:00:00 2001 From: stakovicz Date: Sat, 10 Feb 2024 18:04:22 +0100 Subject: [PATCH] afup#1442 parameters from env vars --- .env-dist | 3 - .env.dist | 70 +++++++++++++++++++++++ .github/workflows/ci.yml | 3 - .gitignore | 1 - Makefile | 7 +-- README.md | 26 +++------ app/config/config.php | 22 +++++++ app/config/config.yml | 3 +- app/config/parameters.yml.dist | 82 --------------------------- app/config/parameters.yml.dist-docker | 82 --------------------------- compose.yml | 10 ++++ planete/app/config/config.yml | 2 +- sources/Afup/Utils/Configuration.php | 37 +++++------- 13 files changed, 129 insertions(+), 219 deletions(-) delete mode 100644 .env-dist create mode 100644 .env.dist create mode 100644 app/config/config.php delete mode 100644 app/config/parameters.yml.dist delete mode 100644 app/config/parameters.yml.dist-docker diff --git a/.env-dist b/.env-dist deleted file mode 100644 index bfeed96f3..000000000 --- a/.env-dist +++ /dev/null @@ -1,3 +0,0 @@ -## Options to pass to `docker compose up` command -#DOCKER_UP_OPTIONS= -d # -d will launch container in detached mode -#ENABLE_XDEBUG=true # enable the PHP xDebug extension diff --git a/.env.dist b/.env.dist new file mode 100644 index 000000000..87a1ac566 --- /dev/null +++ b/.env.dist @@ -0,0 +1,70 @@ +## Options to pass to `docker compose up` command +#DOCKER_UP_OPTIONS= -d # -d will launch container in detached mode +#ENABLE_XDEBUG=true # enable the PHP xDebug extension + +## App configuration +DATABASE_HOST=db +DATABASE_PORT=3306 +DATABASE_NAME=web +DATABASE_USER=afup +DATABASE_PASSWORD=afup + +SECRET=ThisTokenIsNotSoSecretChangeIt + +GITHUB_CLIENT_ID=id +GITHUB_CLIENT_SECRET=secret + +ALGOLIA_APP_ID=DVB92YWTPE +ALGOLIA_BACKEND_API_KEY=78e71e5r5c2Rb353f5a03376gb9878779 +ALGOLIA_FRONTEND_API_KEY=74e71e5r5c2Rb353f5a03376gb9878777 + +HOME_ALGOLIA_ENABLED=false + +SLACK_URL=http://yolo + +TWITTER_OAUTH_ACCESS_TOKEN= +TWITTER_OAUTH_ACCESS_TOKEN_SECRET= +TWITTER_CONSUMER_KEY= +TWITTER_CONSUMER_SECRET= + +MAILCHIMP_API_KEY= +MAILCHIMP_MEMBERS_LIST= +MAILCHIMP_SUBSCRIBERS_LIST= +MAILCHIMP_TECHLETTER_LIST= +MAILCHIMP_TECHLETTER_API_KEY= +MAILCHIMP_TECHLETTER_WEBHOOK_KEY="abc" + +TRELLO_API_KEY= +TRELLO_TOKEN= + +GOOGLE_MAPS_API_KEY= + +MEETUP_API_CONSUMER_KEY= +MEETUP_API_CONSUMER_SECRET= + +TECHNO_WATCH_CALENDAR_URL=https://docs.google.com/spreadsheets/d/2cUeAk86Ov7BLYyn0Ad9ge3ecbsdboeQH64wIU9a9Zzp/export?format=csv +TECHNO_WATCH_CALENDAR_KEY=9Yt0feebMyMrUWx + +SUPER_APERO_CSV_URL= + +GOOGLE_ANALYTICS_ENABLED=false +GOOGLE_ANALYTICS_ID=G-CHPWDR3C1M + +TECHLETTER_TEST_EMAIL_ADDRESS=pole-veille@afup.org + +SLACK_MEMBERS_LEGACY_TOKEN=aaaa-90909097 + +SLACK_API_URL=https://slack.com/api +SLACK_MEMBRE_TOKEN= + +RECAPTCHA_PUBLIC_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI +RECAPTCHA_PRIVATE_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe + +PAYBOX_DOMAIN_SERVER=preprod-tpeweb.paybox.com +PAYBOX_SECRET_KEY=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF +PAYBOX_SITE=1999888 +PAYBOX_RANG=32 +PAYBOX_IDENTIFIANT=110647233 + +BLOG_API_KEY=123456 + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 515643dda..60535e5e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,9 +63,6 @@ jobs: restore-keys: | ${{ runner.os }}-composer- - - name: Parameters file - run: make app/config/parameters.yml - - name: Composer install run: composer install --no-scripts diff --git a/.gitignore b/.gitignore index 10b62ea64..bcc91ac88 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,6 @@ js_dist # uploads /htdocs/uploads -/app/config/parameters.yml /build/ /phpunit.xml /var/* diff --git a/Makefile b/Makefile index 228a79804..5044816a3 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ var/logs/.docker-build: compose.yml compose.override.yml $(shell find docker -ty touch var/logs/.docker-build .env: - cp .env-dist .env + cp .env.dist .env compose.override.yml: cp compose.override.yml-dist compose.override.yml @@ -47,9 +47,6 @@ assets: watch: ./node_modules/.bin/webpack --progress --colors --watch -app/config/parameters.yml: - cp app/config/parameters.yml.dist-docker app/config/parameters.yml - init: make config make init-db @@ -59,7 +56,7 @@ init-db: CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --rm cliphp make db-migrations CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --rm cliphp make db-seed -config: app/config/parameters.yml +config: CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --no-deps --rm cliphp make vendors CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --no-deps --rm cliphp make assets diff --git a/README.md b/README.md index e5402c0a2..1bcbe419b 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Dans chacun des cas, il est possible de spécifier un test dans la ligne de comm # Paiements avec Paybox Il est possible de tester les paiements Paybox en environnement de développement. -Pour cela, les identifiant, site et rang [de test](https://www.paybox.com/espace-integrateur-documentation/comptes-de-tests/) sont déjà configurés dans le fichier parameters.yml par défaut. +Pour cela, les identifiant, site et rang [de test](https://www.paybox.com/espace-integrateur-documentation/comptes-de-tests/) sont déjà configurés dans le fichier .env par défaut. Ensuite pour le paiement il faut utiliser ces informations [de carte](https://www.paybox.com/espace-integrateur-documentation/cartes-de-tests/) (celle _"Carte participant au programme 3-D Secure (enrôlée)"_) : * Numéro de carte : `1111222233334444` @@ -116,17 +116,11 @@ Valider avec le bouton `Register application` Récupérer le `Client ID`et le `Client secret` -Mettre ces 2 informations dans le fichier -```yaml -# app/config/parameters.yml - -parameters: - - # ... - - # GitHub's connection details - github_client_id: - github_client_secret: +Mettre ces 2 informations dans le fichier .env +```dotenv +# .env +GITHUB_CLIENT_ID= +GITHUB_CLIENT_SECRET= ``` ## Connection Google Map Geocoding (pour les exports des Inscriptions) @@ -140,11 +134,9 @@ Créer un projet avec ces paramètres : Puis dans `Identifiants`, `Créer des identifiants`, récupérer la clé Mettre cette information dans le fichier -```yaml -# app/config/parameters.yml -parameters: - # ... - google_maps_api_key: +```dotenv +# .env +GOOGLE_MAPS_API_KEY= ``` Puis dans `API et services` activer l'API `Geocoding API`. diff --git a/app/config/config.php b/app/config/config.php new file mode 100644 index 000000000..95342eb6e --- /dev/null +++ b/app/config/config.php @@ -0,0 +1,22 @@ +setParameter($name, $value); +} diff --git a/app/config/config.yml b/app/config/config.yml index 2a6c7fe06..dbf8751d7 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -1,5 +1,5 @@ imports: - - { resource: parameters.yml } + - { resource: config.php } - { resource: security.yml } - { resource: services.yml } @@ -350,6 +350,7 @@ ting: charset: utf8mb4 master: host: "%database_host%" + # TODO FIX ME POURQUOI ????????? "%database_port%" ne fonctionne pas port: "%database_port%" user: "%database_user%" password: "%database_password%" diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist deleted file mode 100644 index 6dfe81695..000000000 --- a/app/config/parameters.yml.dist +++ /dev/null @@ -1,82 +0,0 @@ -# This file is a "template" of what your parameters.yml file should look like -# Set parameters here that may be different on each deployment target of the app, e.g. development, staging, production. -# http://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration -parameters: - database_host: 127.0.0.1 - database_port: 3306 - database_name: symfony - database_user: root - database_password: ~ - # You should uncomment this if you want use pdo_sqlite - # database_path: "%kernel.root_dir%/data.db3" - - # A secret key that's used to generate certain security-related tokens - secret: ThisTokenIsNotSoSecretChangeIt - - # GitHub's connection details - github_client_id: id - github_client_secret: secret - - algolia_app_id: DVB92YWTPE - algolia_backend_api_key: 78e71e5r5c2Rb353f5a03376gb9878779 - algolia_frontend_api_key: 74e71e5r5c2Rb353f5a03376gb9878777 - - home_algolia_enabled: false - - # Slack url for notifications - slack_url: 'http://yolo' - - twitter_oauth_access_token: "" - twitter_oauth_access_token_secret: "" - twitter_consumer_key: "" - twitter_consumer_secret: "" - - mailchimp_api_key: "" - mailchimp_members_list: - mailchimp_subscribers_list: - mailchimp_techletter_list: - mailchimp_techletter_api_key: - mailchimp_techletter_webhook_key: "abc" - - trello_api_key: "" - trello_token: "" - - google_maps_api_key: "" - - meetup_api_consumer_key: "" - meetup_api_consumer_secret: "" - - techno_watch_calendar_url: "https://docs.google.com/spreadsheets/d/2cUeAk86Ov7BLYyn0Ad9ge3ecbsdboeQH64wIU9a9Zzp/export?format=csv" - techno_watch_calendar_key: "9Yt0feebMyMrUWx" - - super_apero_csv_url: "" - - google_analytics_enabled: false - google_analytics_id: "G-CHPWDR3C1M" - - techletter_test_email_address: "pole-veille@afup.org" - - slack_members_legacy_token: "aaaa-90909097" - - slack_api_url: "https://slack.com/api" - slack_membre_token: "" - - # Test keys from https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha-what-should-i-do - recaptcha_public_key: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' - recaptcha_private_key: '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe' - - paybox_domain_server: "preprod-tpeweb.paybox.com" - paybox_secret_key: "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" - paybox_site: "1999888" - paybox_rang: "32" - paybox_identifiant: "110647233" - - blog_api_key: 123456 - - smtp_host: "mailcatcher" - smtp_tls: 0 - smtp_username: "" - smtp_password: "" - smtp_port: 1025 - mailer_force_recipients: [] - mailer_bcc: [] \ No newline at end of file diff --git a/app/config/parameters.yml.dist-docker b/app/config/parameters.yml.dist-docker deleted file mode 100644 index 3f832194c..000000000 --- a/app/config/parameters.yml.dist-docker +++ /dev/null @@ -1,82 +0,0 @@ -# This file is a "template" of what your parameters.yml file should look like -# Set parameters here that may be different on each deployment target of the app, e.g. development, staging, production. -# http://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration -parameters: - database_host: db - database_port: 3306 - database_name: web - database_user: afup - database_password: afup - # You should uncomment this if you want use pdo_sqlite - # database_path: "%kernel.root_dir%/data.db3" - - # A secret key that's used to generate certain security-related tokens - secret: ThisTokenIsNotSoSecretChangeIt - - # GitHub's connection details - github_client_id: id - github_client_secret: secret - - algolia_app_id: DVB92YWTPE - algolia_backend_api_key: 78e71e5r5c2Rb353f5a03376gb9878779 - algolia_frontend_api_key: 74e71e5r5c2Rb353f5a03376gb9878777 - - home_algolia_enabled: false - - # Slack url for notifications - slack_url: 'http://yolo' - - twitter_oauth_access_token: "" - twitter_oauth_access_token_secret: "" - twitter_consumer_key: "" - twitter_consumer_secret: "" - - mailchimp_api_key: "" - mailchimp_members_list: - mailchimp_subscribers_list: - mailchimp_techletter_list: - mailchimp_techletter_api_key: - mailchimp_techletter_webhook_key: "abc" - - trello_api_key: "" - trello_token: "" - - google_maps_api_key: "" - - meetup_api_consumer_key: "" - meetup_api_consumer_secret: "" - - techno_watch_calendar_url: "https://docs.google.com/spreadsheets/d/2cUeAk86Ov7BLYyn0Ad9ge3ecbsdboeQH64wIU9a9Zzp/export?format=csv" - techno_watch_calendar_key: "9Yt0feebMyMrUWx" - - super_apero_csv_url: "" - - google_analytics_enabled: false - google_analytics_id: "G-CHPWDR3C1M" - - techletter_test_email_address: "pole-veille@afup.org" - - slack_members_legacy_token: "aaaa-90909097" - - slack_api_url: "https://slack.com/api" - slack_membre_token: "" - - # Test keys from https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha-what-should-i-do - recaptcha_public_key: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' - recaptcha_private_key: '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe' - - paybox_domain_server: "preprod-tpeweb.paybox.com" - paybox_secret_key: "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" - paybox_site: "1999888" - paybox_rang: "32" - paybox_identifiant: "110647233" - - blog_api_key: 123456 - - smtp_host: "mailcatcher" - smtp_tls: 0 - smtp_username: "" - smtp_password: "" - smtp_port: 1025 - mailer_force_recipients: [] - mailer_bcc: [] \ No newline at end of file diff --git a/compose.yml b/compose.yml index ccbead964..f6e834c9e 100644 --- a/compose.yml +++ b/compose.yml @@ -34,6 +34,8 @@ services: ENABLE_XDEBUG: ${ENABLE_XDEBUG:-false} environment: SYMFONY_ENV: "dev" + env_file: + .env volumes: - ./:/var/www/html links: @@ -49,6 +51,8 @@ services: ENABLE_XDEBUG: ${ENABLE_XDEBUG:-false} environment: SYMFONY_ENV: "test" + env_file: + .env volumes: - ./:/var/www/html healthcheck: @@ -68,6 +72,8 @@ services: gid: "1001" environment: SYMFONY_ENV: "dev" + env_file: + .env volumes: - ./:/var/www/html links: @@ -83,6 +89,8 @@ services: ENABLE_XDEBUG: ${ENABLE_XDEBUG:-false} environment: SYMFONY_ENV: "test" + env_file: + .env volumes: - ./:/var/www/html healthcheck: @@ -100,6 +108,8 @@ services: args: uid: ${CURRENT_UID:-1001} gid: "1001" + env_file: + .env user: localUser volumes: - ./data/composer:/home/localUser/.composer diff --git a/planete/app/config/config.yml b/planete/app/config/config.yml index 35620f68b..f3e389dc1 100644 --- a/planete/app/config/config.yml +++ b/planete/app/config/config.yml @@ -1,5 +1,5 @@ imports: - - { resource: ../../../app/config/parameters.yml } + - { resource: ../../../app/config/config.php } - { resource: services.yml } parameters: diff --git a/sources/Afup/Utils/Configuration.php b/sources/Afup/Utils/Configuration.php index 048e7e460..972cd6c89 100644 --- a/sources/Afup/Utils/Configuration.php +++ b/sources/Afup/Utils/Configuration.php @@ -21,36 +21,25 @@ class Configuration */ public function __construct() { - $sfParameters = $this->loadSymfonyParameters(); - if ([] !== $sfParameters) { - $this->_valeurs['database_host'] = $sfParameters['database_host']; - $this->_valeurs['database_name'] = $sfParameters['database_name']; - $this->_valeurs['database_user'] = $sfParameters['database_user']; - $this->_valeurs['database_password'] = $sfParameters['database_password']; + $this->_valeurs['database_host'] = getenv('DATABASE_HOST'); + $this->_valeurs['database_name'] = getenv('DATABASE_NAME'); + $this->_valeurs['database_user'] = getenv('DATABASE_USER'); + $this->_valeurs['database_password'] = getenv('DATABASE_PASSWORD'); - $this->_valeurs['smtp_host'] = $sfParameters['smtp_host']; - $this->_valeurs['smtp_port'] = $sfParameters['smtp_port']; - $this->_valeurs['smtp_tls'] = $sfParameters['smtp_tls']; - $this->_valeurs['smtp_username'] = $sfParameters['smtp_username']; - $this->_valeurs['smtp_password'] = $sfParameters['smtp_password']; + $this->_valeurs['smtp_host'] = getenv('SMTP_HOST'); + $this->_valeurs['smtp_port'] = getenv('SMTP_PORT'); + $this->_valeurs['smtp_tls'] = getenv('SMTP_TLS'); + $this->_valeurs['smtp_username'] = getenv('SMTP_USERNAME'); + $this->_valeurs['smtp_password'] = getenv('SMTP_PASSWORD'); - $this->_valeurs['mailer_force_recipients'] = $sfParameters['mailer_force_recipients']; - $this->_valeurs['mailer_bcc'] = $sfParameters['mailer_bcc']; - } - } + $this->_valeurs['mailer_force_recipients'] = getenv('MAILER_FORCE_RECIPIENTS'); + $this->_valeurs['mailer_bcc'] = getenv('MAILER_BCC'); - private function loadSymfonyParameters(): array - { + // Écrase les paramètres définit dans les fichiers lié à l'environnement. $basePath = __DIR__ . '/../../../app/config'; - - $parameters = []; - $this->mergeSymfonyParametersFromFile($basePath . '/parameters.yml', $parameters); - $this->mergeSymfonyParametersFromFile($basePath . '/config.yml', $parameters); if (isset($_ENV['SYMFONY_ENV'])) { - $this->mergeSymfonyParametersFromFile($basePath . '/config_' . $_ENV['SYMFONY_ENV'] . '.yml', $parameters); + $this->mergeSymfonyParametersFromFile($basePath . '/config_' . $_ENV['SYMFONY_ENV'] . '.yml', $this->_valeurs); } - - return $parameters; } private function mergeSymfonyParametersFromFile($file, &$parameters)