Test ogdClient
testing/ogcore-api/pipeline/head This commit looks good Details

pull/12/head
Manuel Aranda Rosales 2024-10-23 10:28:14 +02:00
parent f13731a047
commit 4973be6af6
1 changed files with 17 additions and 6 deletions

View File

@ -22,11 +22,25 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsController]
class StatusAction extends AbstractController
{
protected readonly HttpClientInterface $httpClient;
public function __construct(
protected readonly EntityManagerInterface $entityManager,
protected readonly HttpClientInterface $httpClient
) {}
)
{
$this->httpClient = HttpClient::create([
'verify_peer' => false,
'verify_host' => false,
]);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(Client $client): JsonResponse
{
if (!$client->getIp()) {
@ -34,10 +48,7 @@ class StatusAction extends AbstractController
}
try {
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status', [
'verify_peer' => false,
'verify_host' => false,
]);
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status');
$statusCode = $response->getStatusCode();
$client->setStatus($statusCode === Response::HTTP_OK ? 'active' : 'off');