Skip to content

Commit 7ac1826

Browse files
committed
MAGETWO-66322: Dump env-specific and sensitive variables to env config file
1 parent fe1b3bb commit 7ac1826

File tree

7 files changed

+47
-42
lines changed

7 files changed

+47
-42
lines changed

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,22 @@ public function __construct(
5959
*/
6060
public function get()
6161
{
62-
$comment = array_reduce($this->source->getExcludedFields(), function ($comment, $path) {
63-
if ($this->isCommendRequired($path)) {
64-
$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;
6567
}
66-
return $comment;
67-
});
68+
}
6869

69-
if ($comment) {
70-
$comment = 'The configuration file doesn\'t contain sensitive data for security reasons. '
71-
. 'Sensitive data can be stored in the following environment variables:'
72-
. $comment;
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);
7376
}
74-
return $comment;
75-
}
7677

77-
/**
78-
* Checks if comment required for given configuration path.
79-
*
80-
* @param string $path Configuration field path
81-
* @return bool
82-
*/
83-
private function isCommendRequired($path)
84-
{
85-
return $this->typePool->isPresent($path, TypePool::TYPE_SENSITIVE)
86-
&& !$this->typePool->isPresent($path, TypePool::TYPE_ENVIRONMENT);
78+
return implode(PHP_EOL, $comments);
8779
}
8880
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function __construct(
5555
* //...
5656
* ],
5757
* // ...
58-
* // The configuration file doesn't contain sensitive data for security reasons.
58+
* // Shared configuration was written to config.php and system-specific configuration to env.php.
59+
* // Shared configuration file (config.php) doesn't contain sensitive data for security reasons.
5960
* // Sensitive data can be stored in the following environment variables:
6061
* // CONFIG__DEFAULT__SOME__CONF__PATH_ONE for some/conf/path_one
6162
* 'system' => [],

app/code/Magento/Config/Test/Unit/Model/Config/Export/CommentTest.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,23 @@ public function dataProviderForTestGet()
148148
'expectedMessage' => ''
149149
],
150150
[
151-
'sensitive' => ['some/sensitive/field1', 'some/sensitive/field2', 'some/sensitiveAndEnv/field1'],
151+
'sensitive' => ['some/sensitive/field1', 'some/sensitive/field2', 'some/sensitive_and_env/field'],
152152
'notSensitive' => ['some/notSensitive/field1', 'some/notSensitive/field2'],
153153
'expectedMocks' => [
154154
'typePoolMock' => [
155155
'isPresent' => [
156-
'expects' => $this->exactly(8),
156+
'expects' => $this->exactly(5),
157157
'returnMap' => [
158158
['some/sensitive/field1', TypePool::TYPE_SENSITIVE, true],
159-
['some/sensitive/field1', TypePool::TYPE_ENVIRONMENT, false],
160159
['some/sensitive/field2', TypePool::TYPE_SENSITIVE, true],
161-
['some/sensitive/field2', TypePool::TYPE_ENVIRONMENT, false],
162-
['some/sensitiveAndEnv/field1', TypePool::TYPE_SENSITIVE, true],
163-
['some/sensitiveAndEnv/field1', TypePool::TYPE_ENVIRONMENT, true],
160+
['some/sensitive_and_env/field', TypePool::TYPE_SENSITIVE, true],
164161
['some/notSensitive/field1', TypePool::TYPE_SENSITIVE, false],
165-
['some/notSensitive/field2', TypePool::TYPE_SENSITIVE, false],
166162
]
167163
],
168164
],
169165
'placeholderMock' => [
170166
'generate' => [
171-
'expects' => $this->exactly(2),
167+
'expects' => $this->exactly(3),
172168
'returnMap' => [
173169
[
174170
'some/sensitive/field1',
@@ -182,14 +178,24 @@ public function dataProviderForTestGet()
182178
null,
183179
'CONFIG__SOME__SENSITIVE__FIELD2'
184180
],
181+
[
182+
'some/sensitive_and_env/field',
183+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
184+
null,
185+
'CONFIG__SOME__SENSITIVE_AND_ENV__FIELD'
186+
],
185187
],
186188
],
187189
],
188190
],
189-
'expectedMessage' => 'The configuration file doesn\'t contain sensitive data for security reasons. '
190-
. 'Sensitive data can be stored in the following environment variables:'
191-
. "\n" . 'CONFIG__SOME__SENSITIVE__FIELD1 for some/sensitive/field1'
192-
. "\n" . 'CONFIG__SOME__SENSITIVE__FIELD2 for some/sensitive/field2'
191+
'expectedMessage' => implode(PHP_EOL, [
192+
'Shared configuration was written to config.php and system-specific configuration to env.php.',
193+
'Shared configuration file (config.php) doesn\'t contain sensitive data for security reasons.',
194+
'Sensitive data can be stored in the following environment variables:',
195+
'CONFIG__SOME__SENSITIVE__FIELD1 for some/sensitive/field1',
196+
'CONFIG__SOME__SENSITIVE__FIELD2 for some/sensitive/field2',
197+
'CONFIG__SOME__SENSITIVE_AND_ENV__FIELD for some/sensitive_and_env/field'
198+
])
193199
],
194200
];
195201
}

