Skip to content

Commit 929bc66

Browse files
author
Bohdan Korablov
committed
Merge remote-tracking branch 'falcons/MAGETWO-61515' into MAGETWO-66180
# Conflicts: # app/code/Magento/Config/etc/di.xml # app/code/Magento/Store/etc/di.xml
2 parents dae2ec5 + 90fc578 commit 929bc66

File tree

36 files changed

+912
-131
lines changed

36 files changed

+912
-131
lines changed

app/code/Magento/Authorizenet/etc/di.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,23 @@
2626
</argument>
2727
</arguments>
2828
</type>
29+
<type name="Magento\Config\Model\Config\TypePool">
30+
<arguments>
31+
<argument name="sensitive" xsi:type="array">
32+
<item name="payment/authorizenet_directpost/login" xsi:type="string">1</item>
33+
<item name="payment/authorizenet_directpost/trans_key" xsi:type="string">1</item>
34+
<item name="payment/authorizenet_directpost/trans_md5" xsi:type="string">1</item>
35+
<item name="payment/authorizenet_directpost/merchant_email" xsi:type="string">1</item>
36+
<item name="payment/authorizenet_directpost/cgi_url" xsi:type="string">1</item>
37+
<item name="payment/authorizenet_directpost/cgi_url_td" xsi:type="string">1</item>
38+
<item name="payment/authorizenet_directpost/email_customer" xsi:type="string">1</item>
39+
</argument>
40+
<argument name="environment" xsi:type="array">
41+
<item name="payment/authorizenet_directpost/cgi_url" xsi:type="string">1</item>
42+
<item name="payment/authorizenet_directpost/cgi_url_td" xsi:type="string">1</item>
43+
<item name="payment/authorizenet_directpost/debug" xsi:type="string">1</item>
44+
<item name="payment/authorizenet_directpost/test" xsi:type="string">1</item>
45+
</argument>
46+
</arguments>
47+
</type>
2948
</config>

app/code/Magento/Backend/etc/di.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@
194194
</argument>
195195
</arguments>
196196
</type>
197+
<type name="Magento\Config\Model\Config\TypePool">
198+
<arguments>
199+
<argument name="sensitive" xsi:type="array">
200+
<item name="admin/url/custom" xsi:type="string">1</item>
201+
<item name="admin/url/custom_path" xsi:type="string">1</item>
202+
<item name="trans_email/ident_custom1/email" xsi:type="string">1</item>
203+
<item name="trans_email/ident_custom1/name" xsi:type="string">1</item>
204+
<item name="trans_email/ident_custom2/email" xsi:type="string">1</item>
205+
<item name="trans_email/ident_custom2/name" xsi:type="string">1</item>
206+
<item name="trans_email/ident_general/email" xsi:type="string">1</item>
207+
<item name="trans_email/ident_general/name" xsi:type="string">1</item>
208+
<item name="trans_email/ident_sales/email" xsi:type="string">1</item>
209+
<item name="trans_email/ident_sales/name" xsi:type="string">1</item>
210+
<item name="trans_email/ident_support/email" xsi:type="string">1</item>
211+
<item name="trans_email/ident_support/name" xsi:type="string">1</item>
212+
</argument>
213+
</arguments>
214+
</type>
197215
<type name="Magento\Backend\Model\View\Layout\Filter">
198216
<arguments>
199217
<argument name="filters" xsi:type="array">

app/code/Magento/Braintree/etc/di.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,4 +556,20 @@
556556
</argument>
557557
</arguments>
558558
</type>
559+
<type name="Magento\Config\Model\Config\TypePool">
560+
<arguments>
561+
<argument name="sensitive" xsi:type="array">
562+
<item name="payment/braintree/merchant_id" xsi:type="string">1</item>
563+
<item name="payment/braintree/private_key" xsi:type="string">1</item>
564+
<item name="payment/braintree/merchant_account_id" xsi:type="string">1</item>
565+
<item name="payment/braintree/kount_id" xsi:type="string">1</item>
566+
<item name="payment/braintree_paypal/merchant_name_override" xsi:type="string">1</item>
567+
<item name="payment/braintree/descriptor_phone" xsi:type="string">1</item>
568+
<item name="payment/braintree/descriptor_url" xsi:type="string">1</item>
569+
</argument>
570+
<argument name="environment" xsi:type="array">
571+
<item name="payment/braintree/descriptor_url" xsi:type="string">1</item>
572+
</argument>
573+
</arguments>
574+
</type>
559575
</config>

app/code/Magento/Checkout/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@
4949
</argument>
5050
</arguments>
5151
</type>
52+
<type name="Magento\Config\Model\Config\TypePool">
53+
<arguments>
54+
<argument name="sensitive" xsi:type="array">
55+
<item name="checkout/payment_failed/copy_to" xsi:type="string">1</item>
56+
</argument>
57+
</arguments>
58+
</type>
5259
</config>

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
namespace Magento\Config\App\Config\Source;
77

