Skip to content

Commit

Permalink
Merge pull request #39 from cloudinary/v2.9.3
Browse files Browse the repository at this point in the history
V2.9.3
  • Loading branch information
Pini authored Dec 27, 2018
2 parents 8cce8ba + d1a15a6 commit 2deae18
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ private function setStoreConfig($configPath, $value)
private function getEnvironmentVariable()
{
if (is_null($this->environmentVariable)) {
$value = Mage::helper('core')->decrypt(Mage::getStoreConfig(self::CONFIG_PATH_ENVIRONMENT_VARIABLE));
if (Mage::registry('cloudinaryEnvironmentVariable')) {
$value = Mage::helper('core')->decrypt(Mage::registry('cloudinaryEnvironmentVariable'));
} else {
$value = Mage::helper('core')->decrypt(Mage::getStoreConfig(self::CONFIG_PATH_ENVIRONMENT_VARIABLE));
}
$this->environmentVariable = CloudinaryEnvironmentVariable::fromString($value);
}
return $this->environmentVariable;
Expand Down
13 changes: 11 additions & 2 deletions app/code/community/Cloudinary/Cloudinary/Model/Observer/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public function configSave(Varien_Event_Observer $observer)

$data = Mage::helper('cloudinary_cloudinary/config')->flatten('cloudinary', $config->getGroups());
if ($data[self::ENABLED_FIELD] == '1') {
Mage::register('cloudinaryIsEnabled', true);
$this->validateEnvironmentVariable($data);
$this->logConfigChange($data);
} else {
Mage::register('cloudinaryIsEnabled', false);
}
}

Expand All @@ -42,7 +45,7 @@ public function cloudinaryConfigChanged(Varien_Event_Observer $observer)
Mage::app()->getCacheInstance()->cleanType("config");
Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => "config"));

if (!Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
if (!Mage::registry('cloudinaryIsEnabled')) {
return;
}

Expand All @@ -62,12 +65,18 @@ public function cloudinaryConfigChanged(Varien_Event_Observer $observer)
*/
private function validateEnvironmentVariable(array $data)
{
$value = (string) $data[self::ENVIRONMENT_FIELD];
if (preg_match('/^\*+$/', $value)) {
$value = Mage::helper('core')->decrypt($value);
}
$credentialValidator = new CredentialValidator();
$environmentVariable = CloudinaryEnvironmentVariable::fromString($data[self::ENVIRONMENT_FIELD]);
$environmentVariable = CloudinaryEnvironmentVariable::fromString($value);

if (!$credentialValidator->validate($environmentVariable->getCredentials())) {
Mage::register('cloudinaryEnvironmentVariableIsValid', false);
throw new Mage_Core_Exception(self::ERROR_WRONG_CREDENTIALS);
}
Mage::register('cloudinaryEnvironmentVariableIsValid', true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
use CloudinaryExtension\CredentialValidator;
use CloudinaryExtension\Security\CloudinaryEnvironmentVariable;

/**
* Cloudinary_Cloudinary_Model_System_Config_Credentials
*/
class Cloudinary_Cloudinary_Model_System_Config_Credentials extends Mage_Adminhtml_Model_System_Config_Backend_Encrypted
{
/**
* Encrypt value before saving
*
*/
protected function _beforeSave()
{
$value = (string)$this->getValue();
if (preg_match('/^\*+$/', $value)) {
$value = $this->getOldValue();
}

$isValid = false;
try {
$credentialValidator = new CredentialValidator();
$environmentVariable = CloudinaryEnvironmentVariable::fromString($value);
$isValid = (bool) $credentialValidator->validate($environmentVariable->getCredentials());
} catch (\Exception $e) {
//Ignore errors
}

if (!$isValid) {
$this->setValue(null);
Mage::getSingleton('core/session')->addError(Cloudinary_Cloudinary_Model_Observer_Config::ERROR_WRONG_CREDENTIALS);
}

parent::_beforeSave();

Mage::register('cloudinaryEnvironmentVariable', $this->getValue());

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function httpRequest($url)
*/
public function hasAccountConfigured()
{
return (string)$this->configuration->getCloud() !== '';
return Mage::registry('cloudinaryEnvironmentVariableIsValid');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Cloudinary/Cloudinary/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Cloudinary_Cloudinary>
<version>2.9.2</version>
<version>2.9.3</version>
</Cloudinary_Cloudinary>
</modules>
<global>
Expand Down
4 changes: 2 additions & 2 deletions app/code/community/Cloudinary/Cloudinary/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<label>Cloudinary Account Credentials</label>
<comment>Set the credentials of your Cloudinary account. Copy the "Environment variable" string from the dashboard of Cloudinary's Management Console.</comment>
<frontend_type>password</frontend_type>
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
<backend_model>cloudinary_cloudinary/system_config_credentials</backend_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
Expand Down Expand Up @@ -136,7 +136,7 @@
<source_model>cloudinary_cloudinary/system_config_source_dropdown_dpr</source_model>
</cloudinary_image_dpr>
<cloudinary_free_transform_global>
<label>Global custom transform</label>
<label>Global custom transformation</label>
<frontend_type>text</frontend_type>
<sort_order>5</sort_order>
<show_in_default>1</show_in_default>
Expand Down
7 changes: 3 additions & 4 deletions var/connect/Cloudinary_Cloudinary.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<_>
<form_key>FlphPtIaaCI8lVwe</form_key>
<_create/>
<form_key>pHIzpC9UKidsX254</form_key>
<name>Cloudinary_Cloudinary</name>
<channel>community</channel>
<version_ids>
Expand All @@ -10,7 +9,7 @@
<description>Cloudinary supercharges your images! Upload images to the cloud, deliver optimized via a fast CDN, perform smart resizing and apply effects.</description>
<license>MIT License (MITL)</license>
<license_uri/>
<version>2.9.2</version>
<version>2.9.3</version>
<stability>stable</stability>
<notes> - Match MEQP1 coding standards
</notes>
Expand Down Expand Up @@ -42,7 +41,7 @@
<max/>
</max>
<files>
<files> </files>
<files> </files>
</files>
</package>
<extension>
Expand Down
8 changes: 4 additions & 4 deletions var/package/package.xml

Large diffs are not rendered by default.

0 comments on commit 2deae18

Please sign in to comment.