Skip to content

Commit

Permalink
Merge pull request #370 from PrestaShopCorp/feat/reset-circuit-breaker
Browse files Browse the repository at this point in the history
[ACCOUNT-2048] feat: clear circuit breaker status on install, reset
  • Loading branch information
hschoenenberger authored Oct 16, 2023
2 parents 8898d09 + 1dbc5f2 commit fc4c92c
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 131 deletions.
32 changes: 32 additions & 0 deletions ps_accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Ps_accounts extends Module
'displayDashboardTop',
'actionAdminLoginControllerLoginAfter',
'actionAdminControllerInitBefore',
'actionModuleInstallAfter',
self::HOOK_DISPLAY_ACCOUNT_UPDATE_WARNING,
self::HOOK_ACTION_SHOP_ACCOUNT_LINK_AFTER,
self::HOOK_ACTION_SHOP_ACCOUNT_UNLINK_AFTER,
Expand Down Expand Up @@ -157,6 +158,7 @@ public function getAdminControllers()
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws Exception
*/
public function install()
{
Expand Down Expand Up @@ -711,6 +713,18 @@ public function hookActionShopAccountUnlinkAfter($params)
// Not implemented here
}

/**
* @param mixed $module
*
* @return void
*
* @throws Exception
*/
public function hookActionModuleInstallAfter($module)
{
$this->resetCircuitBreaker();
}

/**
* @return string
*/
Expand Down Expand Up @@ -864,4 +878,22 @@ protected function getOauth2Session(): PrestaShop\Module\PsAccounts\Provider\OAu
{
return $this->getService(\PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopSession::class);
}

/**
* @return void
*
* @throws Exception
*/
private function resetCircuitBreaker(): void
{
$this->getLogger()->info(__METHOD__);

/** @var \PrestaShop\Module\PsAccounts\Api\Client\AccountsClient $accountsClient */
$accountsClient = $this->getService(\PrestaShop\Module\PsAccounts\Api\Client\AccountsClient::class);
$accountsClient->getCircuitBreaker()->reset();

/** @var \PrestaShop\Module\PsAccounts\Api\Client\SsoClient $ssoClient */
$ssoClient = $this->getService(\PrestaShop\Module\PsAccounts\Api\Client\SsoClient::class);
$ssoClient->getCircuitBreaker()->reset();
}
}
50 changes: 12 additions & 38 deletions src/Adapter/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,6 @@

