You are here

private function SDKConnector::buildCredentials in Apigee Edge 8

Builds credentials, which depends on the KeyType of the key entity.

Parameters

\Drupal\key\KeyInterface $key: The key entity which stores the API credentials.

Return value

\Drupal\apigee_edge\CredentialsInterface The credentials.

2 calls to SDKConnector::buildCredentials()
SDKConnector::getCredentials in src/SDKConnector.php
Returns the credentials object used by the API client.
SDKConnector::testConnection in src/SDKConnector.php
Test connection with the Edge Management Server.

File

src/SDKConnector.php, line 232

Class

SDKConnector
Provides an Apigee Edge SDK connector.

Namespace

Drupal\apigee_edge

Code

private function buildCredentials(KeyInterface $key) : CredentialsInterface {

  /** @var \Drupal\apigee_edge\Plugin\EdgeKeyTypeInterface $key */
  if ($key
    ->getKeyType() instanceof EdgeKeyTypeInterface) {
    if ($key
      ->getKeyType()
      ->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
      return new HybridCredentials($key);
    }
    elseif ($key
      ->getKeyType()
      ->getAuthenticationType($key) === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH) {
      return new OauthCredentials($key);
    }
    return new Credentials($key);
  }
  else {
    throw new AuthenticationKeyException("Type of {$key->id()} key does not implement EdgeKeyTypeInterface.");
  }
}