Skip to content

Commit

Permalink
Merge pull request #566 from magento-falcons/MAGETWO-59376
Browse files Browse the repository at this point in the history
Fixed issue: 
- Split Deployment - scrub sensitive data - override config values by environment
  • Loading branch information
Oleksii Korshenko authored Nov 3, 2016
2 parents a77e621 + fbd1d3d commit 32e0525
Show file tree
Hide file tree
Showing 55 changed files with 2,413 additions and 104 deletions.
10 changes: 10 additions & 0 deletions app/code/Magento/Authorizenet/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@
<argument name="storage" xsi:type="object">Magento\Authorizenet\Model\Directpost\Session\Storage</argument>
</arguments>
</type>
<type name="Magento\Config\Model\Config\Export\ExcludeList">
<arguments>
<argument name="configs" xsi:type="array">
<item name="payment/authorizenet_directpost/login" xsi:type="string">1</item>
<item name="payment/authorizenet_directpost/trans_key" xsi:type="string">1</item>
<item name="payment/authorizenet_directpost/trans_md5" xsi:type="string">1</item>
<item name="payment/authorizenet_directpost/merchant_email" xsi:type="string">1</item>
</argument>
</arguments>
</type>
</config>
18 changes: 18 additions & 0 deletions app/code/Magento/Backend/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,22 @@
</argument>
</arguments>
</type>
<type name="Magento\Config\Model\Config\Export\ExcludeList">
<arguments>
<argument name="configs" xsi:type="array">
<item name="trans_email/ident_general/name" xsi:type="string">1</item>
<item name="trans_email/ident_general/email" xsi:type="string">1</item>
<item name="trans_email/ident_sales/name" xsi:type="string">1</item>
<item name="trans_email/ident_sales/email" xsi:type="string">1</item>
<item name="trans_email/ident_support/name" xsi:type="string">1</item>
<item name="trans_email/ident_support/email" xsi:type="string">1</item>
<item name="trans_email/ident_custom1/name" xsi:type="string">1</item>
<item name="trans_email/ident_custom1/email" xsi:type="string">1</item>
<item name="trans_email/ident_custom2/name" xsi:type="string">1</item>
<item name="trans_email/ident_custom2/email" xsi:type="string">1</item>
<item name="admin/url/custom" xsi:type="string">1</item>
<item name="admin/url/custom_path" xsi:type="string">1</item>
</argument>
</arguments>
</type>
</config>
16 changes: 14 additions & 2 deletions app/code/Magento/Braintree/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
</arguments>
</virtualType>
<!-- END PayPal commands -->

<!-- Value handlers infrastructure -->
<type name="Magento\Braintree\Gateway\Response\VaultDetailsHandler">
<arguments>
Expand Down Expand Up @@ -452,7 +452,7 @@
</arguments>
</virtualType>
<!-- END PayPal value handlers infrastructure -->

<!-- Void Command -->
<virtualType name="BraintreeVoidCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
Expand Down Expand Up @@ -544,4 +544,16 @@
</arguments>
</type>
<!-- END Settlement Report Section -->
<type name="Magento\Config\Model\Config\Export\ExcludeList">
<arguments>
<argument name="configs" xsi:type="array">
<item name="payment/braintree/merchant_id" xsi:type="string">1</item>
<item name="payment/braintree/public_key" xsi:type="string">1</item>
<item name="payment/braintree/private_key" xsi:type="string">1</item>
<item name="payment/braintree/merchant_account_id" xsi:type="string">1</item>
<item name="payment/braintree/kount_id" xsi:type="string">1</item>
<item name="payment/braintree_paypal/merchant_name_override" xsi:type="string">1</item>
</argument>
</arguments>
</type>
</config>
7 changes: 7 additions & 0 deletions app/code/Magento/Checkout/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@
</argument>
</arguments>
</type>
<type name="Magento\Config\Model\Config\Export\ExcludeList">
<arguments>
<argument name="configs" xsi:type="array">
<item name="checkout/payment_failed/copy_to" xsi:type="string">1</item>
</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\App\Config\Source;

use Magento\Config\Model\Config\Export\ExcludeList;
use Magento\Framework\App\Config\ConfigSourceInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;

