refs #726. Temporal commit. Added UDS Service logic
parent
792eb8f7b9
commit
f6649231b6
7
.env
7
.env
|
@ -40,3 +40,10 @@ JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
|
||||||
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
|
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
|
||||||
JWT_PASSPHRASE=8b9154df37ffa91ef9186ce095324e39e50ff3b023bb1ed34383abd019ba4515
|
JWT_PASSPHRASE=8b9154df37ffa91ef9186ce095324e39e50ff3b023bb1ed34383abd019ba4515
|
||||||
###< lexik/jwt-authentication-bundle ###
|
###< lexik/jwt-authentication-bundle ###
|
||||||
|
|
||||||
|
###> UDS ###
|
||||||
|
UDS_AUTH_LOGIN="Usuarios locales"
|
||||||
|
UDS_AUTH_USERNAME="natiqindel"
|
||||||
|
UDS_AUTH_PASSWORD="correct horse battery staple"
|
||||||
|
UDS_URL=https://localhost:8087/uds/rest/
|
||||||
|
###< UDS ###
|
|
@ -9,6 +9,12 @@ services:
|
||||||
autowire: true # Automatically injects dependencies in your services.
|
autowire: true # Automatically injects dependencies in your services.
|
||||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
||||||
|
|
||||||
|
bind:
|
||||||
|
$udsAPIurl: '%env(UDS_URL)%'
|
||||||
|
$udsAuthLogin: '%env(UDS_AUTH_LOGIN)%'
|
||||||
|
$udsAuthUsername: '%env(UDS_AUTH_USERNAME)%'
|
||||||
|
$udsAuthPassword: '%env(UDS_AUTH_PASSWORD)%'
|
||||||
|
|
||||||
App\:
|
App\:
|
||||||
resource: '../src/'
|
resource: '../src/'
|
||||||
exclude:
|
exclude:
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service\UDS;
|
||||||
|
|
||||||
|
use AllowDynamicProperties;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
|
#[AllowDynamicProperties]
|
||||||
|
class UDSClient
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private HttpClientInterface $httpClient,
|
||||||
|
EntityManagerInterface $entityManager,
|
||||||
|
private string $udsAPIurl,
|
||||||
|
private string $udsAuthLogin,
|
||||||
|
private string $udsAuthUsername,
|
||||||
|
private string $udsAuthPassword,
|
||||||
|
string $token,
|
||||||
|
string $scrambler
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
*/
|
||||||
|
public function __invoke(): void
|
||||||
|
{
|
||||||
|
$this->login();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
*/
|
||||||
|
public function login(): void
|
||||||
|
{
|
||||||
|
$response = $this->httpClient->request('POST', $this->udsAPIurl . '/auth/login', [
|
||||||
|
'json' => [
|
||||||
|
'login' => $this->udsAuthLogin,
|
||||||
|
'username' => $this->udsAuthUsername,
|
||||||
|
'password' => $this->udsAuthPassword
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = json_decode($response->getContent(), true);
|
||||||
|
$this->token = $data['token'];
|
||||||
|
$this->scrambler = $data['scrambler'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
*/
|
||||||
|
public function getServicePools(): array
|
||||||
|
{
|
||||||
|
$response = $this->httpClient->request('GET', $this->udsAPIurl . '/servicespools/overview', [
|
||||||
|
'headers' => [
|
||||||
|
'X-Auth-Token' => $this->token,
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Scrambler' => $this->scrambler
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getServicePool(string $providerId, string $serviceId): array
|
||||||
|
{
|
||||||
|
$response = $this->httpClient->request('GET', $this->udsAPIurl . '/providers/' . $providerId .'/services/'. $serviceId, [
|
||||||
|
'headers' => [
|
||||||
|
'X-Auth-Token' => $this->token,
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Scrambler' => $this->scrambler
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setServicePool(string $serviceId, array $payload): void
|
||||||
|
{
|
||||||
|
$response = $this->httpClient->request('PUT', $this->udsAPIurl . '/servicespools/' . $serviceId, [
|
||||||
|
'headers' => [
|
||||||
|
'X-Auth-Token' => $this->token,
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Scrambler' => $this->scrambler
|
||||||
|
],
|
||||||
|
'json' => $payload
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue