Skip to content

Fixes & improvements in environment variable validationFixes #15

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Dec 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Model/Config/Backend/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Cloudinary\Cloudinary\Core\Exception\InvalidCredentials;
use Magento\Config\Model\Config\Backend\Encrypted;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Encryption\EncryptorInterface;
Expand Down Expand Up @@ -39,6 +40,13 @@ class Credentials extends Encrypted
*/
private $api;

/**
* Application config
*
* @var ScopeConfigInterface
*/
protected $appConfig;

/**
* @param Context $context
* @param Registry $registry
Expand All @@ -50,6 +58,7 @@ class Credentials extends Encrypted
* @param AbstractDb $resourceCollection
* @param ConfigurationBuilder $configurationBuilder
* @param Api $api
* @param ReinitableConfigInterface $appConfig
* @param array $data
*/
public function __construct(
Expand All @@ -63,11 +72,13 @@ public function __construct(
AbstractDb $resourceCollection = null,
ConfigurationBuilder $configurationBuilder,
Api $api,
ReinitableConfigInterface $appConfig,
array $data = []
) {
$this->configuration = $configuration;
$this->configurationBuilder = $configurationBuilder;
$this->api = $api;
$this->appConfig = $appConfig;

parent::__construct(
$context,
Expand All @@ -87,7 +98,13 @@ public function beforeSave()

parent::beforeSave();

if ($rawValue) {
$this->cacheTypeList->cleanType(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER);
$this->appConfig->reinit();

if ($rawValue || $this->configuration->isEnabled(false)) {
if (!$rawValue) {
throw new ValidatorException(__(self::CREDENTIALS_CHECK_MISSING));
}
if ($this->isSaveAllowed()) {
$this->validate($this->getCredentialsFromEnvironmentVariable($rawValue));
} else {
Expand Down
4 changes: 2 additions & 2 deletions Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ public function getUploadConfig()
/**
* @return boolean
*/
public function isEnabled()
public function isEnabled($checkEnvVar = true)
{
return $this->hasEnvironmentVariable() && $this->configReader->isSetFlag(self::CONFIG_PATH_ENABLED);
return ($this->hasEnvironmentVariable() || !$checkEnvVar) && $this->configReader->isSetFlag(self::CONFIG_PATH_ENABLED);
}

public function enable()
Expand Down