Split V5 dashboard behavior into domain controllers and policies, add agent token rotation/revocation, status reconciliation jobs, ingress firewall syncing, and canvas connection APIs. Add migrations for V5 status tracking, server capabilities, resource connection aliases, and revoked agent tokens.
100 lines
2.9 KiB
PHP
100 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\PersonalAccessToken;
|
|
use App\Models\V5\Application;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Validation\Rules\Password;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Laravel\Telescope\TelescopeServiceProvider;
|
|
use Stripe\StripeClient;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
if (App::isLocal()) {
|
|
$this->app->register(TelescopeServiceProvider::class);
|
|
}
|
|
|
|
$this->app->bind(StripeClient::class, fn () => new StripeClient(config('subscription.stripe_api_key')));
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
$this->configureCommands();
|
|
$this->configureMorphMap();
|
|
$this->configureModels();
|
|
$this->configurePasswords();
|
|
$this->configureSanctumModel();
|
|
$this->configureGitHubHttp();
|
|
|
|
}
|
|
|
|
private function configureCommands(): void
|
|
{
|
|
if (App::isProduction()) {
|
|
DB::prohibitDestructiveCommands();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Map v5 models to stable morph aliases so polymorphic rows survive class
|
|
* renames. Deliberately NOT enforced: v4 polymorphic relations store FQCNs
|
|
* and must keep resolving them.
|
|
*/
|
|
private function configureMorphMap(): void
|
|
{
|
|
Relation::morphMap([
|
|
'v5.application' => Application::class,
|
|
]);
|
|
}
|
|
|
|
private function configureModels(): void
|
|
{
|
|
// Disabled because it's causing issues with the application
|
|
// Model::shouldBeStrict();
|
|
}
|
|
|
|
private function configurePasswords(): void
|
|
{
|
|
Password::defaults(function () {
|
|
return App::isProduction()
|
|
? Password::min(8)
|
|
->mixedCase()
|
|
->letters()
|
|
->numbers()
|
|
->symbols()
|
|
->uncompromised()
|
|
: Password::min(8)->letters();
|
|
});
|
|
}
|
|
|
|
private function configureSanctumModel(): void
|
|
{
|
|
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
|
|
}
|
|
|
|
private function configureGitHubHttp(): void
|
|
{
|
|
Http::macro('GitHub', function (string $api_url, ?string $github_access_token = null) {
|
|
if ($github_access_token) {
|
|
return Http::withHeaders([
|
|
'X-GitHub-Api-Version' => '2022-11-28',
|
|
'Accept' => 'application/vnd.github.v3+json',
|
|
'Authorization' => "Bearer $github_access_token",
|
|
])->baseUrl($api_url);
|
|
} else {
|
|
return Http::withHeaders([
|
|
'Accept' => 'application/vnd.github.v3+json',
|
|
])->baseUrl($api_url);
|
|
}
|
|
});
|
|
}
|
|
}
|