-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Disable Symfony Secrets" checker (#298)
* Add "Disable Symfony Secrets" checker * Add check if symfony secrets are in use
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/Components/Health/Checker/PerformanceChecker/DisableSymfonySecretsChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker; | ||
|
||
use Frosh\Tools\Components\Health\Checker\CheckerInterface; | ||
use Frosh\Tools\Components\Health\HealthCollection; | ||
use Frosh\Tools\Components\Health\SettingsResult; | ||
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
class DisableSymfonySecretsChecker implements PerformanceCheckerInterface, CheckerInterface | ||
{ | ||
public function __construct( | ||
#[Autowire(param: 'framework.secrets.enabled')] | ||
private readonly bool $secretsEnabled, | ||
#[Autowire(service: 'secrets.vault')] | ||
private readonly AbstractVault $vault, | ||
#[Autowire(service: 'secrets.local_vault')] | ||
private readonly ?AbstractVault $localVault = null, | ||
) {} | ||
|
||
public function collect(HealthCollection $collection): void | ||
{ | ||
if ($this->secretsEnabled && !$this->areSecretsInUse()) { | ||
$collection->add( | ||
SettingsResult::info( | ||
'symfony-secrets', | ||
'Disable Symfony Secrets', | ||
'enabled', | ||
'disabled', | ||
'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#disable-symfony-secrets', | ||
), | ||
); | ||
} | ||
} | ||
|
||
private function areSecretsInUse(): bool | ||
{ | ||
return count($this->vault->list()) > 0 || ($this->localVault instanceof AbstractVault && count($this->localVault->list()) > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters