mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 15:54:03 +02:00
ImportSourceRestApi: allow to override url
This commit is contained in:
parent
ed352ed8cc
commit
ad9b624e92
@ -16,57 +16,7 @@ class ImportSourceRestApi extends ImportSourceHook
|
|||||||
|
|
||||||
public function fetchData()
|
public function fetchData()
|
||||||
{
|
{
|
||||||
$url = $this->getSetting('url');
|
$result = $this->getRestApi()->get($this->getUrl());
|
||||||
$parts = \parse_url($url);
|
|
||||||
if (isset($parts['host'])) {
|
|
||||||
$host = $parts['host'];
|
|
||||||
} else {
|
|
||||||
throw new InvalidArgumentException("URL '$url' has no host");
|
|
||||||
}
|
|
||||||
|
|
||||||
$api = new RestApiClient(
|
|
||||||
$host,
|
|
||||||
$this->getSetting('username'),
|
|
||||||
$this->getSetting('password')
|
|
||||||
);
|
|
||||||
if (isset($parts['path'])) {
|
|
||||||
$path = $parts['path'];
|
|
||||||
} else {
|
|
||||||
$path = '/';
|
|
||||||
}
|
|
||||||
if (isset($parts['query'])) {
|
|
||||||
$url = "$path?" . $parts['query'];
|
|
||||||
} else {
|
|
||||||
$url = $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
$api->setScheme($this->getSetting('scheme'));
|
|
||||||
if (isset($parts['port'])) {
|
|
||||||
$api->setPort($parts['port']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($api->getScheme() === 'HTTPS') {
|
|
||||||
if ($this->getSetting('ssl_verify_peer', 'y') === 'n') {
|
|
||||||
$api->disableSslPeerVerification();
|
|
||||||
}
|
|
||||||
if ($this->getSetting('ssl_verify_host', 'y') === 'n') {
|
|
||||||
$api->disableSslHostVerification();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($proxy = $this->getSetting('proxy')) {
|
|
||||||
if ($proxyType = $this->getSetting('proxy_type')) {
|
|
||||||
$api->setProxy($proxy, $proxyType);
|
|
||||||
} else {
|
|
||||||
$api->setProxy($proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user = $this->getSetting('proxy_user')) {
|
|
||||||
$api->setProxyAuth($user, $this->getSetting('proxy_pass'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $api->get($url);
|
|
||||||
if ($property = $this->getSetting('extract_property')) {
|
if ($property = $this->getSetting('extract_property')) {
|
||||||
if (\property_exists($result, $property)) {
|
if (\property_exists($result, $property)) {
|
||||||
$result = $result->$property;
|
$result = $result->$property;
|
||||||
@ -255,6 +205,70 @@ class ImportSourceRestApi extends ImportSourceHook
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getUrl()
|
||||||
|
{
|
||||||
|
$url = $this->getSetting('url');
|
||||||
|
$parts = \parse_url($url);
|
||||||
|
if (isset($parts['path'])) {
|
||||||
|
$path = $parts['path'];
|
||||||
|
} else {
|
||||||
|
$path = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($parts['query'])) {
|
||||||
|
$url = "$path?" . $parts['query'];
|
||||||
|
} else {
|
||||||
|
$url = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRestApi()
|
||||||
|
{
|
||||||
|
$url = $this->getSetting('url');
|
||||||
|
$parts = \parse_url($url);
|
||||||
|
if (isset($parts['host'])) {
|
||||||
|
$host = $parts['host'];
|
||||||
|
} else {
|
||||||
|
throw new InvalidArgumentException("URL '$url' has no host");
|
||||||
|
}
|
||||||
|
|
||||||
|
$api = new RestApiClient(
|
||||||
|
$host,
|
||||||
|
$this->getSetting('username'),
|
||||||
|
$this->getSetting('password')
|
||||||
|
);
|
||||||
|
|
||||||
|
$api->setScheme($this->getSetting('scheme'));
|
||||||
|
if (isset($parts['port'])) {
|
||||||
|
$api->setPort($parts['port']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($api->getScheme() === 'HTTPS') {
|
||||||
|
if ($this->getSetting('ssl_verify_peer', 'y') === 'n') {
|
||||||
|
$api->disableSslPeerVerification();
|
||||||
|
}
|
||||||
|
if ($this->getSetting('ssl_verify_host', 'y') === 'n') {
|
||||||
|
$api->disableSslHostVerification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($proxy = $this->getSetting('proxy')) {
|
||||||
|
if ($proxyType = $this->getSetting('proxy_type')) {
|
||||||
|
$api->setProxy($proxy, $proxyType);
|
||||||
|
} else {
|
||||||
|
$api->setProxy($proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user = $this->getSetting('proxy_user')) {
|
||||||
|
$api->setProxyAuth($user, $this->getSetting('proxy_pass'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $api;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param QuickForm $form
|
* @param QuickForm $form
|
||||||
* @param string $key
|
* @param string $key
|
||||||
|
Loading…
x
Reference in New Issue
Block a user