28 lines
1.5 KiB
PHP
28 lines
1.5 KiB
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Inspiring;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
Artisan::command('activity:credential', function () {
|
|
// Provision only over a private stdin pipe, never argv/env or HTTP.
|
|
try {
|
|
$token = trim(stream_get_contents(STDIN, 256));
|
|
if (!preg_match('/^[a-f0-9]{40}$/D', $token)) { throw new \RuntimeException(); }
|
|
$response = \Illuminate\Support\Facades\Http::withToken($token, 'token')->timeout(10)
|
|
->withOptions(['allow_redirects' => false])->get('https://git.parsaaghayi.ir/api/v1/user');
|
|
if (!$response->successful() || $response->json('login') !== 'parsa') { throw new \RuntimeException(); }
|
|
$credential = \App\Models\ActivityCredential::find('gitea-parsa') ?? new \App\Models\ActivityCredential();
|
|
$credential->id = 'gitea-parsa';
|
|
$credential->token = $token;
|
|
$credential->save();
|
|
if ($credential->getRawOriginal('token') === $token || array_key_exists('token', $credential->toArray())) { throw new \RuntimeException(); }
|
|
\Illuminate\Support\Facades\Cache::forget('activity:v1:failed');
|
|
$this->info('Credential authenticated and stored encrypted; serialization hidden.');
|
|
} catch (\Throwable $e) { $this->error('Credential provisioning failed (details suppressed).'); return 1; }
|
|
return 0;
|
|
})->purpose('Store dedicated Gitea read:user token from private stdin');
|
|
|
|
Artisan::command('inspire', function () {
|
|
$this->comment(Inspiring::quote());
|
|
})->purpose('Display an inspiring quote')->hourly();
|