fix(Discovery): Add comprehensive debug logging for router initialization
- Add initializer count logging in DiscoveryServiceBootstrapper - Add route structure analysis in RouterSetup - Add request parameter logging in HttpRouter - Update PHP production config for better OPcache handling - Fix various config and error handling improvements
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Security\RequestSigning;
|
||||
|
||||
use App\Framework\Config\Environment;
|
||||
|
||||
/**
|
||||
* Configuration for request signing functionality
|
||||
*/
|
||||
@@ -24,26 +26,28 @@ final readonly class RequestSigningConfig
|
||||
/**
|
||||
* Create configuration from environment variables
|
||||
*/
|
||||
public static function fromEnvironment(): self
|
||||
public static function fromEnvironment(Environment $env): self
|
||||
{
|
||||
$enabled = filter_var($_ENV['REQUEST_SIGNING_ENABLED'] ?? 'false', FILTER_VALIDATE_BOOLEAN);
|
||||
$requireSignature = filter_var($_ENV['REQUEST_SIGNING_REQUIRED'] ?? 'false', FILTER_VALIDATE_BOOLEAN);
|
||||
$enabled = $env->getBool('REQUEST_SIGNING_ENABLED', false);
|
||||
$requireSignature = $env->getBool('REQUEST_SIGNING_REQUIRED', false);
|
||||
|
||||
$exemptPaths = [];
|
||||
if (isset($_ENV['REQUEST_SIGNING_EXEMPT_PATHS'])) {
|
||||
$exemptPaths = array_filter(array_map('trim', explode(',', $_ENV['REQUEST_SIGNING_EXEMPT_PATHS'])));
|
||||
$exemptPathsString = $env->getString('REQUEST_SIGNING_EXEMPT_PATHS', '');
|
||||
if ($exemptPathsString !== '') {
|
||||
$exemptPaths = array_filter(array_map('trim', explode(',', $exemptPathsString)));
|
||||
}
|
||||
|
||||
$defaultHeaders = ['(request-target)', 'host', 'date'];
|
||||
if (isset($_ENV['REQUEST_SIGNING_DEFAULT_HEADERS'])) {
|
||||
$defaultHeaders = array_filter(array_map('trim', explode(',', $_ENV['REQUEST_SIGNING_DEFAULT_HEADERS'])));
|
||||
$defaultHeadersString = $env->getString('REQUEST_SIGNING_DEFAULT_HEADERS', '');
|
||||
if ($defaultHeadersString !== '') {
|
||||
$defaultHeaders = array_filter(array_map('trim', explode(',', $defaultHeadersString)));
|
||||
}
|
||||
|
||||
$maxClockSkew = (int) ($_ENV['REQUEST_SIGNING_MAX_CLOCK_SKEW'] ?? 300);
|
||||
$defaultExpiry = (int) ($_ENV['REQUEST_SIGNING_DEFAULT_EXPIRY'] ?? 3600);
|
||||
$maxClockSkew = $env->getInt('REQUEST_SIGNING_MAX_CLOCK_SKEW', 300);
|
||||
$defaultExpiry = $env->getInt('REQUEST_SIGNING_DEFAULT_EXPIRY', 3600);
|
||||
|
||||
$algorithm = SigningAlgorithm::tryFrom($_ENV['REQUEST_SIGNING_ALGORITHM'] ?? 'hmac-sha256')
|
||||
?? SigningAlgorithm::HMAC_SHA256;
|
||||
$algorithmString = $env->getString('REQUEST_SIGNING_ALGORITHM', 'hmac-sha256');
|
||||
$algorithm = SigningAlgorithm::tryFrom($algorithmString) ?? SigningAlgorithm::HMAC_SHA256;
|
||||
|
||||
return new self(
|
||||
enabled: $enabled,
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Framework\Security\RequestSigning;
|
||||
|
||||
use App\Framework\Cache\Cache;
|
||||
use App\Framework\Config\Environment;
|
||||
use App\Framework\Database\EntityManager;
|
||||
use App\Framework\DateTime\Clock;
|
||||
use App\Framework\DI\Container;
|
||||
@@ -58,7 +59,9 @@ final readonly class RequestSigningInitializer
|
||||
*/
|
||||
private function getConfig(): RequestSigningConfig
|
||||
{
|
||||
$isProduction = ($_ENV['APP_ENV'] ?? 'development') === 'production';
|
||||
$env = $this->container->get(Environment::class);
|
||||
$appEnv = $env->getString('APP_ENV', 'development');
|
||||
$isProduction = $appEnv === 'production';
|
||||
|
||||
return $isProduction
|
||||
? RequestSigningConfig::production()
|
||||
@@ -70,7 +73,9 @@ final readonly class RequestSigningInitializer
|
||||
*/
|
||||
private function createKeyRepository(RequestSigningConfig $config): SigningKeyRepository
|
||||
{
|
||||
$isProduction = ($_ENV['APP_ENV'] ?? 'development') === 'production';
|
||||
$env = $this->container->get(Environment::class);
|
||||
$appEnv = $env->getString('APP_ENV', 'development');
|
||||
$isProduction = $appEnv === 'production';
|
||||
|
||||
if ($isProduction && $this->container->has(EntityManager::class)) {
|
||||
return new EntityManagerSigningKeyRepository(
|
||||
@@ -94,7 +99,9 @@ final readonly class RequestSigningInitializer
|
||||
}
|
||||
|
||||
// Add a default development key
|
||||
if (($_ENV['APP_ENV'] ?? 'development') === 'development') {
|
||||
$env = $this->container->get(Environment::class);
|
||||
$appEnv = $env->getString('APP_ENV', 'development');
|
||||
if ($appEnv === 'development') {
|
||||
if ($keyRepository instanceof InMemorySigningKeyRepository) {
|
||||
$keyRepository->addDefaultTestKey();
|
||||
}
|
||||
@@ -109,9 +116,11 @@ final readonly class RequestSigningInitializer
|
||||
*/
|
||||
private function loadKeysFromEnvironment(SigningKeyRepository $keyRepository): void
|
||||
{
|
||||
$env = $this->container->get(Environment::class);
|
||||
|
||||
// Load HMAC keys from environment
|
||||
$hmacKeys = $_ENV['REQUEST_SIGNING_HMAC_KEYS'] ?? '';
|
||||
if ($hmacKeys) {
|
||||
$hmacKeys = $env->getString('REQUEST_SIGNING_HMAC_KEYS', '');
|
||||
if ($hmacKeys !== '') {
|
||||
$keys = json_decode($hmacKeys, true);
|
||||
if (is_array($keys)) {
|
||||
foreach ($keys as $keyData) {
|
||||
@@ -138,8 +147,8 @@ final readonly class RequestSigningInitializer
|
||||
}
|
||||
|
||||
// Load RSA keys from environment
|
||||
$rsaKeys = $_ENV['REQUEST_SIGNING_RSA_KEYS'] ?? '';
|
||||
if ($rsaKeys) {
|
||||
$rsaKeys = $env->getString('REQUEST_SIGNING_RSA_KEYS', '');
|
||||
if ($rsaKeys !== '') {
|
||||
$keys = json_decode($rsaKeys, true);
|
||||
if (is_array($keys)) {
|
||||
foreach ($keys as $keyData) {
|
||||
|
||||
Reference in New Issue
Block a user