Skip to content

Commit

Permalink
Add "Disable Symfony Secrets" checker (#298)
Browse files Browse the repository at this point in the history
* Add "Disable Symfony Secrets" checker

* Add check if symfony secrets are in use
  • Loading branch information
M-arcus authored Dec 3, 2024
1 parent ec8e624 commit b1f6b8d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
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);
}
}
4 changes: 4 additions & 0 deletions src/DependencyInjection/SymfonyConfigCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ public function process(ContainerBuilder $container): void
if (!$container->hasParameter('shopware.cache.tagging.each_theme_config')) {
$container->setParameter('shopware.cache.tagging.each_theme_config', true);
}

if (!$container->hasParameter('framework.secrets.enabled')) {
$container->setParameter('framework.secrets.enabled', true);
}
}
}

0 comments on commit b1f6b8d

Please sign in to comment.