feat(vikon): move API token from .env to integration_credentials
- Rename VICON_TOKEN → VIKON_API_TOKEN in .env and config - Add ViconApiToken service reading from integration_credentials table - Update 3 Vicon services to use ViconApiToken instead of config() - Config/env kept as fallback for clean migration
This commit is contained in:
@@ -4,11 +4,15 @@ namespace App\Services\Vicon\DirectionStudy;
|
||||
|
||||
use App\Jobs\CreateDirectionStudy;
|
||||
use App\Jobs\CreateEducationalProgram;
|
||||
use App\Services\Vicon\ViconApiToken;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AdmissionPlanService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ViconApiToken $viconApiToken,
|
||||
) {}
|
||||
public function getLevelEducationCodes(object $campaign) : array
|
||||
{
|
||||
return array_map(function ($item) {
|
||||
@@ -28,7 +32,7 @@ class AdmissionPlanService
|
||||
try {
|
||||
$response = $this->callAPI(
|
||||
"https://db-nica.ru/api/v1/campaigns",
|
||||
config('services.vicon.token')
|
||||
$this->viconApiToken->get()
|
||||
);
|
||||
if (!is_array($response)) {
|
||||
Log::channel('app')->warning('Unexpected response type in getCampaigns', [
|
||||
@@ -52,7 +56,7 @@ class AdmissionPlanService
|
||||
try {
|
||||
$response = $this->callAPI(
|
||||
"https://db-nica.ru/api/v1/planPriema/$campaign_levels_code",
|
||||
config('services.vicon.token')
|
||||
$this->viconApiToken->get()
|
||||
);
|
||||
|
||||
if (!is_object($response)) {
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
|
||||
namespace App\Services\Vicon\DirectionStudy;
|
||||
|
||||
use App\Services\Vicon\ViconApiToken;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DirectionStudyService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ViconApiToken $viconApiToken,
|
||||
) {}
|
||||
const EDU_LEVELS = [1, 2, 3, 4, 5, 6];
|
||||
|
||||
public function getAllNaprsUuid() : array
|
||||
@@ -40,31 +44,31 @@ class DirectionStudyService
|
||||
|
||||
public function getNaprs(int $edu_level): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/naprs?perPage=200&filter_edu_level=$edu_level", config('services.vicon.token'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/naprs?perPage=200&filter_edu_level=$edu_level", $this->viconApiToken->get());
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNapr(string $uuid): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/napr/$uuid", config('services.vicon.token'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/napr/$uuid", $this->viconApiToken->get());
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPrograms(int $edu_level): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", config('services.vicon.token'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", $this->viconApiToken->get());
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getProgram(string $uuid): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", config('services.vicon.token'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", $this->viconApiToken->get());
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getProgramDocs(string $uuid): object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid/edu-docs?perPage=200", config('services.vicon.token'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid/edu-docs?perPage=200", $this->viconApiToken->get());
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,15 @@ namespace App\Services\Vicon\EducationalProgram;
|
||||
|
||||
use App\Jobs\CreateDirectionStudy;
|
||||
use App\Jobs\CreateEducationalProgram;
|
||||
use App\Services\Vicon\ViconApiToken;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class EducationalProgramService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ViconApiToken $viconApiToken,
|
||||
) {}
|
||||
const EDU_LEVELS = [1,2,3,4,5,6];
|
||||
|
||||
public function getAllProgramsUuid() : array
|
||||
@@ -27,13 +31,13 @@ class EducationalProgramService
|
||||
|
||||
public function getPrograms(int $edu_level) : object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", config('services.vicon.token'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/programs?filter_edu_level=$edu_level&perPage=200", $this->viconApiToken->get());
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getProgram(string $uuid) : object
|
||||
{
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", config('services.vicon.token'));
|
||||
$data = $this->callAPI("https://db-nica.ru/api/v1/program/$uuid", $this->viconApiToken->get());
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Vicon;
|
||||
|
||||
use App\Containers\Dashboard\Tasks\IntegrationCredentials\GetIntegrationCredentialTask;
|
||||
|
||||
class ViconApiToken
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GetIntegrationCredentialTask $getCredential,
|
||||
) {}
|
||||
|
||||
public function get(): string
|
||||
{
|
||||
$credential = $this->getCredential->run('vikon_api');
|
||||
|
||||
if (!$credential || empty($credential->payload['token'])) {
|
||||
throw new \RuntimeException('VIKON API token not configured. Add it in /dashboard/integration-credentials.');
|
||||
}
|
||||
|
||||
return $credential->payload['token'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user