-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from apigee-internal/drup-5-module-skeleton
Created module skeleton and the authentication form class.
- Loading branch information
Showing
30 changed files
with
1,262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
# apigee-drupal-module | ||
A Drupal 8 module that turns a site into a developer portal for Apigee's API management product | ||
|
||
# Testing | ||
|
||
To run the tests, some environment variables are needed. Creating a simple script is recommended: | ||
|
||
``` | ||
#!/bin/bash | ||
export EDGE_USERNAME="" | ||
export EDGE_PASSWORD="" | ||
export EDGE_ORGANIZATION="" | ||
php ./core/scripts/run-tests.sh --verbose --color --url "http://edge.test" ApigeeEdge | ||
``` | ||
|
||
Change the `--url` parameter to the site's url (it defaults to localhost, and sometimes it breaks the tests). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Apigee Edge | ||
description: Apigee Edge Drupal integration | ||
package: Apigee | ||
|
||
type: module | ||
core: 8.x | ||
|
||
dependencies: | ||
|
||
configure: apigee_edge.settings | ||
|
||
php: 7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Install, update and uninstall functions for Apigee Edge. | ||
*/ | ||
|
||
/** | ||
* Implements hook_requirements(). | ||
*/ | ||
function apigee_edge_requirements($phase) { | ||
$requirements = []; | ||
|
||
if ($phase == 'runtime') { | ||
$credentials_storage_plugin_manager = \Drupal::service('plugin.manager.apigee_edge.credentials_storage'); | ||
foreach ($credentials_storage_plugin_manager->getDefinitions() as $key => $value) { | ||
$credentials_storage_plugin = $credentials_storage_plugin_manager->createInstance($key); | ||
/** @var \Drupal\apigee_edge\CredentialsStoragePluginInterface $credentials_storage_plugin */ | ||
if (!empty($credentials_storage_plugin->hasRequirements())) { | ||
$requirements[$credentials_storage_plugin->getId()] = [ | ||
'title' => t('Apigee Edge'), | ||
'description' => $credentials_storage_plugin->hasRequirements(), | ||
'severity' => REQUIREMENT_WARNING, | ||
]; | ||
} | ||
} | ||
} | ||
|
||
return $requirements; | ||
} | ||
|
||
/** | ||
* Implements hook_uninstall(). | ||
*/ | ||
function apigee_edge_uninstall() { | ||
$credentials_storage_plugin_manager = \Drupal::service('plugin.manager.apigee_edge.credentials_storage'); | ||
|
||
foreach ($credentials_storage_plugin_manager->getDefinitions() as $key => $value) { | ||
$credentials_storage_plugin = $credentials_storage_plugin_manager->createInstance($key); | ||
/** @var \Drupal\apigee_edge\CredentialsStoragePluginInterface $credentials_storage_plugin */ | ||
$credentials_storage_plugin->deleteCredentials(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apigee_edge.admin: | ||
version: 1.1 | ||
css: | ||
theme: | ||
css/apigee_edge.admin.css: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apigee_edge.settings: | ||
title: 'Apigee Edge' | ||
description: 'Apigee Edge module settings.' | ||
parent: system.admin_config | ||
route_name: apigee_edge.settings | ||
weight: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Main module file for Apigee Edge. | ||
*/ | ||
|
||
use Apigee\Edge\Api\Management\Entity\Developer; | ||
use Apigee\Edge\Exception\ClientErrorException; | ||
use Drupal\user\UserInterface; | ||
|
||
/** | ||
* Implements hook_user_presave(). | ||
*/ | ||
function apigee_edge_user_presave(UserInterface $account) { | ||
$developer_data = [ | ||
'userName' => $account->getAccountName(), | ||
'email' => $account->getEmail(), | ||
'firstName' => $account->getAccountName(), | ||
'lastName' => $account->getAccountName(), | ||
]; | ||
|
||
try { | ||
/** @var \Apigee\Edge\Entity\EntityControllerFactory $ecf */ | ||
$ecf = \Drupal::service('apigee_edge.sdk_connector')->getEntityControllerFactory(); | ||
$ec = $ecf->getControllerByEndpoint('developers'); | ||
$developer = new Developer($developer_data); | ||
$ec->create($developer); | ||
} | ||
catch (ClientErrorException $exception) { | ||
$context = [ | ||
'@developer' => print_r($developer_data, TRUE), | ||
'@message' => (string) $exception, | ||
'@trace' => $exception->getTraceAsString(), | ||
]; | ||
if ($exception->getEdgeErrorCode() === 'developer.service.DeveloperAlreadyExists') { | ||
\Drupal::logger('apigee_edge')->notice('Developer is already exists. @developer, @message, @trace', $context); | ||
} | ||
else { | ||
\Drupal::logger('apigee_edge')->error('Could not save developer entity. @developer, @message, @trace', $context); | ||
} | ||
} | ||
catch (\Exception $exception) { | ||
$context = [ | ||
'@developer' => print_r($developer_data, TRUE), | ||
'@message' => (string) $exception, | ||
'@trace' => $exception->getTraceAsString(), | ||
]; | ||
\Drupal::logger('apigee_edge')->error('Could not save developer entity. @developer, @message, @trace', $context); | ||
} | ||
} | ||
|
||
/** | ||
* Implements hook_user_delete(). | ||
*/ | ||
function apigee_edge_user_delete(UserInterface $account) { | ||
try { | ||
/** @var \Apigee\Edge\Entity\EntityControllerFactory $ecf */ | ||
$ecf = \Drupal::service('apigee_edge.sdk_connector')->getEntityControllerFactory(); | ||
$ec = $ecf->getControllerByEndpoint('developers'); | ||
$ec->delete($account->getEmail()); | ||
} | ||
catch (\Exception $exception) { | ||
$context = [ | ||
'@developer' => $account->getEmail(), | ||
'@message' => (string) $exception, | ||
'@trace' => $exception->getTraceAsString(), | ||
]; | ||
\Drupal::logger('apigee_edge')->error('Could not delete developer entity. @developer, @message, @trace', $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
administer apigee edge: | ||
title: 'Administer Apigee Edge' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apigee_edge.settings: | ||
path: '/admin/config/apigee_edge' | ||
defaults: | ||
_form: '\Drupal\apigee_edge\Form\AuthenticationForm' | ||
_title: 'Apigee Edge Configuration' | ||
requirements: | ||
_permission: 'administer apigee edge' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
services: | ||
plugin.manager.apigee_edge.credentials_storage: | ||
class: Drupal\apigee_edge\CredentialsStorageManager | ||
parent: default_plugin_manager | ||
|
||
plugin.manager.apigee_edge.authentication_method: | ||
class: Drupal\apigee_edge\AuthenticationMethodManager | ||
parent: default_plugin_manager | ||
|
||
apigee_edge.sdk_connector: | ||
class: Drupal\apigee_edge\SDKConnector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "Apigee Edge", | ||
"type": "drupal-module", | ||
"require": { | ||
"php": ">=7.1", | ||
"php-http/guzzle6-adapter": "^1.1", | ||
"apigee/edge": "dev-2.x-dev#be0754b7088fa386a8306577d841b63e080f2d5f" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apigee_edge/config/install/apigee_edge.authentication_method.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
authentication_method: authentication_method_basic_auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
credentials_storage_type: credentials_storage_private_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apigee_edge.authentication_method: | ||
type: config_object | ||
mapping: | ||
authentication_method: | ||
type: string | ||
|
||
apigee_edge.credentials_storage: | ||
type: config_object | ||
mapping: | ||
credentials_storage_type: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#edit-test-connection-submit { | ||
margin-left: 0; | ||
} | ||
|
||
.test-connection-response-error { | ||
color: red; | ||
font-weight: bold; | ||
} | ||
|
||
.test-connection-response-success { | ||
color: green; | ||
font-weight: bold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Drupal\apigee_edge\Annotation; | ||
|
||
use Drupal\Component\Annotation\Plugin; | ||
|
||
/** | ||
* Defines an authentication method plugin annotation object. | ||
* | ||
* @Annotation | ||
*/ | ||
class AuthenticationMethod extends Plugin { | ||
|
||
/** | ||
* The plugin ID. | ||
* | ||
* @var string | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* The name of the storage plugin. | ||
* | ||
* @var \Drupal\Core\Annotation\Translation | ||
* | ||
* @ingroup plugin_translatable | ||
*/ | ||
public $name; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Drupal\apigee_edge\Annotation; | ||
|
||
use Drupal\Component\Annotation\Plugin; | ||
|
||
/** | ||
* Defines a credentials storage plugin annotation object. | ||
* | ||
* @Annotation | ||
*/ | ||
class CredentialsStorage extends Plugin { | ||
|
||
/** | ||
* The plugin ID. | ||
* | ||
* @var string | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* The name of the storage plugin. | ||
* | ||
* @var \Drupal\Core\Annotation\Translation | ||
* | ||
* @ingroup plugin_translatable | ||
*/ | ||
public $name; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Drupal\apigee_edge; | ||
|
||
use Drupal\apigee_edge\Annotation\AuthenticationMethod; | ||
use Drupal\Component\Plugin\Factory\DefaultFactory; | ||
use Drupal\Core\Plugin\DefaultPluginManager; | ||
use Drupal\Core\Cache\CacheBackendInterface; | ||
use Drupal\Core\Extension\ModuleHandlerInterface; | ||
|
||
/** | ||
* Provides an authentication method plugin manager. | ||
* | ||
* @see \Drupal\apigee_edge\Annotation\AuthetnicationMethod | ||
* @see \Drupal\apigee_edge\AuthetnicationMethodPluginInterface | ||
* @see plugin_api | ||
*/ | ||
class AuthenticationMethodManager extends DefaultPluginManager { | ||
|
||
/** | ||
* Constructs a AuthenticationMethodManager object. | ||
* | ||
* @param \Traversable $namespaces | ||
* An object that implements \Traversable which contains the root paths | ||
* keyed by the corresponding namespace to look for plugin implementations. | ||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend | ||
* Cache backend instance to use. | ||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | ||
* The module handler to invoke the alter hook with. | ||
*/ | ||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { | ||
parent::__construct( | ||
'Plugin/AuthenticationMethod', | ||
$namespaces, | ||
$module_handler, | ||
AuthenticationMethodPluginInterface::class, | ||
AuthenticationMethod::class | ||
); | ||
|
||
$this->alterInfo('authetnication_method_info'); | ||
$this->setCacheBackend($cache_backend, 'authentication_method'); | ||
$this->factory = new DefaultFactory($this->getDiscovery()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Drupal\apigee_edge; | ||
|
||
use Drupal\Component\Plugin\PluginBase; | ||
|
||
/** | ||
* Defines the AuthenticationMethodPluginBase abstract class. | ||
*/ | ||
abstract class AuthenticationMethodPluginBase extends PluginBase implements AuthenticationMethodPluginInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getId() : string { | ||
return $this->pluginDefinition['id']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() : string { | ||
return $this->pluginDefinition['name']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Drupal\apigee_edge; | ||
|
||
use Drupal\Component\Plugin\PluginInspectionInterface; | ||
use Http\Message\Authentication as AuthenticationInterface; | ||
|
||
/** | ||
* Defines an interface for authentication method plugins. | ||
*/ | ||
interface AuthenticationMethodPluginInterface extends PluginInspectionInterface { | ||
|
||
/** | ||
* Returns the ID of the authentication method plugin. | ||
* | ||
* @return string | ||
* The ID of the authentication method plugin. | ||
*/ | ||
public function getId() : string; | ||
|
||
/** | ||
* Returns the name of the authentication method plugin. | ||
* | ||
* @return string | ||
* The name of the authentication method plugin. | ||
*/ | ||
public function getName() : string; | ||
|
||
/** | ||
* Creates an authentication object. | ||
* | ||
* @param \Drupal\apigee_edge\CredentialsInterface $credentials | ||
* An object that implements \Drupal\apigee_edge\CredentialsInterface | ||
* which contains the API credentials. | ||
* | ||
* @return \Http\Message\Authentication | ||
* An object that implements \Http\Message\Authentication. | ||
*/ | ||
public function createAuthenticationObject(CredentialsInterface $credentials) : AuthenticationInterface; | ||
|
||
} |
Oops, something went wrong.