IcingaEndpoint: provide getRestApiClient() helper

fixes #877
This commit is contained in:
Thomas Gelf 2017-03-28 18:08:27 +02:00
parent f885d90a0a
commit 9f2070dced
1 changed files with 21 additions and 13 deletions

View File

@ -54,6 +54,19 @@ class IcingaEndpoint extends IcingaObject
{ {
$format = $this->connection->settings()->config_format; $format = $this->connection->settings()->config_format;
if ($format === 'v2') { if ($format === 'v2') {
return new CoreApi($this->getRestApiClient());
} elseif ($format === 'v1') {
return new LegacyDeploymentApi($this->connection);
} else {
throw new ProgrammingError('Unsupported config format: %s', $format);
}
}
/**
* @return RestApiClient
*/
public function getRestApiClient()
{
$client = new RestApiClient( $client = new RestApiClient(
$this->getResolvedProperty('host', $this->getObjectName()), $this->getResolvedProperty('host', $this->getObjectName()),
$this->getResolvedProperty('port') $this->getResolvedProperty('port')
@ -66,12 +79,7 @@ class IcingaEndpoint extends IcingaObject
$user->password $user->password
); );
return new CoreApi($client); return $client;
} elseif ($format === 'v1') {
return new LegacyDeploymentApi($this->connection);
} else {
throw new ProgrammingError('Unsupported config format: %s', $format);
}
} }
/** /**