Setzt Phase 1 aus Visualization.md um: Vanilla-PHP-REST-API mit SQLite-Persistenz, statischen API-Keys pro Agent, Codeberg-Sync fuer Backlog/Done, PHPUnit-Tests und vollstaendiger API.md-Dokumentation - Vorgaben aus Detailantworten.md (F1-F16) umgesetzt. Entwicklung/Build/Test laufen komplett in Docker-Compose-Containern (PHP 8.2 + SQLite + Composer + PHPUnit/pcov), analog zum NC-Gantt-Projekt ist auf dem Host kein PHP/Composer noetig. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
30 lines
761 B
PHP
30 lines
761 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Monitor\Api\Auth;
|
|
|
|
use Monitor\Api\Http\Request;
|
|
|
|
/**
|
|
* Schuetzt die Agenten-Registrierung (POST /api/v1/agents) mit einem einzelnen
|
|
* Administrator-Key aus der Umgebungsvariable MONITOR_ADMIN_API_KEY, damit nicht jeder
|
|
* beliebig neue Agenten (und damit API-Keys) anlegen kann.
|
|
*/
|
|
final class AdminAuthenticator
|
|
{
|
|
public function __construct(private readonly ?string $adminApiKey)
|
|
{
|
|
}
|
|
|
|
public function authenticate(Request $request): bool
|
|
{
|
|
if ($this->adminApiKey === null || $this->adminApiKey === '') {
|
|
return false;
|
|
}
|
|
|
|
$provided = $request->header('x-admin-key');
|
|
|
|
return $provided !== null && hash_equals($this->adminApiKey, $provided);
|
|
}
|
|
}
|