-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3.x' into drupal10-prep
- Loading branch information
Showing
25 changed files
with
1,619 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Serializer\AppGroupEntitySerializer; | ||
use Apigee\Edge\Api\Management\Controller\OrganizationControllerInterface; | ||
use Apigee\Edge\Api\Management\Entity\AppInterface; | ||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Controller\EntityListingControllerTrait; | ||
use Apigee\Edge\Controller\PaginatedEntityController; | ||
use Apigee\Edge\Controller\PaginationHelperTrait; | ||
use Apigee\Edge\Serializer\EntitySerializerInterface; | ||
use Apigee\Edge\Structure\PagerInterface; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
/** | ||
* Class AppController. | ||
*/ | ||
class AppController extends PaginatedEntityController implements AppControllerInterface | ||
{ | ||
use EntityListingControllerTrait; | ||
use PaginationHelperTrait { | ||
listEntities as private traitListEntities; | ||
} | ||
|
||
protected const ID_GETTER = 'getAppId'; | ||
|
||
/** | ||
* AppController constructor. | ||
* | ||
* @param string $organization | ||
* @param \Apigee\Edge\ClientInterface $client | ||
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer | ||
* @param \Apigee\Edge\Api\Management\Controller\OrganizationControllerInterface|null $organizationController | ||
*/ | ||
public function __construct( | ||
string $organization, | ||
ClientInterface $client, | ||
?EntitySerializerInterface $entitySerializer = null, | ||
?OrganizationControllerInterface $organizationController = null | ||
) { | ||
$entitySerializer = $entitySerializer ?? new AppGroupEntitySerializer(); | ||
parent::__construct($organization, $client, $entitySerializer, $organizationController); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadAppGroup(string $appId): AppInterface | ||
{ | ||
$response = $this->client->get($this->getEntityEndpointUri($appId)); | ||
|
||
return $this->entitySerializer->denormalize( | ||
// Pass it as an object, because if serializer would have been used here (just as other places) it would | ||
// pass an object to the denormalizer and not an array. | ||
(object) $this->responseToArray($response), | ||
$this->getEntityClass() | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function listAppIds(PagerInterface $pager = null): array | ||
{ | ||
return $this->listEntityIds($pager, []); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function listApps(bool $includeCredentials = true, PagerInterface $pager = null): array | ||
{ | ||
$queryParams = [ | ||
'includeCred' => $includeCredentials ? 'true' : 'false', | ||
]; | ||
|
||
return $this->listEntities($pager, $queryParams); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function listAppIdsByStatus(string $status, PagerInterface $pager = null): array | ||
{ | ||
$queryParams = [ | ||
'status' => $status, | ||
]; | ||
|
||
return $this->listEntityIds($pager, $queryParams); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function listAppsByStatus( | ||
string $status, | ||
bool $includeCredentials = true, | ||
PagerInterface $pager = null | ||
): array { | ||
$queryParams = [ | ||
'status' => $status, | ||
'includeCred' => $includeCredentials ? 'true' : 'false', | ||
]; | ||
|
||
return $this->listEntities($pager, $queryParams); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function listAppIdsByType(string $appType, PagerInterface $pager = null): array | ||
{ | ||
$queryParams = [ | ||
'apptype' => $appType, | ||
]; | ||
|
||
return $this->listEntityIds($pager, $queryParams); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getBaseEndpointUri(): UriInterface | ||
{ | ||
return $this->client->getUriFactory()->createUri("/organizations/{$this->organization}/apps"); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getEntityClass(): string | ||
{ | ||
// It could be either a developer- or a appGroup app. The AppDenormalizer can automatically decide which one | ||
// should be used. | ||
return AppInterface::class; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function listEntities( | ||
PagerInterface $pager = null, | ||
array $query_params = [], | ||
string $idGetter = null | ||
): array { | ||
$idGetter = $idGetter ?? static::ID_GETTER; | ||
|
||
return $this->traitListEntities($pager, $query_params, $idGetter); | ||
} | ||
} |
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,134 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\Management\Entity\AppInterface; | ||
use Apigee\Edge\Controller\EntityControllerInterface; | ||
use Apigee\Edge\Controller\PaginatedEntityControllerInterface; | ||
use Apigee\Edge\Structure\PagerInterface; | ||
|
||
/** | ||
* Interface AppControllerInterface. | ||
* | ||
* @see https://docs.apigee.com/api/apps-0 | ||
*/ | ||
interface AppControllerInterface extends PaginatedEntityControllerInterface, EntityControllerInterface | ||
{ | ||
/** | ||
* Type of a developer app. | ||
*/ | ||
public const APP_TYPE_DEVELOPER = 'developer'; | ||
|
||
/** | ||
* Type of a appgroup app. | ||
*/ | ||
public const APP_TYPE_COMPANY = 'appgroup'; | ||
|
||
/** | ||
* String that should be sent to the API to change the status of a | ||
* credential to approved. | ||
*/ | ||
public const STATUS_APPROVE = 'approve'; | ||
|
||
/** | ||
* String that should be sent to the API to change the status of a | ||
* credential to revoked. | ||
*/ | ||
public const STATUS_REVOKE = 'revoke'; | ||
|
||
/** | ||
* Loads a developer or a appgroup app from Edge based on its UUID. | ||
* | ||
* @param string $appId | ||
* UUID of an app (appId). | ||
* | ||
* @return \Apigee\Edge\Api\Management\Entity\AppInterface | ||
* A developer- or a appgroup app entity. | ||
*/ | ||
public function loadAppGroup(string $appId): AppInterface; | ||
|
||
/** | ||
* Returns list of app ids from Edge. | ||
* | ||
* @param \Apigee\Edge\Structure\PagerInterface|null $pager | ||
* Number of results to return. | ||
* | ||
* @return string[] | ||
* An array of developer- and appgroup app ids. | ||
*/ | ||
public function listAppIds(PagerInterface $pager = null): array; | ||
|
||
/** | ||
* Returns list of app entities from Edge. The returned number of entities can be limited. | ||
* | ||
* @param bool $includeCredentials | ||
* Whether to include consumer key and secret for each app in the response or not. | ||
* @param \Apigee\Edge\Structure\PagerInterface|null $pager | ||
* Number of results to return. | ||
* | ||
* @return \Apigee\Edge\Api\Management\Entity\AppInterface[] | ||
* An array that can contain both developer- and appgroup app entities. | ||
*/ | ||
public function listApps(bool $includeCredentials = false, PagerInterface $pager = null): array; | ||
|
||
/** | ||
* Returns a list of app ids filtered by status from Edge. | ||
* | ||
* @param string $status | ||
* App status. (Recommended way is to use App entity constants.) | ||
* @param \Apigee\Edge\Structure\PagerInterface|null $pager | ||
* Number of results to return. | ||
* | ||
* @return string[] | ||
* An array of developer- and appgroup app ids. | ||
*/ | ||
public function listAppIdsByStatus(string $status, PagerInterface $pager = null): array; | ||
|
||
/** | ||
* Returns a list of app entities filtered by status from Edge. | ||
* | ||
* @param string $status | ||
* App status. (Recommended way is to use App entity constants.) | ||
* @param bool $includeCredentials | ||
* Whether to include app credentials in the response or not. | ||
* @param \Apigee\Edge\Structure\PagerInterface|null $pager | ||
* Number of results to return. | ||
* | ||
* @return \Apigee\Edge\Api\Management\Entity\AppInterface[] | ||
* An array that can contain both developer- and appgroup app entities. | ||
*/ | ||
public function listAppsByStatus( | ||
string $status, | ||
bool $includeCredentials = true, | ||
PagerInterface $pager = null | ||
): array; | ||
|
||
/** | ||
* Returns a list of app ids filtered by app type from Edge. | ||
* | ||
* @param string $appType | ||
* Either "developer" or "appgroup". | ||
* @param \Apigee\Edge\Structure\PagerInterface|null $pager | ||
* Number of results to return. | ||
* | ||
* @return string[] | ||
* An array of developer- and appgroup app ids. | ||
*/ | ||
public function listAppIdsByType(string $appType, PagerInterface $pager = null): array; | ||
} |
Oops, something went wrong.