You are here

final class SDKConnector in Apigee Edge 8

Same name in this branch
  1. 8 src/SDKConnector.php \Drupal\apigee_edge\SDKConnector
  2. 8 modules/apigee_edge_debug/src/SDKConnector.php \Drupal\apigee_edge_debug\SDKConnector
  3. 8 tests/modules/apigee_edge_test/src/SDKConnector.php \Drupal\apigee_edge_test\SDKConnector

Service decorator for SDKConnector.

Hierarchy

Expanded class hierarchy of SDKConnector

1 string reference to 'SDKConnector'
apigee_edge_test.services.yml in tests/modules/apigee_edge_test/apigee_edge_test.services.yml
tests/modules/apigee_edge_test/apigee_edge_test.services.yml
1 service uses SDKConnector
apigee_edge_test.sdk_connector in tests/modules/apigee_edge_test/apigee_edge_test.services.yml
Drupal\apigee_edge_test\SDKConnector

File

tests/modules/apigee_edge_test/src/SDKConnector.php, line 42

Namespace

Drupal\apigee_edge_test
View source
final class SDKConnector extends DecoratedSDKConnector implements SDKConnectorInterface {

  /**
   * The decorated SDK connector service.
   *
   * @var \Drupal\apigee_edge\SDKConnector
   */
  private $innerService;

  /**
   * A logger instance.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  private $logger;

  /**
   * Constructs a new SDKConnector.
   *
   * @param \Drupal\apigee_edge\SDKConnectorInterface $inner_service
   *   The decorated SDK connector service.
   * @param \Drupal\Core\Logger\LoggerChannelInterface $logger
   *   Logger interface.
   * @param \Drupal\Core\Http\ClientFactory $clientFactory
   *   Http client.
   * @param \Drupal\key\KeyRepositoryInterface $key_repository
   *   The key repository.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager service.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   Module handler service.
   * @param \Drupal\Core\Extension\InfoParserInterface $infoParser
   *   Info file parser service.
   */
  public function __construct(SDKConnectorInterface $inner_service, LoggerChannelInterface $logger, ClientFactory $clientFactory, KeyRepositoryInterface $key_repository, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $moduleHandler, InfoParserInterface $infoParser) {
    $this->innerService = $inner_service;
    $this->logger = $logger;
    parent::__construct($clientFactory, $key_repository, $entity_type_manager, $config_factory, $moduleHandler, $infoParser);
  }

  /**
   * {@inheritdoc}
   */
  public function buildClient(Authentication $authentication, ?string $endpoint = NULL, array $options = []) : ClientInterface {
    $decider = function (RequestInterface $request, Exception $e) {

      // Only retry API calls that failed with this specific error.
      if ($e instanceof ApiResponseException && $e
        ->getEdgeErrorCode() === 'messaging.adaptors.http.flow.ApplicationNotFound') {
        $this->logger
          ->warning('Restarting request because it failed. {error_code}: {exception}.', [
          'error_code' => $e
            ->getEdgeErrorCode(),
          'exception' => $e
            ->getMessage(),
        ]);
        return TRUE;
      }
      return FALSE;
    };

    // Use the retry plugin in tests.
    return $this->innerService
      ->buildClient($authentication, $endpoint, [
      Client::CONFIG_RETRY_PLUGIN_CONFIG => [
        'retries' => 5,
        'exception_decider' => $decider,
        'exception_delay' => function (RequestInterface $request, Exception $e, $retries) : int {
          return $retries * 15000000;
        },
      ],
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function httpClientConfiguration() : array {
    return $this->innerService
      ->httpClientConfiguration();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SDKConnector::$client private static property The client object.
SDKConnector::$clientFactory private property The HTTP client factory.
SDKConnector::$configFactory protected property The config factory.
SDKConnector::$credentials private static property The currently used credentials object.
SDKConnector::$entityTypeManager protected property The entity type manager.
SDKConnector::$infoParser protected property The info parser.
SDKConnector::$innerService private property The decorated SDK connector service.
SDKConnector::$keyRepository protected property The key repository.
SDKConnector::$logger private property A logger instance.
SDKConnector::$moduleHandler protected property The module handler service.
SDKConnector::$userAgentPrefix private static property Custom user agent prefix.
SDKConnector::buildClient public function Returns a pre-configured API client with the provided credentials. Overrides SDKConnector::buildClient
SDKConnector::buildCredentials private function Builds credentials, which depends on the KeyType of the key entity.
SDKConnector::getClient public function Returns the http client. Overrides SDKConnectorInterface::getClient
SDKConnector::getCredentials private function Returns the credentials object used by the API client.
SDKConnector::getOrganization public function Gets the organization. Overrides SDKConnectorInterface::getOrganization
SDKConnector::httpClientConfiguration protected function Get HTTP client overrides for Apigee Edge API client. Overrides SDKConnector::httpClientConfiguration
SDKConnector::setCredentials private function Changes credentials used by the API client.
SDKConnector::testConnection public function Test connection with the Edge Management Server. Overrides SDKConnectorInterface::testConnection
SDKConnector::userAgentPrefix protected function Generates a custom user agent prefix.
SDKConnector::__construct public function Constructs a new SDKConnector. Overrides SDKConnector::__construct