+22
-1
@@ -4,17 +4,20 @@ namespace Jakach\Logging\Api;
|
||||
|
||||
use Jakach\Logging\Model\{LogSourceType, AlertStatus};
|
||||
use Jakach\Logging\Storage\{Database, Repository};
|
||||
use Jakach\Logging\RuleEngine\Engine;
|
||||
|
||||
class Router
|
||||
{
|
||||
private Repository $repo;
|
||||
private AuthMiddleware $auth;
|
||||
private Engine $engine;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$db = new Database();
|
||||
$this->repo = new Repository($db);
|
||||
$this->auth = new AuthMiddleware($this->repo);
|
||||
$this->engine = new Engine($this->repo);
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
@@ -27,7 +30,7 @@ class Router
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
$publicPaths = ['/health', '/oauth', '/auth/me', '/auth/logout'];
|
||||
$publicPaths = ['/health', '/oauth', '/auth/me', '/auth/logout', '/ingest'];
|
||||
$isPublic = false;
|
||||
foreach ($publicPaths as $pp) {
|
||||
if ($path === $pp || str_starts_with($path, $pp . '/')) {
|
||||
@@ -48,6 +51,8 @@ class Router
|
||||
$result = match (true) {
|
||||
$path === '/health' && $method === 'GET' => ['status' => 'ok'],
|
||||
|
||||
$path === '/ingest' && $method === 'POST' => $this->ingest(),
|
||||
|
||||
$path === '/auth/me' && $method === 'GET' => $this->getMe(),
|
||||
$path === '/auth/logout' && $method === 'POST' => $this->logout(),
|
||||
|
||||
@@ -195,4 +200,20 @@ class Router
|
||||
$this->repo->setAllowedUserTokens($tokens);
|
||||
return ['status' => 'saved', 'tokens' => $this->repo->getAllowedUserTokens()];
|
||||
}
|
||||
|
||||
private function ingest(): array
|
||||
{
|
||||
$body = json_decode(file_get_contents('php://input'), true);
|
||||
$line = $body['line'] ?? '';
|
||||
$source = $body['source'] ?? 'http';
|
||||
|
||||
if (empty($line)) {
|
||||
http_response_code(400);
|
||||
return ['error' => 'Missing "line" field'];
|
||||
}
|
||||
|
||||
$this->engine->evaluate($line, null);
|
||||
|
||||
return ['status' => 'ingested', 'line' => substr($line, 0, 100)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user