mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 01:44:45 +02:00

* Remove old admin * Remove controller test * Remove unused exceptions * Remove unused files * More small tweaks * Fix doc block * Remove unused service * Restore these * Add back autoDeploy * Revert "Add back autoDeploy" This reverts commit 630c1e08acf8056ce8e612f376fcd00c23d90aea. * Add these back * Add back exception * Remove ApiController again --------- Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> Co-authored-by: Boy132 <mail@boy132.de> Co-authored-by: notCharles <charles@pelican.dev>
92 lines
3.3 KiB
PHP
92 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models;
|
|
use App\Models\ApiKey;
|
|
use App\Models\Node;
|
|
use App\Models\User;
|
|
use Dedoc\Scramble\Scramble;
|
|
use Dedoc\Scramble\Support\Generator\OpenApi;
|
|
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
|
use Filament\Support\Colors\Color;
|
|
use Filament\Support\Facades\FilamentColor;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use SocialiteProviders\Discord\Provider;
|
|
use SocialiteProviders\Manager\SocialiteWasCalled;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(Application $app): void
|
|
{
|
|
Relation::enforceMorphMap([
|
|
'allocation' => Models\Allocation::class,
|
|
'api_key' => Models\ApiKey::class,
|
|
'backup' => Models\Backup::class,
|
|
'database' => Models\Database::class,
|
|
'egg' => Models\Egg::class,
|
|
'egg_variable' => Models\EggVariable::class,
|
|
'schedule' => Models\Schedule::class,
|
|
'server' => Models\Server::class,
|
|
'ssh_key' => Models\UserSSHKey::class,
|
|
'task' => Models\Task::class,
|
|
'user' => Models\User::class,
|
|
]);
|
|
|
|
Http::macro(
|
|
'daemon',
|
|
fn (Node $node, array $headers = []) => Http::acceptJson()
|
|
->asJson()
|
|
->withToken($node->daemon_token)
|
|
->withHeaders($headers)
|
|
->withOptions(['verify' => (bool) $app->environment('production')])
|
|
->timeout(config('panel.guzzle.timeout'))
|
|
->connectTimeout(config('panel.guzzle.connect_timeout'))
|
|
->baseUrl($node->getConnectionAddress())
|
|
);
|
|
|
|
Sanctum::usePersonalAccessTokenModel(ApiKey::class);
|
|
|
|
$bearerTokens = fn (OpenApi $openApi) => $openApi->secure(SecurityScheme::http('bearer'));
|
|
Gate::define('viewApiDocs', fn () => true);
|
|
Scramble::registerApi('application', ['api_path' => 'api/application', 'info' => ['version' => '1.0']]);
|
|
Scramble::registerApi('client', ['api_path' => 'api/client', 'info' => ['version' => '1.0']])->afterOpenApiGenerated($bearerTokens);
|
|
Scramble::registerApi('remote', ['api_path' => 'api/remote', 'info' => ['version' => '1.0']])->afterOpenApiGenerated($bearerTokens);
|
|
|
|
Event::listen(function (SocialiteWasCalled $event) {
|
|
$event->extendSocialite('discord', Provider::class);
|
|
});
|
|
|
|
FilamentColor::register([
|
|
'danger' => Color::Red,
|
|
'gray' => Color::Zinc,
|
|
'info' => Color::Sky,
|
|
'primary' => Color::Blue,
|
|
'success' => Color::Green,
|
|
'warning' => Color::Amber,
|
|
]);
|
|
|
|
Gate::before(function (User $user, $ability) {
|
|
return $user->isRootAdmin() ? true : null;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Register application service providers.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
Scramble::extendOpenApi(fn (OpenApi $openApi) => $openApi->secure(SecurityScheme::http('bearer')));
|
|
Scramble::ignoreDefaultRoutes();
|
|
}
|
|
}
|