refs #734 Renemas oggitservice
parent
b1c699dbea
commit
64eba6f500
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
// src/OgGitBundle/Service/CurlRequestService.php
|
||||
|
||||
namespace App\OgGitBundle\Service;
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class CurlRequestService
|
||||
{
|
||||
|
||||
public function convertMaskToCIDR($mask)
|
||||
{
|
||||
$bits = 0;
|
||||
$mask = explode(".", $mask);
|
||||
|
||||
foreach ($mask as $octect)
|
||||
$bits += strlen(str_replace("0", "", decbin($octect)));
|
||||
|
||||
return $bits;
|
||||
}
|
||||
|
||||
|
||||
// src/Service/CurlRequestService.php
|
||||
|
||||
public function callOgLive($parameter)
|
||||
{
|
||||
// Ruta completa al script oglivecli
|
||||
$ogLiveCliPath = sprintf("%s/bin/oglivecli", dirname(dirname(dirname(__DIR__))));
|
||||
|
||||
// Dividir el parámetro en acción y argumentos
|
||||
$args = array_map('trim', explode(' ', $parameter));
|
||||
$action = array_shift($args);
|
||||
|
||||
// Registrar la acción y los argumentos
|
||||
syslog(LOG_INFO, 'action ' . $action);
|
||||
syslog(LOG_INFO, 'args ' . json_encode($args));
|
||||
|
||||
// Limpiar los argumentos de comillas innecesarias
|
||||
$cleanedArgs = array_map(function($arg) {
|
||||
return trim($arg, '\'\"');
|
||||
}, $args);
|
||||
// Construir el comando final sin añadir comillas alrededor de cada elemento
|
||||
$commandToRun = $ogLiveCliPath . ' ' . $action . ' ' . implode(' ', $cleanedArgs);
|
||||
|
||||
// Registrar el comando en syslog para depuración
|
||||
syslog(LOG_INFO, 'command ' . $commandToRun);
|
||||
|
||||
// Ejecutar el comando
|
||||
$output = shell_exec($commandToRun);
|
||||
syslog(LOG_INFO, 'output ' . $output);
|
||||
|
||||
// Decodificar la salida JSON si es posible
|
||||
$decodedOutput = json_decode($output, true);
|
||||
|
||||
return $decodedOutput;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
// src/OgGitBundle/Service/OgGitService.php
|
||||
|
||||
namespace App\OgGitBundle\Service;
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
class OgGitService
|
||||
{
|
||||
private $client;
|
||||
private $ogGitUrl;
|
||||
public function __construct(ParameterBagInterface $params)
|
||||
{
|
||||
// Obtener la URL de la variable de entorno OGGIT_URL
|
||||
$this->ogGitUrl = $params->get('OGGIT_URL');
|
||||
$this->client = new Client();
|
||||
}
|
||||
public function convertMaskToCIDR($mask)
|
||||
{
|
||||
$bits = 0;
|
||||
$mask = explode(".", $mask);
|
||||
|
||||
foreach ($mask as $octect)
|
||||
$bits += strlen(str_replace("0", "", decbin($octect)));
|
||||
|
||||
return $bits;
|
||||
}
|
||||
|
||||
public function isValidBranchName($name) {
|
||||
$output = null;
|
||||
$return_var = null;
|
||||
exec("git check-ref-format --branch " . escapeshellarg($name), $output, $return_var);
|
||||
# $output = exec("python3 ./gitlib.py " . escapeshellarg($name), $output, $return_var);
|
||||
return $return_var === 0;
|
||||
}
|
||||
|
||||
public function makeRequest(string $method, string $endpoint, array $params = [])
|
||||
{
|
||||
$url = $this->ogGitUrl . $endpoint;
|
||||
|
||||
try {
|
||||
$response = $this->client->request($method, $url, $params);
|
||||
$body = $response->getBody();
|
||||
return json_decode($body, true);
|
||||
} catch (\Exception $e) {
|
||||
return ['error' => 'No se pudo conectar con el servicio Python: ' . $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue