public function Raven::alterPolicy in Raven: Sentry Integration 8.2
Same name and namespace in other branches
- 3.x src/Plugin/CspReportingHandler/Raven.php \Drupal\raven\Plugin\CspReportingHandler\Raven::alterPolicy()
Alter the provided policy according to the plugin settings.
Parameters
\Drupal\csp\Csp $policy: The policy to alter.
Overrides ReportingHandlerBase::alterPolicy
File
- src/
Plugin/ CspReportingHandler/ Raven.php, line 52
Class
- Raven
- CSP Reporting Plugin for a Sentry endpoint.
Namespace
Drupal\raven\Plugin\CspReportingHandlerCode
public function alterPolicy(Csp $policy) {
if (!class_exists(\Raven_Client::class)) {
return;
}
$config = $this->configFactory
->get('raven.settings');
try {
$dsn = \Raven_Client::parseDSN(empty($_SERVER['SENTRY_DSN']) ? $config
->get('public_dsn') : $_SERVER['SENTRY_DSN']);
} catch (\InvalidArgumentException $e) {
// Raven is incorrectly configured.
return;
}
$query = [
'sentry_key' => $dsn['public_key'],
];
if ($environment = empty($_SERVER['SENTRY_ENVIRONMENT']) ? $config
->get('environment') : $_SERVER['SENTRY_ENVIRONMENT']) {
$query['sentry_environment'] = $environment;
}
if ($release = empty($_SERVER['SENTRY_RELEASE']) ? $config
->get('release') : $_SERVER['SENTRY_RELEASE']) {
$query['sentry_release'] = $release;
}
$policy
->setDirective('report-uri', Url::fromUri(str_replace('/store/', '/security/', $dsn['server']), [
'query' => $query,
])
->toString());
}