Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 6 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/Service/iTopClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
{

}
Expand All @@ -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),
];
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/iTopClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Loading