Skip to content

Commit

Permalink
Updating Dotenv::getConfig to enable Shield by default. Updating read…
Browse files Browse the repository at this point in the history
…me & change log.
  • Loading branch information
dl-unleashed-technologies committed Jan 20, 2022
1 parent 31d7786 commit 13d2b44
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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:

Expand Down
44 changes: 34 additions & 10 deletions src/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 13d2b44

Please sign in to comment.