class DumpConfigSourceAggregated implements DumpConfigSourceInterface
{
/**
* @var ExcludeList
*/
private $excludeList;

/**
* @var ConfigSourceInterface[]
*/
private $sources;

/**
* @var array
*/
private $excludedFields;

/**
* @var array
*/
private $data;

/**
* @param ExcludeList $excludeList
* @param array $sources
*/
public function __construct(ExcludeList $excludeList, array $sources = [])
{
$this->excludeList = $excludeList;
$this->sources = $sources;
}

/**
* Retrieve aggregated configuration from all available sources.
*
* @param string $path
* @return array
*/
public function get($path = '')
{
$path = (string)$path;
$data = [];

if (isset($this->data[$path])) {
return $this->data[$path];
}

$this->sortSources();

foreach ($this->sources as $sourceConfig) {
/** @var ConfigSourceInterface $source */
$source = $sourceConfig['source'];
$data = array_replace_recursive($data, $source->get($path));
}

$this->excludedFields = [];
$this->filterChain($path, $data);

return $this->data[$path] = $data;
}

/**
* Recursive filtering of sensitive data
*
* @param string $path
* @param array $data
* @return void
*/
private function filterChain($path, &$data)
{
foreach ($data as $subKey => &$subData) {
$newPath = $path ? $path . '/' . $subKey : $subKey;
$filteredPath = $this->filterPath($newPath);

if (
$filteredPath
&& !is_array($data[$subKey])
&& $this->excludeList->isPresent($filteredPath)
) {
$this->excludedFields[$newPath] = $filteredPath;

unset($data[$subKey]);
} elseif (is_array($subData)) {
$this->filterChain($newPath, $subData);
}
}
}

/**
* Eliminating scope info from path
*
* @param string $path
* @return null|string
*/
private function filterPath($path)
{
$parts = explode('/', $path);

// Check if there are enough parts to recognize scope
if (count($parts) < 3) {
return null;
}

if ($parts[0] === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
unset($parts[0]);
} else {
unset($parts[0], $parts[1]);
}

return implode('/', $parts);
}

/**
* Sort sources ASC from higher priority to lower
*
* @return void
*/
private function sortSources()
{
uasort($this->sources, function ($firstItem, $secondItem) {
return $firstItem['sortOrder'] > $secondItem['sortOrder'];
});
}

/**
* Retrieves list of field paths were excluded from config dump
* @return array
*/
public function getExcludedFields()
{
$this->get();

$fields = array_values($this->excludedFields);
$fields = array_unique($fields);

return $fields;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\App\Config\Source;

use Magento\Framework\App\Config\ConfigSourceInterface;

/**
* Interface DumpConfigSourceInterface
*/
interface DumpConfigSourceInterface extends ConfigSourceInterface
{
/**
* Retrieves list of field paths were excluded from config dump
*
* @return array
*/
public function getExcludedFields();
}
13 changes: 12 additions & 1 deletion app/code/Magento/Config/App/Config/Type/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\App\Config\ConfigTypeInterface;
use Magento\Framework\App\Config\ConfigSourceInterface;
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
use Magento\Framework\App\Config\Spi\PreProcessorInterface;
use Magento\Framework\Cache\FrontendInterface;
use Magento\Framework\DataObject;
use Magento\Store\Model\Config\Processor\Fallback;
Expand Down Expand Up @@ -38,6 +39,11 @@ class System implements ConfigTypeInterface
*/
private $postProcessor;

/**
* @var PreProcessorInterface
*/
private $preProcessor;

/**
* @var FrontendInterface
*/
Expand All @@ -59,17 +65,20 @@ class System implements ConfigTypeInterface
* @param PostProcessorInterface $postProcessor
* @param Fallback $fallback
* @param FrontendInterface $cache
* @param PreProcessorInterface $preProcessor
* @param int $cachingNestedLevel
*/
public function __construct(
ConfigSourceInterface $source,
PostProcessorInterface $postProcessor,
Fallback $fallback,
FrontendInterface $cache,
PreProcessorInterface $preProcessor,
$cachingNestedLevel = 1
) {
$this->source = $source;
$this->postProcessor = $postProcessor;
$this->preProcessor = $preProcessor;
$this->cache = $cache;
$this->cachingNestedLevel = $cachingNestedLevel;
$this->fallback = $fallback;
Expand All @@ -86,7 +95,9 @@ public function get($path = '')
if (!$this->data) {
$data = $this->cache->load(self::CONFIG_TYPE);
if (!$data) {
$data = $this->fallback->process($this->source->get());
$data = $this->preProcessor->process($this->source->get());
$this->data = new DataObject($data);
$data = $this->fallback->process($data);
$this->data = new DataObject($data);
$data = $this->postProcessor->process($data);
$this->data = new DataObject($data);
Expand Down
Loading

0 comments on commit 32e0525

Please sign in to comment.