Skip to content

Commit

Permalink
Add protected properties
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Nov 11, 2021
1 parent b177912 commit f76285a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ This will print all host configuration for the host `staging`.
- source.factorial.io:2222
```
They can be overridden on a per host-basis.
* `protectedProperties` a list of properties which wont be affected by a override.yaml file. See [local overrides](local-overrides.md)

### Configuration for the local-method

Expand Down
10 changes: 10 additions & 0 deletions docs/local-overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ dockerNetRcFile: /home/user/.netrc
Another possibility is to place a socalled override file side by side to the original ymal-file. Name it the same as the original file, and add `.override` before the file extension, e.g. `fabfile.yml` becomes `fabfile.override.yml`.
The data of the override will be merged with the data of the original file. No inheritance or other advanced features are supported.
## Prevent overriding of certain values
3.7.1 supports a new property on the root level of the fabfile called `protectedProperties`. These properties will be prevented for being overridden:
```yaml
protectedOverrides:
- dockerHosts.mbb.environment
```
If your override-file wants to override `dockerHosts > mbb > environment` phab will prevent this and restore the original value as in the fabfile.
24 changes: 21 additions & 3 deletions src/Configuration/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,27 @@ public function getFabfileLocation()
return $this->fabfileLocation;
}

public function mergeData(array $data, array $override_data): array
{
return Utilities::mergeData($data, $override_data);
public function mergeData(
array $data,
array $override_data,
$protected_properties_key = 'protectedProperties'
): array {
$properties_to_restore = [];
if ($protected_properties = $data[$protected_properties_key] ?? false) {
if (!is_array($protected_properties)) {
$protected_properties = [ $protected_properties ];
}
foreach ($protected_properties as $prop) {
$properties_to_restore[$prop] = Utilities::getProperty($data, $prop);
}
}

$data = Utilities::mergeData($data, $override_data);

foreach ($properties_to_restore as $prop => $value) {
Utilities::setProperty($data, $prop, $value);
}
return $data;
}

private function applyDefaults(array $data, array $defaults, array $disallowed_keys = []): array
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Utilities
{

const FALLBACK_VERSION = '3.7.0';
const FALLBACK_VERSION = '3.7.1';
const COMBINED_ARGUMENTS = 'combined';
const UNNAMED_ARGUMENTS = 'unnamedArguments';

Expand Down

0 comments on commit f76285a

Please sign in to comment.