8+
use Magento\Config\Model\Config\TypePool;
89
use Magento\Config\Model\Config\Export\ExcludeList;
910
use Magento\Framework\App\Config\ConfigSourceInterface;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\ObjectManager;
1113

1214
/**
1315
* Class DumpConfigSourceAggregated aggregates configurations from all available sources
@@ -19,6 +21,13 @@ class DumpConfigSourceAggregated implements DumpConfigSourceInterface
1921
*/
2022
private $excludeList;
2123

24+
/**
25+
* Checker for config type.
26+
*
27+
* @var TypePool
28+
*/
29+
private $typePool;
30+
2231
/**
2332
* @var ConfigSourceInterface[]
2433
*/
@@ -37,11 +46,13 @@ class DumpConfigSourceAggregated implements DumpConfigSourceInterface
3746
/**
3847
* @param ExcludeList $excludeList
3948
* @param array $sources
49+
* @param TypePool|null $typePool
4050
*/
41-
public function __construct(ExcludeList $excludeList, array $sources = [])
51+
public function __construct(ExcludeList $excludeList, array $sources = [], TypePool $typePool = null)
4252
{
4353
$this->excludeList = $excludeList;
4454
$this->sources = $sources;
55+
$this->typePool = $typePool ?: ObjectManager::getInstance()->get(TypePool::class);
4556
}
4657

4758
/**
@@ -88,7 +99,7 @@ private function filterChain($path, &$data)
8899

89100
if ($filteredPath
90101
&& !is_array($data[$subKey])
91-
&& $this->excludeList->isPresent($filteredPath)
102+
&& $this->isExcludePath($filteredPath)
92103
) {
93104
$this->excludedFields[$newPath] = $filteredPath;
94105

@@ -99,6 +110,19 @@ private function filterChain($path, &$data)
99110
}
100111
}
101112

113+
/**
114+
* Checks if the configuration field belongs to a sensitive type.
115+
*
116+
* @param string $path Configuration field path. For example 'contact/email/recipient_email'
117+
* @return boolean
118+
*/
119+
private function isExcludePath($path)
120+
{
121+
return $this->excludeList->isPresent($path)
122+
|| $this->typePool->isPresent($path, TypePool::TYPE_ENVIRONMENT)
123+
|| $this->typePool->isPresent($path, TypePool::TYPE_SENSITIVE);
124+
}
125+
102126
/**
103127
* Eliminating scope info from path
104128
*

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
namespace Magento\Config\Model\Config\Export;
77

88
use Magento\Config\App\Config\Source\DumpConfigSourceInterface;
9+
use Magento\Config\Model\Config\TypePool;
910
use Magento\Config\Model\Placeholder\PlaceholderFactory;
1011
use Magento\Config\Model\Placeholder\PlaceholderInterface;
1112
use Magento\Framework\App\Config\CommentInterface;
13+
use Magento\Framework\App\ObjectManager;
1214

1315
/**
1416
* Class Comment. Is used to retrieve comment for config dump file
@@ -25,20 +27,43 @@ class Comment implements CommentInterface
2527
*/
2628
private $source;
2729

30+
/**
31+
* Checker for config type.
32+
*
33+
* @var TypePool
34+
*/
35+
private $typePool;
36+
37+
/**
38+
* Contains list of config fields which should be excluded from config export file.
39+
*
40+
* @var ExcludeList
41+
*/
42+
private $excludeList;
43+
2844
/**
2945
* @param PlaceholderFactory $placeholderFactory
3046
* @param DumpConfigSourceInterface $source
47+
* @param TypePool|null $typePool
48+
* @param ExcludeList|null $excludeList
3149
*/
3250
public function __construct(
3351
PlaceholderFactory $placeholderFactory,
34-
DumpConfigSourceInterface $source
52+
DumpConfigSourceInterface $source,
53+
TypePool $typePool = null,
54+
ExcludeList $excludeList = null
3555
) {
3656
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
3757
$this->source = $source;
58+
$this->typePool = $typePool ?: ObjectManager::getInstance()->get(TypePool::class);
59+
$this->excludeList = $excludeList ?: ObjectManager::getInstance()->get(ExcludeList::class);
3860
}
3961

4062
/**
41-
* Retrieves comments for config export file.
63+
* Retrieves comments for the configuration export file.
64+
*
65+
* If there are sensitive fields in the configuration fields,
66+
* a list with descriptions of these fields will be added to the comments.
4267
*
4368
* @return string
4469
*/
@@ -47,7 +72,9 @@ public function get()
4772
$comment = '';
4873
$fields = $this->source->getExcludedFields();
4974
foreach ($fields as $path) {
50-
$comment .= "\n" . $this->placeholder->generate($path) . ' for ' . $path ;
75+
if ($this->isSensitive($path)) {
76+
$comment .= "\n" . $this->placeholder->generate($path) . ' for ' . $path;
77+
}
5178
}
5279
if ($comment) {
5380
$comment = 'The configuration file doesn\'t contain sensitive data for security reasons. '
@@ -56,4 +83,16 @@ public function get()
5683
}
5784
return $comment;
5885
}
86+
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);
97+
}
5998
}

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

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

