You are here

abstract class EdgeKeyTypeBase in Apigee Edge 8

Defines a base class for Apigee Edge Key Type plugins.

Hierarchy

Expanded class hierarchy of EdgeKeyTypeBase

1 file declares its use of EdgeKeyTypeBase
ApigeeAuthKeyType.php in src/Plugin/KeyType/ApigeeAuthKeyType.php

File

src/Plugin/EdgeKeyTypeBase.php, line 33

Namespace

Drupal\apigee_edge\Plugin
View source
abstract class EdgeKeyTypeBase extends KeyTypeBase implements EdgeKeyTypeInterface {

  /**
   * {@inheritdoc}
   */
  public function serialize(array $array) {
    return Json::encode($array);
  }

  /**
   * {@inheritdoc}
   */
  public function unserialize($value) {
    return Json::decode($value);
  }

  /**
   * {@inheritdoc}
   */
  public function getAuthenticationType(KeyInterface $key) : string {
    if ($this
      ->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
      if ($this
        ->useGcpDefaultServiceAccount($key)) {
        return EdgeKeyTypeInterface::EDGE_AUTH_TYPE_DEFAULT_GCE_SERVICE_ACCOUNT;
      }
      else {
        return EdgeKeyTypeInterface::EDGE_AUTH_TYPE_JWT;
      }
    }
    if (!isset($key
      ->getKeyValues()['auth_type'])) {
      throw new AuthenticationKeyValueMalformedException('auth_type');
    }
    return $key
      ->getKeyValues()['auth_type'];
  }

  /**
   * {@inheritdoc}
   */
  public function getEndpoint(KeyInterface $key) : string {
    if ($this
      ->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
      return ClientInterface::APIGEE_ON_GCP_ENDPOINT;
    }
    elseif ($this
      ->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC) {
      return Client::EDGE_ENDPOINT;
    }
    return $key
      ->getKeyValues()['endpoint'];
  }

  /**
   * {@inheritdoc}
   */
  public function getEndpointType(KeyInterface $key) : string {
    if ($this
      ->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC) {

      /* @phpstan-ignore-next-line */
      return EdgeKeyTypeInterface::EDGE_ENDPOINT_TYPE_DEFAULT;
    }

    /* @phpstan-ignore-next-line */
    return EdgeKeyTypeInterface::EDGE_ENDPOINT_TYPE_CUSTOM;
  }

  /**
   * {@inheritdoc}
   */
  public function getInstanceType(KeyInterface $key) : string {
    $key_values = $key
      ->getKeyValues();
    if (isset($key_values['instance_type'])) {
      return $key_values['instance_type'];
    }

    // Backwards compatibility, before Hybrid support.
    if (empty($key_values['endpoint']) || $key_values['endpoint'] === ClientInterface::EDGE_ENDPOINT) {
      return EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC;
    }
    return EdgeKeyTypeInterface::INSTANCE_TYPE_PRIVATE;
  }

  /**
   * {@inheritdoc}
   */
  public function getOrganization(KeyInterface $key) : string {
    if (!isset($key
      ->getKeyValues()['organization'])) {
      throw new AuthenticationKeyValueMalformedException('organization');
    }
    return $key
      ->getKeyValues()['organization'];
  }

  /**
   * {@inheritdoc}
   */
  public function getUsername(KeyInterface $key) : string {
    if (!isset($key
      ->getKeyValues()['username'])) {
      throw new AuthenticationKeyValueMalformedException('username');
    }
    return $key
      ->getKeyValues()['username'];
  }

  /**
   * {@inheritdoc}
   */
  public function getPassword(KeyInterface $key) : string {
    if (!isset($key
      ->getKeyValues()['password'])) {
      throw new AuthenticationKeyValueMalformedException('password');
    }
    return $key
      ->getKeyValues()['password'];
  }

  /**
   * {@inheritdoc}
   */
  public function getAuthorizationServer(KeyInterface $key) : string {
    return $key
      ->getKeyValues()['authorization_server'] ?? Oauth::DEFAULT_AUTHORIZATION_SERVER;
  }

  /**
   * {@inheritdoc}
   */
  public function getClientId(KeyInterface $key) : string {
    return $key
      ->getKeyValues()['client_id'] ?? Oauth::DEFAULT_CLIENT_ID;
  }

