Skip to content

Commit 13d2b44

Browse files
Updating Dotenv::getConfig to enable Shield by default. Updating readme & change log.
1 parent 31d7786 commit 13d2b44

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
44

55
## [Unreleased][unreleased]
66

7+
## [0.1.12] - 2022-01-20
8+
9+
### Changed
10+
11+
- Updating Dotenv::getConfig to enable Shield by default.
12+
713
## [0.1.11] - 2022-01-07
814

915
### Changed
16+
1017
- Updating Dotenv::getConfig to support environments with full "production" name.
1118
- Updating Dotenv::getDatabaseName to provide helpful output in Drush context for multi-site config with dis-allowed default site.
1219

@@ -87,8 +94,9 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
8794

8895
**Initial release!**
8996

90-
[unreleased]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.11...main
91-
[0.1.11]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.9...0.1.11
97+
[unreleased]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.12...main
98+
[0.1.12]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.11...0.1.12
99+
[0.1.11]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.10...0.1.11
92100
[0.1.10]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.9...0.1.10
93101
[0.1.9]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.8...0.1.9
94102
[0.1.8]: https://github.com/unleashedtech/dotenv-drupal/compare/0.1.7...0.1.8

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ configuration.
113113
* [FILE_TEMP_PATH](#file_temp_path)
114114
* [CONFIG_SYNC_PATH](#config_sync_path)
115115
* [DOMAINS](#domains)
116+
* [SHIELD](#shield)
117+
* [SHIELD_USERNAME](#shield_username)
118+
* [SHIELD_PASSWORD](#shield_password)
119+
* [SHIELD_MESSAGE](#shield_message)
116120
* [SITES](#sites)
117121
* [SOLR_URL](#solr_url)
118122
* More configuration options coming soon!
@@ -173,6 +177,18 @@ A CSV list of domains used by the given environment:
173177
DOMAINS=foo.example,bar.example,baz.example
174178
```
175179

180+
#### SHIELD
181+
A boolean allowing the enabling/disabling of Shield module auth functionality.
182+
183+
##### SHIELD_USERNAME
184+
The username for Shield to require if enabled.
185+
186+
##### SHIELD_PASSWORD
187+
The password for Shield to require if enabled.
188+
189+
##### SHIELD_MESSAGE
190+
The _public_ message Shield should show in the auth prompt if enabled.
191+
176192
#### SITES
177193
A CSV list of Drupal "sites" (e.g. "subdomains") used by the given environment:
178194

src/Dotenv.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,16 @@ private function alter(&$data, $type): void
112112
public function getConfig(): array
113113
{
114114
$config = [];
115-
if (isset($_SERVER['SOLR_URL'])) {
116-
$parts = parse_url($_SERVER['SOLR_URL']);
117-
$name = $parts['fragment'] ?? 'default';
118-
$config['search_api.server.' . $name]['backend_config']['connector_config'] = [
119-
'scheme' => $parts['scheme'] ?? 'http',
120-
'host' => $parts['host'] ?? 'localhost',
121-
'port' => $parts['port'] ?? 8983,
122-
'path' => $parts['path'] ?? '/',
123-
'core' => $parts['user'] ?? 'default',
124-
];
115+
116+
// Default to having shield enabled.
117+
if (isset($_SERVER['SHIELD'])) {
118+
$config['shield.settings']['shield_enable'] = (bool) $_SERVER['SHIELD'];
125119
}
120+
121+
// Apply configuration based on environment name.
126122
switch ($this->getEnvironmentName()) {
127123
case 'dev':
124+
$config['shield.settings']['shield_enable'] = FALSE;
128125
$config['config_split.config_split.local']['status'] = TRUE;
129126
$config['environment_indicator.indicator'] = [
130127
'name' => 'Development',
@@ -159,6 +156,33 @@ public function getConfig(): array
159156
];
160157
break;
161158
}
159+
160+
// Configure Shield if enabled.
161+
if ($config['shield.settings']['shield_enable']) {
162+
if (isset($_SERVER['SHIELD_USER'])) {
163+
$config['shield.settings']['credentials']['shield']['user'] = $_SERVER['SHIELD_USER'];
164+
}
165+
if (isset($_SERVER['SHIELD_PASSWORD'])) {
166+
$config['shield.settings']['credentials']['shield']['pass'] = $_SERVER['SHIELD_PASSWORD'];
167+
}
168+
if (isset($_SERVER['SHIELD_MESSAGE'])) {
169+
$config['shield.settings']['print'] = $_SERVER['SHIELD_MESSAGE'];
170+
}
171+
}
172+
173+
// Configure Solr.
174+
if (isset($_SERVER['SOLR_URL'])) {
175+
$parts = parse_url($_SERVER['SOLR_URL']);
176+
$name = $parts['fragment'] ?? 'default';
177+
$config['search_api.server.' . $name]['backend_config']['connector_config'] = [
178+
'scheme' => $parts['scheme'] ?? 'http',
179+
'host' => $parts['host'] ?? 'localhost',
180+
'port' => $parts['port'] ?? 8983,
181+
'path' => $parts['path'] ?? '/',
182+
'core' => $parts['user'] ?? 'default',
183+
];
184+
}
185+
162186
$this->alter($config, 'config');
163187
return $config;
164188
}

0 commit comments

Comments
 (0)