Skip to content

Commit

Permalink
[BUGS-5488] Do not accept debug option unless user has permission for…
Browse files Browse the repository at this point in the history
… it. (#155)

* Use new permission to set debug TRUE for guzzle.

* Fix coding standards.
  • Loading branch information
kporras07 authored Nov 23, 2022
1 parent c749cc2 commit baca1e8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ with the concept usage in a Solr context:
and throw errors on the pieces that are not working. This command will develop further as the module nears general availability.

* `drush search-api-pantheon:select` (`saps`) This command will run the given query against Solr server. It's recommended to use
`?debug=true` in any Solr page to get a good query to pass to this command to debug results.
`?debug=true` in any Solr page (having the right permissions) to get a good query to pass to this command to debug results.


* `drush search-api-pantheon:force-cleanup` (`sapfc`) This command will delete all of the contents for the given
Expand Down
4 changes: 4 additions & 0 deletions search_api_pantheon.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
access search_api_pantheon debug information:
title: 'Access Search API Pantheon debug information'
description: 'Provides access to debug information.'
restrict access: true
2 changes: 1 addition & 1 deletion search_api_pantheon.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
arguments: [[], '@entity_type.manager']
search_api_pantheon.pantheon_guzzle:
class: Drupal\search_api_pantheon\Services\PantheonGuzzle
arguments: ['@search_api_pantheon.endpoint', '@logger.factory']
arguments: ['@search_api_pantheon.endpoint', '@logger.factory', '@current_user']
search_api_pantheon.solarium_client:
class: Drupal\search_api_pantheon\Services\SolariumClient
arguments: ['@search_api_pantheon.pantheon_guzzle', '@search_api_pantheon.endpoint', '@logger.factory', '@event_dispatcher']
11 changes: 7 additions & 4 deletions src/Services/PantheonGuzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Solarium\Core\Client\Adapter\AdapterInterface;
use Solarium\Core\Client\Adapter\Psr18Adapter;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Session\AccountProxyInterface;

/**
* Pantheon-specific extension of the Guzzle http query class.
Expand All @@ -39,7 +40,7 @@ class PantheonGuzzle extends Client implements
/**
* Class Constructor.
*/
public function __construct(Endpoint $endpoint, LoggerChannelFactoryInterface $logger_factory) {
public function __construct(Endpoint $endpoint, LoggerChannelFactoryInterface $logger_factory, AccountProxyInterface $current_user) {
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(
Expand All @@ -59,13 +60,15 @@ public function __construct(Endpoint $endpoint, LoggerChannelFactoryInterface $l
$config = [
'base_uri' => $endpoint->getBaseUri(),
'http_errors' => FALSE,
// Putting `?debug=true` at the end of any Solr url will show you the low-level debugging from guzzle.
// @codingStandardsIgnoreLine
'debug' => (php_sapi_name() === 'cli' || isset($_GET['debug'])),
'debug' => FALSE,
'verify' => FALSE,
'handler' => $stack,
'allow_redirects' => FALSE,
];
// Putting `?debug=true` at the end of any Solr url will show you the low-level debugging from guzzle.
if ((php_sapi_name() === 'cli' || isset($_GET['debug'])) && $current_user->hasPermission('access search_api_pantheon debug information')) {
$config['debug'] = TRUE;
}
if (is_file($cert)) {
$config['cert'] = $cert;
}
Expand Down

0 comments on commit baca1e8

Please sign in to comment.