phase 2
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\ProcessEventJob;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EventIngestController extends Controller
|
||||
{
|
||||
public function store(Request $request, Project $project): JsonResponse
|
||||
{
|
||||
$payload = $request->json()->all();
|
||||
|
||||
if (empty($payload)) {
|
||||
return response()->json(['error' => 'Empty payload'], 400);
|
||||
}
|
||||
|
||||
ProcessEventJob::dispatch($project, $payload);
|
||||
|
||||
return response()->json(
|
||||
['id' => $payload['event_id'] ?? null],
|
||||
202,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Project;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AuthenticateDsn
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$project = $request->route('project');
|
||||
|
||||
if (! $project instanceof Project) {
|
||||
abort(404, 'Project not found.');
|
||||
}
|
||||
|
||||
$sentryKey = $this->extractSentryKey($request);
|
||||
|
||||
if (! $sentryKey || $sentryKey !== $project->dsn_public_key) {
|
||||
abort(401, 'Invalid DSN key.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the sentry_key from the query string or X-Sentry-Auth header.
|
||||
*
|
||||
* Header format: Sentry sentry_version=7, sentry_client=..., sentry_key=<key>
|
||||
*/
|
||||
private function extractSentryKey(Request $request): ?string
|
||||
{
|
||||
if ($key = $request->query('sentry_key')) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
$header = $request->header('X-Sentry-Auth', '');
|
||||
|
||||
if (preg_match('/sentry_key=([a-f0-9\-]+)/i', $header, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user