feat: api tokens + deploy webhook
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Actions\Database\StartPostgresql;
|
||||
use App\Models\Application;
|
||||
use App\Models\Service;
|
||||
use App\Models\StandaloneMongodb;
|
||||
use App\Models\StandalonePostgresql;
|
||||
use App\Models\StandaloneRedis;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -17,9 +25,46 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::get('/health', function () {
|
||||
return 'OK';
|
||||
});
|
||||
Route::group([
|
||||
'middleware' => ['auth:sanctum'],
|
||||
'prefix' => 'v1'
|
||||
], function () {
|
||||
Route::get('/deploy', function (Request $request) {
|
||||
$token = auth()->user()->currentAccessToken();
|
||||
$teamId = data_get($token, 'team_id');
|
||||
$uuid = $request->query->get('uuid');
|
||||
$force = $request->query->get('force') ?? false;
|
||||
|
||||
if (is_null($teamId)) {
|
||||
return response()->json(['error' => 'Invalid token.'], 400);
|
||||
}
|
||||
if (!$uuid) {
|
||||
return response()->json(['error' => 'No UUID provided.'], 400);
|
||||
}
|
||||
$resource = getResourceByUuid($uuid, $teamId);
|
||||
if ($resource) {
|
||||
$type = $resource->getMorphClass();
|
||||
if ($type === 'App\Models\Application') {
|
||||
queue_application_deployment(
|
||||
application_id: $resource->id,
|
||||
deployment_uuid: new Cuid2(7),
|
||||
force_rebuild: $force,
|
||||
);
|
||||
return response()->json(['message' => 'Deployment queued.'], 200);
|
||||
} else if ($type === 'App\Models\StandalonePostgresql') {
|
||||
StartPostgresql::run($resource);
|
||||
$resource->update([
|
||||
'started_at' => now(),
|
||||
]);
|
||||
return response()->json(['message' => 'Database started.'], 200);
|
||||
}
|
||||
}
|
||||
return response()->json(['error' => 'No resource found.'], 404);
|
||||
});
|
||||
});
|
||||
|
||||
Route::middleware(['throttle:5'])->group(function () {
|
||||
Route::get('/unsubscribe/{token}', function() {
|
||||
Route::get('/unsubscribe/{token}', function () {
|
||||
try {
|
||||
$token = request()->token;
|
||||
$email = decrypt($token);
|
||||
@@ -34,6 +79,5 @@ Route::middleware(['throttle:5'])->group(function () {
|
||||
} catch (\Throwable $e) {
|
||||
return 'Something went wrong. Please try again or contact support.';
|
||||
}
|
||||
|
||||
})->name('unsubscribe.marketing.emails');
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Http\Livewire\Dev\Compose as Compose;
|
||||
use App\Http\Livewire\Dashboard;
|
||||
use App\Http\Livewire\Project\CloneProject;
|
||||
use App\Http\Livewire\Project\Shared\Logs;
|
||||
use App\Http\Livewire\Security\ApiTokens;
|
||||
use App\Http\Livewire\Server\All;
|
||||
use App\Http\Livewire\Server\Create;
|
||||
use App\Http\Livewire\Server\Destination\Show as DestinationShow;
|
||||
@@ -164,6 +165,8 @@ Route::middleware(['auth'])->group(function () {
|
||||
Route::get('/security/private-key/{private_key_uuid}', fn () => view('security.private-key.show', [
|
||||
'private_key' => PrivateKey::ownedByCurrentTeam(['name', 'description', 'private_key', 'is_git_related'])->whereUuid(request()->private_key_uuid)->firstOrFail()
|
||||
]))->name('security.private-key.show');
|
||||
Route::get('/security/api-tokens', ApiTokens::class)->name('security.api-tokens');
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user