-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AppGroup-App implementation for list, view, edit, delete apps (#813)
- Loading branch information
1 parent
98a80ed
commit ccacbcb
Showing
16 changed files
with
242 additions
and
61 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 |
---|---|---|
|
@@ -29,7 +29,6 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
php-version: | ||
- "7.4" | ||
- "8.0" | ||
- "8.1" | ||
drupal-core: | ||
|
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ dependencies: | |
|
||
configure: apigee_edge.settings | ||
|
||
php: "7.1" | ||
php: "8.0" |
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
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
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
121 changes: 121 additions & 0 deletions
121
modules/apigee_edge_teams/src/Entity/Controller/TeamAppApigeeXEntityControllerProxy.php
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,121 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2023 Google Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* version 2 as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
namespace Drupal\apigee_edge_teams\Entity\Controller; | ||
|
||
use Apigee\Edge\Api\Management\Entity\AppInterface; | ||
use Apigee\Edge\Api\ApigeeX\Entity\AppGroupAppInterface; | ||
use Apigee\Edge\Entity\EntityInterface; | ||
use Drupal\apigee_edge\Entity\Controller\AppControllerInterface; | ||
use Drupal\apigee_edge\Entity\Controller\EdgeEntityControllerInterface; | ||
use Drupal\apigee_edge\Exception\RuntimeException; | ||
|
||
/** | ||
* Team app specific entity controller implementation. | ||
* | ||
* It ensures that the right SDK controllers (and with that the right API | ||
* endpoints) gets used for CRUDL operations. | ||
*/ | ||
final class TeamAppApigeeXEntityControllerProxy implements EdgeEntityControllerInterface { | ||
|
||
/** | ||
* The team app controller factory service. | ||
* | ||
* @var \Drupal\apigee_edge_teams\Entity\Controller\TeamAppControllerFactoryInterface | ||
*/ | ||
private $teamAppControllerFactory; | ||
|
||
/** | ||
* The app controller service. | ||
* | ||
* @var \Drupal\apigee_edge\Entity\Controller\AppControllerInterface | ||
*/ | ||
private $appController; | ||
|
||
/** | ||
* TeamAppApigeeXEntityControllerProxy constructor. | ||
* | ||
* @param \Drupal\apigee_edge_teams\Entity\Controller\TeamAppControllerFactoryInterface $team_app_controller_factory | ||
* The team app controller factory service. | ||
* @param \Drupal\apigee_edge\Entity\Controller\AppControllerInterface $app_controller | ||
* The app controller service. | ||
*/ | ||
public function __construct(TeamAppControllerFactoryInterface $team_app_controller_factory, AppControllerInterface $app_controller) { | ||
$this->teamAppControllerFactory = $team_app_controller_factory; | ||
$this->appController = $app_controller; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function create(EntityInterface $entity): void { | ||
/** @var \Apigee\Edge\Api\ApigeeX\Entity\AppGroupAppInterface $entity */ | ||
if (empty($entity->getAppGroup())) { | ||
// Sanity check. | ||
throw new RuntimeException('AppGroup name has to set on the app.'); | ||
} | ||
$controller = $this->teamAppControllerFactory->teamAppController($entity->getAppGroup()); | ||
$controller->create($entity); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(string $id): EntityInterface { | ||
return $this->appController->loadAppGroup($id); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function update(EntityInterface $entity): void { | ||
/** @var \Apigee\Edge\Api\ApigeeX\Entity\AppGroupAppInterface $entity */ | ||
$controller = $this->teamAppControllerFactory->teamAppController($entity->getAppGroup()); | ||
$controller->update($entity); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete(string $id): void { | ||
// Try to be smart here and load the app from the appgroup app | ||
// entity cache (app controller's cache is probably empty unless there were | ||
// a load() or getEntities() call before). | ||
$entity = \Drupal::entityTypeManager()->getStorage('team_app')->load($id); | ||
if (!$entity) { | ||
// Entity has not found in the entity cache, we have it from Apigee Edge. | ||
$entity = $this->load($id); | ||
} | ||
/** @var \Apigee\Edge\Api\ApigeeX\Entity\AppGroupAppInterface $entity */ | ||
$controller = $this->teamAppControllerFactory->teamAppController($entity->getAppGroup()); | ||
// The id that we got is a UUID, what we need is an app name. | ||
$controller->delete($entity->getName()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadAll(): array { | ||
return array_filter($this->appController->listApps(TRUE), function (AppInterface $app) { | ||
return $app instanceof AppGroupAppInterface; | ||
}); | ||
} | ||
|
||
} |
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
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
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
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
Oops, something went wrong.