diff --git a/CHANGELOG.md b/CHANGELOG.md index daf4cba..641d32a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## UNRELEASED +### Added + +- Added `api_host` configuration property used by `NotifyDeploymentCommand` + ## v2.1.3 ### Added diff --git a/Command/NotifyDeploymentCommand.php b/Command/NotifyDeploymentCommand.php index 66dfd71..837ebcb 100644 --- a/Command/NotifyDeploymentCommand.php +++ b/Command/NotifyDeploymentCommand.php @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $exitCode = 0; foreach ($appNames as $appName) { - $response = $this->performRequest($this->newrelic->getApiKey(), $this->createPayload($appName, $input)); + $response = $this->performRequest($this->newrelic->getApiKey(), $this->createPayload($appName, $input), $this->newrelic->getApiHost()); switch ($response['status']) { case 200: @@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return $exitCode; } - public function performRequest(string $api_key, string $payload): array + public function performRequest(string $api_key, string $payload, ?string $api_host = null): array { $headers = [ \sprintf('x-api-key: %s', $api_key), @@ -116,7 +116,7 @@ public function performRequest(string $api_key, string $payload): array ]; $level = \error_reporting(0); - $content = \file_get_contents('https://api.newrelic.com/deployments.xml', false, \stream_context_create($context)); + $content = \file_get_contents(\sprintf('https://%s/deployments.xml', $api_host ?? 'api.newrelic.com'), false, \stream_context_create($context)); \error_reporting($level); if (false === $content) { $error = \error_get_last(); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index c248353..9033d38 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -37,6 +37,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('interactor')->end() ->booleanNode('twig')->defaultValue(\class_exists(Environment::class))->end() ->scalarNode('api_key')->defaultValue(null)->end() + ->scalarNode('api_host')->defaultValue(null)->end() ->scalarNode('license_key')->defaultValue(null)->end() ->scalarNode('application_name')->defaultValue(null)->end() ->arrayNode('deployment_names') diff --git a/DependencyInjection/EkinoNewRelicExtension.php b/DependencyInjection/EkinoNewRelicExtension.php index 5f174d1..11cf8f4 100644 --- a/DependencyInjection/EkinoNewRelicExtension.php +++ b/DependencyInjection/EkinoNewRelicExtension.php @@ -75,6 +75,7 @@ public function load(array $configs, ContainerBuilder $container): void '$licenseKey' => $config['license_key'], '$xmit' => $config['xmit'], '$deploymentNames' => $config['deployment_names'], + '$apiHost' => $config['api_host'], ] ); diff --git a/NewRelic/Config.php b/NewRelic/Config.php index e557c60..07c56dc 100644 --- a/NewRelic/Config.php +++ b/NewRelic/Config.php @@ -20,6 +20,7 @@ class Config { private $name; private $apiKey; + private $apiHost = null; private $licenseKey; private $xmit; private $customEvents; @@ -27,10 +28,11 @@ class Config private $customParameters; private $deploymentNames; - public function __construct(?string $name, string $apiKey = null, string $licenseKey = null, bool $xmit = false, array $deploymentNames = []) + public function __construct(?string $name, string $apiKey = null, string $licenseKey = null, bool $xmit = false, array $deploymentNames = [], ?string $apiHost = null) { $this->name = (!empty($name) ? $name : \ini_get('newrelic.appname')) ?: ''; $this->apiKey = $apiKey; + $this->apiHost = $apiHost; $this->licenseKey = (!empty($licenseKey) ? $licenseKey : \ini_get('newrelic.license')) ?: ''; $this->xmit = $xmit; $this->deploymentNames = $deploymentNames; @@ -105,6 +107,11 @@ public function getApiKey(): ?string return $this->apiKey; } + public function getApiHost(): ?string + { + return $this->apiHost; + } + public function getLicenseKey(): ?string { return $this->licenseKey; diff --git a/README.md b/README.md index 2f492b6..23b7a7a 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ ekino_new_relic: # as php ini-value deployment_names: ~ # default value is 'application_name', supports string array or semi-colon separated string api_key: # New Relic API + api_host: ~ # New Relic API Host (default value is api.newrelic.com, for EU should be set to api.eu.newrelic.com ) license_key: # New Relic license key (optional, default value is read from php.ini) xmit: false # if you want to record the metric data up to the point newrelic_set_appname is called, set this to true (default: false) logging: false # If true, logs all New Relic interactions to the Symfony log (default: false) diff --git a/Tests/NewRelic/ConfigTest.php b/Tests/NewRelic/ConfigTest.php index 36116b7..ac05759 100644 --- a/Tests/NewRelic/ConfigTest.php +++ b/Tests/NewRelic/ConfigTest.php @@ -20,10 +20,11 @@ class ConfigTest extends TestCase { public function testGeneric() { - $newRelic = new Config('Ekino', 'XXX'); + $newRelic = new Config('Ekino', 'XXX', null, false, [], 'api.host'); $this->assertSame('Ekino', $newRelic->getName()); $this->assertSame('XXX', $newRelic->getApiKey()); + $this->assertSame('api.host', $newRelic->getApiHost()); $this->assertEmpty($newRelic->getCustomEvents()); $this->assertEmpty($newRelic->getCustomMetrics()); @@ -75,5 +76,7 @@ public function testDefaults() $this->assertNotNull($newRelic->getLicenseKey()); $this->assertSame(\ini_get('newrelic.license') ?: '', $newRelic->getLicenseKey()); + + $this->assertNull($newRelic->getApiHost()); } }