diff --git a/.env b/.env index 2d1c753..bc50ff4 100644 --- a/.env +++ b/.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_PASSPHRASE=8b9154df37ffa91ef9186ce095324e39e50ff3b023bb1ed34383abd019ba4515 ###< 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 ### \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml index 52a86a4..31634f6 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -9,6 +9,12 @@ services: autowire: true # Automatically injects dependencies in your services. 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\: resource: '../src/' exclude: diff --git a/src/Service/UDS/UDSClient.php b/src/Service/UDS/UDSClient.php new file mode 100644 index 0000000..fa7fde2 --- /dev/null +++ b/src/Service/UDS/UDSClient.php @@ -0,0 +1,88 @@ +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 + ]); + } +} \ No newline at end of file