app/code/Magento/Config/Test/Unit/Model/Config/_files/config.local.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
],
1313
],
1414
/**
15-
* The configuration file doesn't contain sensitive data for security reasons.
15+
* Shared configuration was written to config.php and system-specific configuration to env.php.
16+
* Shared configuration file (config.php) doesn't contain sensitive data for security reasons.
1617
* Sensitive data can be stored in the following environment variables:
1718
* CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD for some/payment/password
1819
*/

dev/tests/integration/testsuite/Magento/Deploy/Console/Command/App/ApplicationDumpCommandTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ public function testExecute()
135135
]
136136
]);
137137

138-
$comment = 'The configuration file doesn\'t contain sensitive data for security reasons. '
139-
. 'Sensitive data can be stored in the following environment variables:'
140-
. "\nCONFIG__DEFAULT__WEB__TEST__TEST_SENSITIVE for web/test/test_sensitive"
141-
. "\nCONFIG__DEFAULT__WEB__TEST__TEST_SENSITIVE3 for web/test/test_sensitive3"
142-
. "\nCONFIG__DEFAULT__WEB__TEST__TEST_SENSITIVE_ENVIRONMENT5 for web/test/test_sensitive_environment5";
138+
$comment = implode(PHP_EOL, [
139+
'Shared configuration was written to config.php and system-specific configuration to env.php.',
140+
'Shared configuration file (config.php) doesn\'t contain sensitive data for security reasons.',
141+
'Sensitive data can be stored in the following environment variables:',
142+
'CONFIG__DEFAULT__WEB__TEST__TEST_SENSITIVE for web/test/test_sensitive',
143+
'CONFIG__DEFAULT__WEB__TEST__TEST_SENSITIVE3 for web/test/test_sensitive3',
144+
'CONFIG__DEFAULT__WEB__TEST__TEST_SENSITIVE_ENVIRONMENT5 for web/test/test_sensitive_environment5'
145+
]);
143146
$outputMock = $this->getMock(OutputInterface::class);
144147
$outputMock->expects($this->at(0))
145148
->method('writeln')

dev/tests/integration/testsuite/Magento/Deploy/_files/_config.local.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
'websites' => []
99
],
1010
/**
11-
* The configuration file doesn't contain sensitive data for security reasons.
11+
* Shared configuration was written to config.php and system-specific configuration to env.php.
12+
* Shared configuration file (config.php) doesn't contain sensitive data for security reasons.
1213
* Sensitive data can be stored in the following environment variables:
1314
* CONFIG__DEFAULT__SOME__CONFIG__PATH_ONE for some/config/path_one
1415
* CONFIG__DEFAULT__SOME__CONFIG__PATH_TWO for some/config/path_two

dev/tests/integration/testsuite/Magento/Deploy/_files/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
'websites' => []
99
],
1010
/**
11-
* The configuration file doesn't contain sensitive data for security reasons.
11+
* Shared configuration was written to config.php and system-specific configuration to env.php.
12+
* Shared configuration file (config.php) doesn't contain sensitive data for security reasons.
1213
* Sensitive data can be stored in the following environment variables:
1314
* CONFIG__DEFAULT__SOME__CONFIG__PATH_ONE for some/config/path_one
1415
* CONFIG__DEFAULT__SOME__CONFIG__PATH_TWO for some/config/path_two

0 commit comments

Comments
 (0)