feat(vikon): rewrite VikonIntegration from scratch — OAuth + core update
- HttpTask: Laravel Http facade with SSL enabled, retry, timeout - ValidateTokenTask: token check via auth.db-nica.ru - RefreshTokenTask: token refresh via db-nica.ru - FilesystemTask: path traversal protection, blocked extensions (PHP/ASP/etc) - AuthenticateAction: OAuth2 code→token exchange - CheckAccessAction: token validation + filesystem writability check - CheckVersionAction: version comparison against remote API - UpdateCoreAction: ZIP download, Zip Slip protection, atomic sync with rollback - VikonController: thin controller, 7 endpoints with Session-based token storage - Routes: access-check, dashboard.auth, throttle:30,1 middleware - Vue 3 Composition API frontend with progress bar - Config: all secrets in .env via config/vikon.php - vikon_core kept as fallback (not deleted)
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\VikonIntegration\Tasks;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
|
||||
class HttpTask
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $apiDomain,
|
||||
private readonly string $authDomain,
|
||||
private readonly string $filemanagerDomain,
|
||||
private readonly int $timeout,
|
||||
private readonly int $retries,
|
||||
) {}
|
||||
|
||||
public function get(string $endpoint, array $params = [], string $service = 'api'): \Illuminate\Http\Client\Response
|
||||
{
|
||||
$url = $this->url($endpoint, $service);
|
||||
return $this->client()->get($url, $params);
|
||||
}
|
||||
|
||||
public function post(string $endpoint, array $data = [], string $service = 'api'): \Illuminate\Http\Client\Response
|
||||
{
|
||||
$url = $this->url($endpoint, $service);
|
||||
return $this->client()->post($url, $data);
|
||||
}
|
||||
|
||||
public function getWithToken(string $endpoint, string $token, string $service = 'api'): \Illuminate\Http\Client\Response
|
||||
{
|
||||
$url = $this->url($endpoint, $service);
|
||||
return $this->client()
|
||||
->withToken($token)
|
||||
->get($url);
|
||||
}
|
||||
|
||||
public function postWithToken(string $endpoint, string $token, array $data = [], string $service = 'api'): \Illuminate\Http\Client\Response
|
||||
{
|
||||
$url = $this->url($endpoint, $service);
|
||||
return $this->client()
|
||||
->withToken($token)
|
||||
->post($url, $data);
|
||||
}
|
||||
|
||||
public function downloadWithToken(string $endpoint, string $token, string $service = 'api'): string
|
||||
{
|
||||
$url = $this->url($endpoint, $service);
|
||||
$response = $this->client()
|
||||
->withToken($token)
|
||||
->withHeaders(['Accept-Encoding' => 'zip, gzip'])
|
||||
->get($url);
|
||||
|
||||
if ($response->failed()) {
|
||||
throw new \RuntimeException('Download failed: HTTP ' . $response->status());
|
||||
}
|
||||
|
||||
return $response->body();
|
||||
}
|
||||
|
||||
private function client(): PendingRequest
|
||||
{
|
||||
return Http::timeout($this->timeout)
|
||||
->retry($this->retries, 500)
|
||||
->withHeaders(['Accept' => 'application/json']);
|
||||
}
|
||||
|
||||
private function url(string $endpoint, string $service): string
|
||||
{
|
||||
$base = match ($service) {
|
||||
'auth' => $this->authDomain,
|
||||
'filemanager' => $this->filemanagerDomain,
|
||||
default => $this->apiDomain,
|
||||
};
|
||||
return rtrim($base, '/') . '/' . ltrim($endpoint, '/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user