class Configuration
{
public const PSX_UUID_V4 = 'PSX_UUID_V4';

// PS Shop Account
public const PS_ACCOUNTS_FIREBASE_ID_TOKEN = 'PS_ACCOUNTS_FIREBASE_ID_TOKEN';
public const PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN = 'PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN';
public const PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN_FAILURE = 'PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN_FAILURE';

// PS User Account
public const PS_ACCOUNTS_FIREBASE_EMAIL = 'PS_ACCOUNTS_FIREBASE_EMAIL';
public const PS_ACCOUNTS_FIREBASE_EMAIL_IS_VERIFIED = 'PS_ACCOUNTS_FIREBASE_EMAIL_IS_VERIFIED';
public const PS_ACCOUNTS_USER_FIREBASE_UUID = 'PS_ACCOUNTS_USER_FIREBASE_UUID';
public const PS_ACCOUNTS_USER_FIREBASE_ID_TOKEN = 'PS_ACCOUNTS_USER_FIREBASE_ID_TOKEN';
public const PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN = 'PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN';
public const PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN_FAILURE = 'PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN_FAILURE';
public const PS_ACCOUNTS_SHOP_UNLINKED_AUTO = 'PS_ACCOUNTS_SHOP_UNLINKED_AUTO';

// PS Backend User
public const PS_ACCOUNTS_EMPLOYEE_ID = 'PS_ACCOUNTS_EMPLOYEE_ID';

// API keys
public const PS_ACCOUNTS_RSA_PUBLIC_KEY = 'PS_ACCOUNTS_RSA_PUBLIC_KEY';
public const PS_ACCOUNTS_RSA_PRIVATE_KEY = 'PS_ACCOUNTS_RSA_PRIVATE_KEY';
public const PS_ACCOUNTS_RSA_SIGN_DATA = 'PS_ACCOUNTS_RSA_SIGN_DATA';

// /!\ Compat with ps_checkout
public const PS_CHECKOUT_SHOP_UUID_V4 = 'PS_CHECKOUT_SHOP_UUID_V4';
public const PS_PSX_FIREBASE_ID_TOKEN = 'PS_PSX_FIREBASE_ID_TOKEN';
public const PS_PSX_FIREBASE_REFRESH_TOKEN = 'PS_PSX_FIREBASE_REFRESH_TOKEN';
public const PS_PSX_FIREBASE_REFRESH_DATE = 'PS_PSX_FIREBASE_REFRESH_DATE';
public const PS_PSX_FIREBASE_EMAIL = 'PS_PSX_FIREBASE_EMAIL';

// PsAccounts SSO login enabled
public const PS_ACCOUNTS_LOGIN_ENABLED = 'PS_ACCOUNTS_LOGIN_ENABLED';

// OAuth2 client setup
public const PS_ACCOUNTS_OAUTH2_CLIENT_ID = 'PS_ACCOUNTS_OAUTH2_CLIENT_ID';
public const PS_ACCOUNTS_OAUTH2_CLIENT_SECRET = 'PS_ACCOUNTS_OAUTH2_CLIENT_SECRET';

/**
* @var int
*/
Expand Down Expand Up @@ -192,6 +154,18 @@ public function setRaw($key, $values, $html = false, $idShopGroup = null, $idSho
return \Configuration::updateValue($key, $values, $html, $idShopGroup, $idShop);
}

/**
* @param string $key
* @param string|array $values
* @param bool $html
*
* @return void
*/
public function setGlobal($key, $values, $html = false)
{
\Configuration::updateGlobalValue($key, $values, $html);
}

/**
* @param string $key
* @param int|null $idShopGroup
Expand Down
51 changes: 51 additions & 0 deletions src/Adapter/ConfigurationKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace PrestaShop\Module\PsAccounts\Adapter;

use ReflectionClass;

class ConfigurationKeys
{
public const PSX_UUID_V4 = 'PSX_UUID_V4';

// PS Shop Account
public const PS_ACCOUNTS_FIREBASE_ID_TOKEN = 'PS_ACCOUNTS_FIREBASE_ID_TOKEN';
public const PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN = 'PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN';
public const PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN_FAILURE = 'PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN_FAILURE';

// PS User Account
public const PS_ACCOUNTS_FIREBASE_EMAIL = 'PS_ACCOUNTS_FIREBASE_EMAIL';
public const PS_ACCOUNTS_FIREBASE_EMAIL_IS_VERIFIED = 'PS_ACCOUNTS_FIREBASE_EMAIL_IS_VERIFIED';
public const PS_ACCOUNTS_USER_FIREBASE_UUID = 'PS_ACCOUNTS_USER_FIREBASE_UUID';
public const PS_ACCOUNTS_USER_FIREBASE_ID_TOKEN = 'PS_ACCOUNTS_USER_FIREBASE_ID_TOKEN';
public const PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN = 'PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN';
public const PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN_FAILURE = 'PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN_FAILURE';
public const PS_ACCOUNTS_SHOP_UNLINKED_AUTO = 'PS_ACCOUNTS_SHOP_UNLINKED_AUTO';

// PS Backend User
public const PS_ACCOUNTS_EMPLOYEE_ID = 'PS_ACCOUNTS_EMPLOYEE_ID';

// API keys
public const PS_ACCOUNTS_RSA_PUBLIC_KEY = 'PS_ACCOUNTS_RSA_PUBLIC_KEY';
public const PS_ACCOUNTS_RSA_PRIVATE_KEY = 'PS_ACCOUNTS_RSA_PRIVATE_KEY';
public const PS_ACCOUNTS_RSA_SIGN_DATA = 'PS_ACCOUNTS_RSA_SIGN_DATA';

// /!\ Compat with ps_checkout
public const PS_CHECKOUT_SHOP_UUID_V4 = 'PS_CHECKOUT_SHOP_UUID_V4';
public const PS_PSX_FIREBASE_ID_TOKEN = 'PS_PSX_FIREBASE_ID_TOKEN';
public const PS_PSX_FIREBASE_REFRESH_TOKEN = 'PS_PSX_FIREBASE_REFRESH_TOKEN';
public const PS_PSX_FIREBASE_REFRESH_DATE = 'PS_PSX_FIREBASE_REFRESH_DATE';
public const PS_PSX_FIREBASE_EMAIL = 'PS_PSX_FIREBASE_EMAIL';

// PsAccounts SSO login enabled
public const PS_ACCOUNTS_LOGIN_ENABLED = 'PS_ACCOUNTS_LOGIN_ENABLED';

// OAuth2 client setup
public const PS_ACCOUNTS_OAUTH2_CLIENT_ID = 'PS_ACCOUNTS_OAUTH2_CLIENT_ID';
public const PS_ACCOUNTS_OAUTH2_CLIENT_SECRET = 'PS_ACCOUNTS_OAUTH2_CLIENT_SECRET';

public static function getKeys(): array
{
return (new ReflectionClass(self::class))->getConstants();
}
}
8 changes: 8 additions & 0 deletions src/Api/Client/AccountsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ public function updateUserShop(UpdateShop $shop)
});
}

/**
* @return CircuitBreaker
*/
public function getCircuitBreaker(): CircuitBreaker
{
return $this->circuitBreaker;
}

/**
* @param array $additionalHeaders
*
Expand Down
3 changes: 2 additions & 1 deletion src/Api/Client/CircuitBreaker/PersistentCircuitBreaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private function get(string $key): string
*/
private function set(string $key, $value): void
{
$this->config->setRaw($this->getKey($key), $value, false, 0, 0);
//$this->config->setRaw($this->getKey($key), $value, false, 0, 0);
$this->config->setGlobal($this->getKey($key), $value);
}

private function getKey(string $key): string
Expand Down
8 changes: 8 additions & 0 deletions src/Api/Client/SsoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,12 @@ public function refreshToken($refreshToken)
]);
});
}

/**
* @return CircuitBreaker
*/
public function getCircuitBreaker(): CircuitBreaker
{
return $this->circuitBreaker;
}
}
Loading

0 comments on commit fc4c92c

Please sign in to comment.