8-
use Magento\Framework\App\Config\ScopeConfigInterface;
9-
108
/**
11-
* Class ExcludeList contains list of config fields which should be excluded from config export file
9+
* Class ExcludeList contains list of config fields which should be excluded from config export file.
10+
*
11+
* @deprecated because in Magento since version 2.2.0 there are several
12+
* types for configuration fields that require special processing.
13+
* @see \Magento\Config\Model\Config\TypePool
1214
*/
1315
class ExcludeList
1416
{
@@ -30,16 +32,18 @@ public function __construct(array $configs = [])
3032
*
3133
* @param string $path
3234
* @return bool
35+
* @deprecated
3336
*/
3437
public function isPresent($path)
3538
{
36-
return !empty($this->configs[$path]) ;
39+
return !empty($this->configs[$path]);
3740
}
3841

3942
/**
4043
* Retrieves all excluded field paths for export
4144
*
4245
* @return array
46+
* @deprecated
4347
*/
4448
public function get()
4549
{
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Model\Config;
7+
8+
/**
9+
* Checker for config type.
10+
*
11+
* Used when you need to know if the configuration path belongs to a certain type.
12+
* Participates in the mechanism for creating the configuration dump file.
13+
* There are several types:
14+
* - sensitive - the fields that have this type will not be written in the dump configuration;
15+
* - environment - the fields that have this type will not be written to the dump configuration.
16+
*/
17+
class TypePool
18+
{
19+
/**
20+
* Sensitive type.
21+
*/
22+
const TYPE_SENSITIVE = 'sensitive';
23+
24+
/**
25+
* Environment type.
26+
*/
27+
const TYPE_ENVIRONMENT = 'environment';
28+
29+
/**
30+
* List of sensitive configuration fields paths.
31+
*
32+
* @var array
33+
*/
34+
private $sensitive;
35+
36+
/**
37+
* List of environment configuration fields paths.
38+
*
39+
* @var array
40+
*/
41+
private $environment;
42+
43+
/**
44+
* Filtered configuration array
45+
*
46+
* @var array
47+
*/
48+
private $filteredPaths;
49+
50+
/**
51+
* @param array $sensitive List of sensitive configuration fields paths
52+
* @param array $environment List of environment configuration fields paths
53+
*/
54+
public function __construct(array $sensitive = [], array $environment = [])
55+
{
56+
$this->sensitive = $sensitive;
57+
$this->environment = $environment;
58+
}
59+
60+
/**
61+
* Verifies that the configuration field path belongs to the specified type.
62+
*
63+
* @param string $path Configuration field path. For example, 'contact/email/recipient_email'
64+
* @param string $type Type of configuration fields
65+
* @return bool True when the path belongs to requested type, false otherwise
66+
*/
67+
public function isPresent($path, $type)
68+
{
69+
if (!isset($this->filteredPaths[$type])) {
70+
$this->filteredPaths[$type] = $this->getPathsByType($type);
71+
}
72+
73+
return in_array($path, $this->filteredPaths[$type]);
74+
}
75+
76+
/**
77+
* Gets a list of configuration fields paths for the specified type.
78+
*
79+
* Returns an empty array if the passed type does not exist. If the type exists,
80+
* it returns a list of fields of a persistent type.
81+
* For example, if you pass a sensitive or TypePool::TYPE_SENSITIVE type, we get an array:
82+
* ```php
83+
* array(
84+
* 'some/path/sensetive/path1'
85+
* 'some/path/sensetive/path2'
86+
* 'some/path/sensetive/path3'
87+
* 'some/path/sensetive/path4'
88+
* );
89+
* ```
90+
*
91+
* @param string $type Type configuration fields paths. Allowed values of types:
92+
* - sensitive or TypePool::TYPE_SENSITIVE;
93+
* - environment or TypePool::TYPE_ENVIRONMENT.
94+
* @return array
95+
*/
96+
private function getPathsByType($type)
97+
{
98+
switch ($type) {
99+
case self::TYPE_SENSITIVE:
100+
$paths = $this->sensitive;
101+
break;
102+
case self::TYPE_ENVIRONMENT:
103+
$paths = $this->environment;
104+
break;
105+
default:
106+
return [];
107+
}
108+
109+
return array_keys(array_filter(
110+
$paths,
111+
function ($value) {
112+
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
113+
}
114+
));
115+
}
116+
}

0 commit comments

Comments
 (0)