  /**
   * {@inheritdoc}
   */
  public function getClientSecret(KeyInterface $key) : string {
    return $key
      ->getKeyValues()['client_secret'] ?? Oauth::DEFAULT_CLIENT_SECRET;
  }

  /**
   * {@inheritdoc}
   */
  public function getAccountKey(KeyInterface $key) : array {
    $value = $key
      ->getKeyValues()['account_json_key'] ?? '';
    $json = json_decode($value, TRUE);
    if (empty($json['private_key']) || empty($json['client_email'])) {
      throw new AuthenticationKeyValueMalformedException('account_json_key');
    }
    return $json;
  }

  /**
   * {@inheritdoc}
   */
  public function useGcpDefaultServiceAccount(KeyInterface $key) : bool {
    return !empty($key
      ->getKeyValues()['gcp_hosted']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EdgeKeyTypeBase::getAccountKey public function Return the JSON account key decoded as an array. Overrides EdgeKeyTypeInterface::getAccountKey
EdgeKeyTypeBase::getAuthenticationType public function Gets the authentication type. Overrides EdgeKeyTypeInterface::getAuthenticationType
EdgeKeyTypeBase::getAuthorizationServer public function Gets the authorization server. Overrides EdgeKeyTypeInterface::getAuthorizationServer
EdgeKeyTypeBase::getClientId public function Gets the client ID. Overrides EdgeKeyTypeInterface::getClientId
EdgeKeyTypeBase::getClientSecret public function Gets the client secret. Overrides EdgeKeyTypeInterface::getClientSecret
EdgeKeyTypeBase::getEndpoint public function Gets the API endpoint. Overrides EdgeKeyTypeInterface::getEndpoint
EdgeKeyTypeBase::getEndpointType public function Gets the API endpoint type (default or custom). Overrides EdgeKeyTypeInterface::getEndpointType
EdgeKeyTypeBase::getInstanceType public function Gets the instance type (public, private or hybrid). Overrides EdgeKeyTypeInterface::getInstanceType
EdgeKeyTypeBase::getOrganization public function Gets the API organization. Overrides EdgeKeyTypeInterface::getOrganization
EdgeKeyTypeBase::getPassword public function Gets the API password. Overrides EdgeKeyTypeInterface::getPassword
EdgeKeyTypeBase::getUsername public function Gets the API username. Overrides EdgeKeyTypeInterface::getUsername
EdgeKeyTypeBase::serialize public function Serialize an array of key values into a string. Overrides KeyTypeMultivalueInterface::serialize
EdgeKeyTypeBase::unserialize public function Unserialize a string of key values into an array. Overrides KeyTypeMultivalueInterface::unserialize
EdgeKeyTypeBase::useGcpDefaultServiceAccount public function Return if you should use the Default Service account. Overrides EdgeKeyTypeInterface::useGcpDefaultServiceAccount
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC constant ID of the basic authentication method.
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_DEFAULT_GCE_SERVICE_ACCOUNT constant
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_JWT constant ID of the JWT authentication method.
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH constant ID of the OAuth authentication method.
EdgeKeyTypeInterface::EDGE_ENDPOINT_TYPE_CUSTOM Deprecated constant The endpoint type for custom.
EdgeKeyTypeInterface::EDGE_ENDPOINT_TYPE_DEFAULT Deprecated constant The endpoint type for default.
EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID public constant Apigee instance on hybrid cloud.
EdgeKeyTypeInterface::INSTANCE_TYPE_PRIVATE public constant Apigee instance on private cloud.
EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC public constant Apigee instance on public cloud.
KeyPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
KeyPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
KeyPluginBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 8
KeyPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
KeyPluginBase::getPluginType public function Returns the type of plugin. Overrides KeyPluginInterface::getPluginType
KeyPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
KeyPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
KeyTypeAuthenticationMethodInterface::getAuthenticationMethod public function Gets the authentication method object. 1
KeyTypeInterface::generateKeyValue public static function Generate a key value of this type using the submitted configuration. 4
KeyTypeInterface::validateKeyValue public function Allows the Key Type plugin to validate the key value. 4
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.