From 13d2b44691987c086e534edf0fd09cd58fd2fb03 Mon Sep 17 00:00:00 2001 From: Daniel Love Date: Thu, 20 Jan 2022 15:29:20 -0700 Subject: [PATCH] Updating Dotenv::getConfig to enable Shield by default. Updating readme & change log. --- CHANGELOG.md | 12 ++++++++++-- README.md | 16 ++++++++++++++++ src/Dotenv.php | 44 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3723a17..2a2fbbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,16 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi ## [Unreleased][unreleased] +## [0.1.12] - 2022-01-20 + +### Changed + +- Updating Dotenv::getConfig to enable Shield by default. + ## [0.1.11] - 2022-01-07 ### Changed + - Updating Dotenv::getConfig to support environments with full "production" name. - Updating Dotenv::getDatabaseName to provide helpful output in Drush context for multi-site config with dis-allowed default site. @@ -87,8 +94,9 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi **Initial release!** -[unreleased]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.11...main -[0.1.11]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.9...0.1.11 +[unreleased]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.12...main +[0.1.12]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.11...0.1.12 +[0.1.11]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.10...0.1.11 [0.1.10]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.9...0.1.10 [0.1.9]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.8...0.1.9 [0.1.8]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.7...0.1.8 diff --git a/README.md b/README.md index a844de3..7e63504 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,10 @@ configuration. * [FILE_TEMP_PATH](#file_temp_path) * [CONFIG_SYNC_PATH](#config_sync_path) * [DOMAINS](#domains) +* [SHIELD](#shield) +* [SHIELD_USERNAME](#shield_username) +* [SHIELD_PASSWORD](#shield_password) +* [SHIELD_MESSAGE](#shield_message) * [SITES](#sites) * [SOLR_URL](#solr_url) * More configuration options coming soon! @@ -173,6 +177,18 @@ A CSV list of domains used by the given environment: DOMAINS=foo.example,bar.example,baz.example ``` +#### SHIELD +A boolean allowing the enabling/disabling of Shield module auth functionality. + +##### SHIELD_USERNAME +The username for Shield to require if enabled. + +##### SHIELD_PASSWORD +The password for Shield to require if enabled. + +##### SHIELD_MESSAGE +The _public_ message Shield should show in the auth prompt if enabled. + #### SITES A CSV list of Drupal "sites" (e.g. "subdomains") used by the given environment: diff --git a/src/Dotenv.php b/src/Dotenv.php index 0c04717..ccdec8c 100644 --- a/src/Dotenv.php +++ b/src/Dotenv.php @@ -112,19 +112,16 @@ private function alter(&$data, $type): void public function getConfig(): array { $config = []; - if (isset($_SERVER['SOLR_URL'])) { - $parts = parse_url($_SERVER['SOLR_URL']); - $name = $parts['fragment'] ?? 'default'; - $config['search_api.server.' . $name]['backend_config']['connector_config'] = [ - 'scheme' => $parts['scheme'] ?? 'http', - 'host' => $parts['host'] ?? 'localhost', - 'port' => $parts['port'] ?? 8983, - 'path' => $parts['path'] ?? '/', - 'core' => $parts['user'] ?? 'default', - ]; + + // Default to having shield enabled. + if (isset($_SERVER['SHIELD'])) { + $config['shield.settings']['shield_enable'] = (bool) $_SERVER['SHIELD']; } + + // Apply configuration based on environment name. switch ($this->getEnvironmentName()) { case 'dev': + $config['shield.settings']['shield_enable'] = FALSE; $config['config_split.config_split.local']['status'] = TRUE; $config['environment_indicator.indicator'] = [ 'name' => 'Development', @@ -159,6 +156,33 @@ public function getConfig(): array ]; break; } + + // Configure Shield if enabled. + if ($config['shield.settings']['shield_enable']) { + if (isset($_SERVER['SHIELD_USER'])) { + $config['shield.settings']['credentials']['shield']['user'] = $_SERVER['SHIELD_USER']; + } + if (isset($_SERVER['SHIELD_PASSWORD'])) { + $config['shield.settings']['credentials']['shield']['pass'] = $_SERVER['SHIELD_PASSWORD']; + } + if (isset($_SERVER['SHIELD_MESSAGE'])) { + $config['shield.settings']['print'] = $_SERVER['SHIELD_MESSAGE']; + } + } + + // Configure Solr. + if (isset($_SERVER['SOLR_URL'])) { + $parts = parse_url($_SERVER['SOLR_URL']); + $name = $parts['fragment'] ?? 'default'; + $config['search_api.server.' . $name]['backend_config']['connector_config'] = [ + 'scheme' => $parts['scheme'] ?? 'http', + 'host' => $parts['host'] ?? 'localhost', + 'port' => $parts['port'] ?? 8983, + 'path' => $parts['path'] ?? '/', + 'core' => $parts['user'] ?? 'default', + ]; + } + $this->alter($config, 'config'); return $config; }