Skip to content

Commit 0aa0031

Browse files
authored
Merge pull request #1002 from magento-falcons/MAGETWO-67099
- MAGETWO-66322 Dump env-specific and sensitive variables to env config file - MAGETWO-64317 POST request to /setup/index.php/session/prolong returns successful json - MAGETWO-66969 PreparedValueFactory issues
2 parents 59e8864 + 6fe803b commit 0aa0031

File tree

18 files changed

+700
-306
lines changed

18 files changed

+700
-306
lines changed

app/code/Magento/Config/App/Config/Source/DumpConfigSourceAggregated.php

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
class DumpConfigSourceAggregated implements DumpConfigSourceInterface
1818
{
1919
/**
20-
* @var ExcludeList
20+
* Rule name for include configuration data.
2121
*/
22-
private $excludeList;
22+
const RULE_TYPE_INCLUDE = 'include';
23+
24+
/**
25+
* Rule name for exclude configuration data.
26+
*/
27+
const RULE_TYPE_EXCLUDE = 'exclude';
2328

2429
/**
2530
* Checker for config type.
@@ -44,15 +49,49 @@ class DumpConfigSourceAggregated implements DumpConfigSourceInterface
4449
private $data;
4550

4651
/**
47-
* @param ExcludeList $excludeList
52+
* Array of rules for filtration the configuration data.
53+
*
54+
* For example:
55+
* ```php
56+
* [
57+
* 'default' => 'include',
58+
* 'sensitive' => 'exclude',
59+
* 'environment' => 'exclude',
60+
* ]
61+
* ```
62+
* It means that all aggregated configuration data will be included in result but configurations
63+
* that relates to 'sensitive' or 'environment' will be excluded.
64+
*
65+
*
66+
* ```php
67+
* [
68+
* 'default' => 'exclude',
69+
* 'sensitive' => 'include',
70+
* 'environment' => 'include',
71+
* ]
72+
* ```
73+
* It means that result will contains only 'sensitive' and 'environment' configurations.
74+
*
75+
* @var array
76+
*/
77+
private $rules;
78+
79+
/**
80+
* @param ExcludeList $excludeList Is not used anymore as it was deprecated, use TypePool instead.
4881
* @param array $sources
4982
* @param TypePool|null $typePool
83+
* @param array $rules Rules for filtration the configuration data.
84+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5085
*/
51-
public function __construct(ExcludeList $excludeList, array $sources = [], TypePool $typePool = null)
52-
{
53-
$this->excludeList = $excludeList;
86+
public function __construct(
87+
ExcludeList $excludeList,
88+
array $sources = [],
89+
TypePool $typePool = null,
90+
array $rules = []
91+
) {
5492
$this->sources = $sources;
5593
$this->typePool = $typePool ?: ObjectManager::getInstance()->get(TypePool::class);
94+
$this->rules = $rules;
5695
}
5796

5897
/**
@@ -97,30 +136,45 @@ private function filterChain($path, &$data)
97136
$newPath = $path ? $path . '/' . $subKey : $subKey;
98137
$filteredPath = $this->filterPath($newPath);
99138

100-
if ($filteredPath
101-
&& !is_array($data[$subKey])
102-
&& $this->isExcludePath($filteredPath)
103-
) {
139+
if (is_array($subData)) {
140+
$this->filterChain($newPath, $subData);
141+
} elseif ($this->isExcludedPath($filteredPath)) {
104142
$this->excludedFields[$newPath] = $filteredPath;
143+
unset($data[$subKey]);
144+
}
105145

146+
if (empty($subData) && isset($data[$subKey]) && is_array($data[$subKey])) {
106147
unset($data[$subKey]);
107-
} elseif (is_array($subData)) {
108-
$this->filterChain($newPath, $subData);
109148
}
110149
}
111150
}
112151

113152
/**
114-
* Checks if the configuration field belongs to a sensitive type.
153+
* Checks if the configuration field needs to be excluded.
115154
*
116155
* @param string $path Configuration field path. For example 'contact/email/recipient_email'
117-
* @return boolean
156+
* @return boolean Return true if path should be excluded
118157
*/
119-
private function isExcludePath($path)
158+
private function isExcludedPath($path)
120159
{
121-
return $this->excludeList->isPresent($path)
122-
|| $this->typePool->isPresent($path, TypePool::TYPE_ENVIRONMENT)
123-
|| $this->typePool->isPresent($path, TypePool::TYPE_SENSITIVE);
160+
if (empty($path)) {
161+
return false;
162+
}
163+
164+
$defaultRule = isset($this->rules['default']) ?
165+
$this->rules['default'] : self::RULE_TYPE_INCLUDE;
166+
167+
foreach ($this->rules as $type => $rule) {
168+
if ($type === 'default') {
169+
continue;
170+
}
171+
172+
if ($this->typePool->isPresent($path, $type)) {
173+
return $rule === self::RULE_TYPE_EXCLUDE;
174+
}
175+
}
176+
177+
return $defaultRule === self::RULE_TYPE_EXCLUDE;
124178
}
125179

126180
/**

app/code/Magento/Config/Model/Config/Export/Comment.php

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,19 @@ class Comment implements CommentInterface
3434
*/
3535
private $typePool;
3636

37-
/**
38-
* Contains list of config fields which should be excluded from config export file.
39-
*
40-
* @var ExcludeList
41-
*/
42-
private $excludeList;
43-
4437
/**
4538
* @param PlaceholderFactory $placeholderFactory
4639
* @param DumpConfigSourceInterface $source
47-
* @param TypePool|null $typePool
48-
* @param ExcludeList|null $excludeList
40+
* @param TypePool|null $typePool The checker for config type
4941
*/
5042
public function __construct(
5143
PlaceholderFactory $placeholderFactory,
5244
DumpConfigSourceInterface $source,
53-
TypePool $typePool = null,
54-
ExcludeList $excludeList = null
45+
TypePool $typePool = null
5546
) {
5647
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
5748
$this->source = $source;
5849
$this->typePool = $typePool ?: ObjectManager::getInstance()->get(TypePool::class);
59-
$this->excludeList = $excludeList ?: ObjectManager::getInstance()->get(ExcludeList::class);
6050
}
6151

6252
/**
@@ -69,30 +59,22 @@ public function __construct(
6959
*/
7060
public function get()
7161
{
72-
$comment = '';
73-
$fields = $this->source->getExcludedFields();
74-
foreach ($fields as $path) {
75-
if ($this->isSensitive($path)) {
76-
$comment .= "\n" . $this->placeholder->generate($path) . ' for ' . $path;
62+
$comments = [];
63+
64+
foreach ($this->source->getExcludedFields() as $path) {
65+
if ($this->typePool->isPresent($path, TypePool::TYPE_SENSITIVE)) {
66+
$comments[] = $this->placeholder->generate($path) . ' for ' . $path;
7767
}
7868
}
79-
if ($comment) {
80-
$comment = 'The configuration file doesn\'t contain sensitive data for security reasons. '
81-
. 'Sensitive data can be stored in the following environment variables:'
82-
. $comment;
69+
70+
if (!empty($comments)) {
71+
$comments = array_merge([
72+
'Shared configuration was written to config.php and system-specific configuration to env.php.',
73+
'Shared configuration file (config.php) doesn\'t contain sensitive data for security reasons.',
74+
'Sensitive data can be stored in the following environment variables:'
75+
], $comments);
8376
}
84-
return $comment;
85-
}
8677

87-
/**
88-
* Checks whether the field path is sensitive.
89-
*
90-
* @param string $path Configuration field path
91-
* @return bool
92-
*/
93-
private function isSensitive($path)
94-
{
95-
return $this->typePool->isPresent($path, TypePool::TYPE_SENSITIVE)
96-
|| $this->excludeList->isPresent($path);
78+
return implode(PHP_EOL, $comments);
9779
}
9880
}

app/code/Magento/Config/Model/Config/Parser/Comment.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function __construct(
5555
* //...
5656
* ],
5757
* // ...
58-
* // The configuration file doesn't contain sensitive data for security reasons.
5958
* // Sensitive data can be stored in the following environment variables:
6059
* // CONFIG__DEFAULT__SOME__CONF__PATH_ONE for some/conf/path_one
6160
* 'system' => [],

app/code/Magento/Config/Model/Config/TypePool.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Config\Model\Config;
77

8+
use Magento\Config\Model\Config\Export\ExcludeList;
9+
810
/**
911
* Checker for config type.
1012
*
@@ -44,19 +46,38 @@ class TypePool
4446
*/
4547
private $filteredPaths;
4648

49+
/**
50+
* Checks if the configuration path is contained in exclude list.
51+
*
52+
* @var ExcludeList
53+
* @deprecated We use it only to support backward compatibility. If some configurations
54+
* were set to this list before, we need to read them.
55+
* It will be supported for next 2 minor releases or until a major release.
56+
* TypePool should be used to mark configurations with types.
57+
* @see TypePool
58+
*/
59+
private $excludeList;
60+
4761
/**
4862
* @param array $sensitive List of sensitive configuration fields paths
4963
* @param array $environment List of environment configuration fields paths
64+
* @param ExcludeList $excludeList Checks if the configuration path is contained in exclude list
5065
*/
51-
public function __construct(array $sensitive = [], array $environment = [])
66+
public function __construct(array $sensitive = [], array $environment = [], ExcludeList $excludeList = null)
5267
{
5368
$this->sensitive = $sensitive;
5469
$this->environment = $environment;
70+
$this->excludeList = $excludeList;
5571
}
5672

5773
/**
5874
* Verifies that the configuration field path belongs to the specified type.
5975
*
76+
* For sensitive type, if configuration path was not found in the sensitive type pool
77+
* checks if this configuration path present in ExcludeList. It used only to support backward compatibility.
78+
* If some configurations were set to ExcludeList before, we need to read them.
79+
* It will be supported for next 2 minor releases or until a major release.
80+
*
6081
* @param string $path Configuration field path. For example, 'contact/email/recipient_email'
6182
* @param string $type Type of configuration fields
6283
* @return bool True when the path belongs to requested type, false otherwise
@@ -67,7 +88,16 @@ public function isPresent($path, $type)
6788
$this->filteredPaths[$type] = $this->getPathsByType($type);
6889
}
6990

70-
return in_array($path, $this->filteredPaths[$type]);
91+
$isPresent = in_array($path, $this->filteredPaths[$type]);
92+
93+
if ($type == self::TYPE_SENSITIVE
94+
&& !$isPresent
95+
&& $this->excludeList instanceof ExcludeList
96+
) {
97+
$isPresent = $this->excludeList->isPresent($path);
98+
}
99+
100+
return $isPresent;
71101
}
72102

73103
/**
@@ -78,10 +108,8 @@ public function isPresent($path, $type)
78108
* For example, if you pass a sensitive or TypePool::TYPE_SENSITIVE type, we get an array:
79109
* ```php
80110
* array(
81-
* 'some/path/sensetive/path1'
82-
* 'some/path/sensetive/path2'
83-
* 'some/path/sensetive/path3'
84-
* 'some/path/sensetive/path4'
111+
* 'some/path/sensitive/path1',
112+
* 'some/path/sensitive/path2'
85113
* );
86114
* ```
87115
*

0 commit comments

Comments
 (0)