refs #1154. API env_vars
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
testing/ogcore-api/pipeline/head There was a failure building this commit
Details
parent
116a773b6e
commit
404ee80d68
|
@ -4,22 +4,16 @@ imports:
|
|||
parameters:
|
||||
|
||||
services:
|
||||
App\DependencyInjection\JsonEnvVarLoader:
|
||||
tags: ['container.env_var_loader']
|
||||
|
||||
_defaults:
|
||||
autowire: true # Automatically injects dependencies in your services.
|
||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
||||
|
||||
bind:
|
||||
$ogBootApiUrl: '%env(OGBOOT_API_URL)%'
|
||||
$ogDhcpApiUrl: '%env(OGDHCP_API_URL)%'
|
||||
$udsAPIurl: '%env(UDS_URL)%'
|
||||
$udsAuthLogin: '%env(UDS_AUTH_LOGIN)%'
|
||||
$udsAuthUsername: '%env(UDS_AUTH_USERNAME)%'
|
||||
$udsAuthPassword: '%env(UDS_AUTH_PASSWORD)%'
|
||||
|
||||
App\:
|
||||
resource: '../src/'
|
||||
exclude:
|
||||
- '../src/DependencyInjection/'
|
||||
- '../src/Entity/'
|
||||
- '../src/Kernel.php'
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
xdebug.mode=debug
|
||||
xdebug.start_with_request=trigger
|
||||
xdebug.discover_client_host = 1
|
||||
xdebug.client_host=${XDEBUG_CLIENT_HOST}
|
||||
xdebug.client_port=${XDEBUG_CLIENT_PORT}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\DependencyInjection\JsonEnvVarLoader;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class EnvDataController extends AbstractController
|
||||
{
|
||||
private const string ENV_VARS_FILE = 'env.json';
|
||||
|
||||
public function __construct(
|
||||
private readonly KernelInterface $kernel
|
||||
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/env-vars', methods: ['GET'])]
|
||||
public function getEnvVars(): JsonResponse
|
||||
{
|
||||
$projectDir = $this->kernel->getProjectDir();
|
||||
|
||||
$fileName = $projectDir . DIRECTORY_SEPARATOR . self::ENV_VARS_FILE;
|
||||
if (!is_file($fileName)) {
|
||||
throw new \RuntimeException('File not found: '.$fileName);
|
||||
}
|
||||
|
||||
$content = json_decode(file_get_contents($fileName), true);
|
||||
|
||||
return new JsonResponse(['vars' => $content['vars']]);
|
||||
}
|
||||
|
||||
#[Route('/env-vars', methods: ['POST'])]
|
||||
public function updateEnvVars(Request $request): JsonResponse
|
||||
{
|
||||
$data = json_decode($request->getContent(), true);
|
||||
$projectDir = $this->kernel->getProjectDir();
|
||||
|
||||
$fileName = $projectDir . DIRECTORY_SEPARATOR . self::ENV_VARS_FILE;
|
||||
|
||||
if (!isset($data['vars']) || !is_array($data['vars'])) {
|
||||
return new JsonResponse(['error' => 'Invalid payload'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
|
||||
if ($json === false) {
|
||||
throw new \RuntimeException('Failed to encode JSON: ' . json_last_error_msg());
|
||||
}
|
||||
|
||||
if (file_put_contents($fileName, $json) === false) {
|
||||
throw new \RuntimeException('Failed to write to file: ' . self::ENV_VARS_FILE);
|
||||
}
|
||||
|
||||
return new JsonResponse(['message' => 'Variables updated successfully']);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ namespace App\Controller\OgBoot;
|
|||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
|
@ -20,7 +21,8 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|||
abstract class AbstractOgBootController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly string $ogBootApiUrl,
|
||||
#[Autowire(env: 'OG_BOOT_API_URL')]
|
||||
private string $ogBootApiUrl,
|
||||
protected readonly EntityManagerInterface $entityManager
|
||||
)
|
||||
{
|
||||
|
|
|
@ -36,23 +36,24 @@ class PostAction extends AbstractOgBootController
|
|||
'mac' => strtolower($client->getMac()),
|
||||
'lang' => 'es_ES.UTF_8',
|
||||
'ip' => $client->getIp(),
|
||||
'server_ip' => '192.168.2.4',
|
||||
//'server_ip' => '192.168.2.4', //rootServer (ogCore)
|
||||
'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(),
|
||||
'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0',
|
||||
'computer_name' => $client->getName(),
|
||||
'netiface' => $client->getNetiface(),
|
||||
'group' => $client->getOrganizationalUnit()->getName(),
|
||||
'ogrepo' => $client->getRepository() ? $client->getRepository()->getIpAddress() : '192.168.2.4',
|
||||
'oglive' => '192.168.2.4',
|
||||
'ogrepo' => $client->getRepository() ? $client->getRepository()->getIp() : '192.168.2.4',
|
||||
//'ogcore' => 'parametro_consola',
|
||||
//'oglive' => '192.168.2.4',
|
||||
'oglog' => '192.168.2.4',
|
||||
'ogshare' => '192.168.2.4',
|
||||
'oglivedir' => 'ogLive',
|
||||
'ogprof' => 'false',
|
||||
//'ogshare' => '192.168.2.4',
|
||||
'oglivedir' => $client->getOgLive()->getFilename(),
|
||||
'ogprof' => 'false', // cliente del profesor
|
||||
'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default',
|
||||
'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(),
|
||||
'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(),
|
||||
'ogProxy' => $client->getOrganizationalUnit()->getNetworkSettings()?->getProxy(),
|
||||
'ogunit' => '',
|
||||
'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(), //optional
|
||||
'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(), //optional
|
||||
'ogProxy' => $client->getOrganizationalUnit()->getNetworkSettings()?->getProxy(), //optional
|
||||
// 'ogunit' => '', //eliminar
|
||||
'resolution' => '788'
|
||||
];
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace App\Controller\OgDhcp;
|
|||
use App\Service\Utils\GetIpAddressAndNetmaskFromCIDRService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
|
@ -21,6 +22,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|||
abstract class AbstractOgDhcpController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
#[Autowire(env: 'OG_DHCP_API_URL')]
|
||||
protected readonly string $ogDhcpApiUrl,
|
||||
protected readonly EntityManagerInterface $entityManager,
|
||||
protected readonly GetIpAddressAndNetmaskFromCIDRService $getIpAddressAndNetmaskFromCIDRService
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Model\OrganizationalUnitTypes;
|
|||
use App\Service\UDS\UDSClient;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
@ -16,6 +17,7 @@ class RemoteCalendarSyncUdsAction extends AbstractController
|
|||
{
|
||||
|
||||
public function __construct(
|
||||
#[Autowire(env: 'UDS_URL')]
|
||||
private readonly UDSClient $udsClient
|
||||
)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\EnvVarLoaderInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
final class JsonEnvVarLoader implements EnvVarLoaderInterface
|
||||
{
|
||||
private const string ENV_VARS_FILE = 'env.json';
|
||||
|
||||
public function __construct(
|
||||
private readonly KernelInterface $kernel
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function loadEnvVars(): array
|
||||
{
|
||||
$projectDir = $this->kernel->getProjectDir();
|
||||
|
||||
$fileName = $projectDir . DIRECTORY_SEPARATOR . self::ENV_VARS_FILE;
|
||||
if (!is_file($fileName)) {
|
||||
throw new \RuntimeException('File not found: '.$fileName);
|
||||
}
|
||||
|
||||
$content = json_decode(file_get_contents($fileName), true);
|
||||
|
||||
return $content['vars'];
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Service\OgBoot;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
|
@ -15,7 +16,8 @@ use Symfony\Component\HttpClient\HttpClient;
|
|||
readonly class StatusService
|
||||
{
|
||||
public function __construct(
|
||||
private string $ogBootApiUrl
|
||||
#[Autowire(env: 'OG_BOOT_API_URL')]
|
||||
private string $ogBootApiUrl
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Service\OgDhcp;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -10,10 +11,11 @@ use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
class StatusService
|
||||
readonly class StatusService
|
||||
{
|
||||
public function __construct(
|
||||
private string $ogDhcpApiUrl
|
||||
#[Autowire(env: 'OG_DHCP_API_URL')]
|
||||
private string $ogDhcpApiUrl
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Service\UDS;
|
|||
use AllowDynamicProperties;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -24,9 +25,13 @@ class UDSClient
|
|||
public function __construct(
|
||||
private HttpClientInterface $httpClient,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
#[Autowire(env: 'UDS_URL')]
|
||||
private string $udsAPIurl,
|
||||
#[Autowire(env: 'UDS_AUTH_LOGIN')]
|
||||
private string $udsAuthLogin,
|
||||
#[Autowire(env: 'UDS_AUTH_USERNAME')]
|
||||
private string $udsAuthUsername,
|
||||
#[Autowire(env: 'UDS_AUTH_PASSWORD')]
|
||||
private string $udsAuthPassword,
|
||||
)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue