From d35e5f42ccc27807e93d4af8d30c3376567b3f53 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Fri, 16 Oct 2026 11:23:42 +0200 Subject: [PATCH] Make some curl options configurable to fix issue #19 --- .env | 4 ++++ config/services.yaml | 6 ++++++ src/Service/iTopClient.php | 15 +++++++++++---- tests/phpunit/iTopClientTest.php | 6 +++--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 3f3ff69..77dab44 100644 --- a/.env +++ b/.env @@ -54,3 +54,7 @@ APP_DATAMODEL_FILE="data/datamodel-production.xml" APP_LANGUAGE="FR FR" APP_LOG_LEVEL="info" APP_TOOLS_PREFIX="iTop-" +APP_CURL_CONNECT_TIMEOUT=120 +APP_CURL_TIMEOUT=120 +APP_CURL_SSL_VERIFYPEER=1 + diff --git a/config/services.yaml b/config/services.yaml index 6ec4f64..3f7bca4 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -12,6 +12,9 @@ parameters: app.language: '%env(APP_LANGUAGE)%' app.log_level: '%env(APP_LOG_LEVEL)%' app.tools_prefix: '%env(APP_TOOLS_PREFIX)%' + app.curl_connect_timeout: '%env(APP_CURL_CONNECT_TIMEOUT)%' + app.curl_timeout: '%env(int:APP_CURL_TIMEOUT)%' + app.curl_ssl_verify_peer: '%env(bool:APP_CURL_SSL_VERIFYPEER)%' services: _defaults: @@ -25,6 +28,9 @@ services: string $projectDir: '%kernel.project_dir%' string $datamodelFile: '%app.datamodel_file%' string $language: '%app.language%' + int $curlConnectTimeout: '%app.curl_connect_timeout%' + int $curlTimeout: '%app.curl_timeout%' + bool $curlSslVerifyPeer: '%app.curl_ssl_verify_peer%' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/Service/iTopClient.php b/src/Service/iTopClient.php index 297f321..49abe61 100644 --- a/src/Service/iTopClient.php +++ b/src/Service/iTopClient.php @@ -6,7 +6,14 @@ class iTopClient implements iTopClientInterface { - public function __construct(private Security $security, private LoggerInterface $mcpLogger, private string $iTopUrl) + public function __construct( + private Security $security, + private LoggerInterface $mcpLogger, + private string $iTopUrl, + private int $curlConnectTimeout, + private int $curlTimeout, + private bool $curlSslVerifyPeer + ) { } @@ -28,10 +35,10 @@ public function postJsonToItop(string $json): string CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "MCP-server", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect - CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect - CURLOPT_TIMEOUT => 120, // timeout on response + CURLOPT_CONNECTTIMEOUT => $this->curlConnectTimeout, // timeout on connect + CURLOPT_TIMEOUT => $this->curlTimeout, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects - CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks + CURLOPT_SSL_VERIFYPEER => $this->curlSslVerifyPeer, CURLOPT_POST => count($postData), CURLOPT_POSTFIELDS => http_build_query($postData), ]; diff --git a/tests/phpunit/iTopClientTest.php b/tests/phpunit/iTopClientTest.php index 3606e4e..6a0c868 100644 --- a/tests/phpunit/iTopClientTest.php +++ b/tests/phpunit/iTopClientTest.php @@ -24,19 +24,19 @@ public function setUp():void public function testGetRestEndpointShortNoSlash() { - $client = new iTopClient($this->security, $this->logger, 'http://www.itop.com/demo'); + $client = new iTopClient($this->security, $this->logger, 'http://www.itop.com/demo', 120, 120, false); $this->assertEquals('http://www.itop.com/demo/webservices/rest.php', $client->getRestEndpointUrl()); } public function testGetRestEndpointShortSlash() { - $client = new iTopClient($this->security, $this->logger, 'http://www.itop.com/demo/'); + $client = new iTopClient($this->security, $this->logger, 'http://www.itop.com/demo/', 120, 120, false); $this->assertEquals('http://www.itop.com/demo/webservices/rest.php', $client->getRestEndpointUrl()); } public function testGetRestEndpointLong() { - $client = new iTopClient($this->security, $this->logger, 'http://www.itop.com/demo/webservices/rest.php'); + $client = new iTopClient($this->security, $this->logger, 'http://www.itop.com/demo/webservices/rest.php', 120, 120, false); $this->assertEquals('http://www.itop.com/demo/webservices/rest.php', $client->getRestEndpointUrl()); } }