Skip to content

Commit

Permalink
Merge branch '3.x' into issue-359-codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
kedarkhaire authored May 9, 2024
2 parents 3b666e8 + 13761ed commit 225dd93
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 95 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# CHANGELOG
## [3.0.5](https://github.com/apigee/apigee-client-php/milestone/29?closed=1)
* [#351] Retrieving the next list items based on 'nextpagetoken' flag in Apigee X.
* [#348] Fix for composer analyze failing in github action.

## [3.0.4](https://github.com/apigee/apigee-client-php/milestone/28?closed=1)
* [#343] Fix Invalid payload issue while editing/updating AppGroup/Teams in Apigee X.
* [#342] Fix for test failing for symfony 6.4.
* [#340] Fix for attribute values lost in PUT call while creating AppGroup.
* [#337] Fix for Team app credentials listings sorted in ascending order.
* [#334] Fix for \Apigee\Edge\HttpClient\Plugin\Authentication\GceServiceAccount::isAvailable() throws exception when called on non-GCE context.

## [3.0.3](https://github.com/apigee/apigee-client-php/milestone/26?closed=1)
* [#323] Add union type to suppress deprecation warning.
* [#325] Fix error when AppGroup list is empty or do not returns appgroups array.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"symfony/options-resolver": "^6.3",
"symfony/property-access": "^6.3",
"symfony/property-info": "^6.3",
"symfony/serializer": "^6.3"
"symfony/serializer": "^6.3.11"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.4.0",
Expand All @@ -47,7 +47,7 @@
"phpunit/phpunit": "^9.6",
"sebastian/comparator": "^4.0.5",
"symfony/cache": "^6.3",
"vimeo/psalm": "^5.12"
"vimeo/psalm": "^5.20"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@

<!-- Disable error caused by deprecated interface-->
<DeprecatedInterface errorLevel="info" />

<RiskyTruthyFalsyComparison errorLevel="info" />

</issueHandlers>
</psalm>
24 changes: 22 additions & 2 deletions src/Api/ApigeeX/Controller/AppGroupMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Apigee\Edge\Api\ApigeeX\Serializer\AppGroupMembershipSerializer;
use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership;
use Apigee\Edge\Api\Management\Serializer\AttributesPropertyAwareEntitySerializer;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Controller\AbstractController;
use Apigee\Edge\Controller\OrganizationAwareControllerTrait;
Expand Down Expand Up @@ -47,7 +48,7 @@ class AppGroupMembersController extends AbstractController implements AppGroupMe
*
* @param string $appGroup
* @param string $organization
* @param \Apigee\Edge\ClientInterface $client
* @param ClientInterface $client
*/
public function __construct(string $appGroup, string $organization, ClientInterface $client)
{
Expand All @@ -73,8 +74,10 @@ public function getMembers(): AppGroupMembership
public function setMembers(AppGroupMembership $members): AppGroupMembership
{
$members = $this->serializer->normalize($members);
$apigeeReservedMembers = new AttributesProperty();

// We don't have a separate API to get appgroup attributes,
// that is why we are calling getAppGroupAttributes() method.
$apigeeReservedMembers = $this->getAppGroupAttributes();
// Adding the new members into the attribute.
$apigeeReservedMembers->add('__apigee_reserved__developer_details', json_encode($members));
$response = $this->client->put(
Expand All @@ -101,6 +104,23 @@ public function removeMember(string $email): void
$this->client->delete($this->getBaseEndpointUri()->withPath("{$this->getBaseEndpointUri()->getPath()}/{$encoded}"));
}

/**
* Helper function for getting all attributes in AppGroup.
*
* @return AttributesProperty
*/
public function getAppGroupAttributes(): AttributesProperty
{
$appGroup = $this->responseToArray($this->client->get($this->getBaseEndpointUri()));
$serializer = new AttributesPropertyAwareEntitySerializer();
$appGroupAttributes = $serializer->denormalize(
$appGroup['attributes'],
AttributesProperty::class
);

return $appGroupAttributes;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface AppGroupMembersControllerInterface extends AppGroupAwareControllerInte
/**
* List all developers associated with a appgroup.
*
* @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership
* @return AppGroupMembership
* Array of developers with their optional roles in the appgroup.
*/
public function getMembers(): AppGroupMembership;
Expand All @@ -39,10 +39,10 @@ public function getMembers(): AppGroupMembership;
* WARNING! If you pass en empty membership object you remove all developers
* from the appgroup.
*
* @param \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership $members
* @param AppGroupMembership $members
* Membership object with the changes to be applied.
*
* @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership
* @return AppGroupMembership
* Membership object with the applied changes, it does not contain all
* members. Use getMembers() to retrieve them.
*/
Expand Down
56 changes: 29 additions & 27 deletions src/Api/ApigeeX/Controller/PaginationHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Utility methods for those controllers that supports paginated listing.
*
* @see \Apigee\Edge\Api\ApigeeX\Controller\PaginatedEntityListingControllerInterface
* @see \PaginatedEntityListingControllerInterface
*/
trait PaginationHelperTrait
{
Expand All @@ -35,7 +35,7 @@ trait PaginationHelperTrait
/**
* {@inheritdoc}
*/
public function createPager(int $limit = 0, string $pageToken = null): PagerInterface
public function createPager(int $limit = 0, ?string $pageToken = null): PagerInterface
{
// Create an anonymous class here because this class should not exist and be in use
// in those controllers that do not work with entities that belongs to an organization.
Expand Down Expand Up @@ -90,7 +90,7 @@ public function setLimit(int $limit): int
/**
* Loads paginated list of entities from Apigee X.
*
* @param \Apigee\Edge\Api\ApigeeX\Structure\PagerInterface|null $pager
* @param PagerInterface|null $pager
* Pager.
* @param array $query_params
* Additional query parameters.
Expand All @@ -103,7 +103,7 @@ public function setLimit(int $limit): int
* @psalm-suppress PossiblyNullArrayOffset $tmp->id() is always not null here.
* @psalm-suppress PossiblyFalseArgument $tmp not be false.
*/
protected function listEntities(PagerInterface $pager = null, array $query_params = [], string $key_provider = 'id'): array
protected function listEntities(?PagerInterface $pager = null, array $query_params = [], string $key_provider = 'id'): array
{
if ($pager) {
$responseArray = $this->getResultsInRange($pager, $query_params);
Expand All @@ -113,8 +113,14 @@ protected function listEntities(PagerInterface $pager = null, array $query_param

return $this->responseArrayToArrayOfEntities($responseArray, $key_provider);
} else {
// Default page size set to 1000, because the AppGroupApps endpoint
// does not return nextPageToken unless a pageSize is specified
// in the request parameters.
$pageSize = 1000;
// Pass an empty pager to load all entities.
$responseArray = $this->getResultsInRange($this->createPager(), $query_params);
$responseArray = $this->getResultsInRange($this->createPager($pageSize), $query_params);
// Check flag 'nextPageToken' to get next items from the list.
$nextPageToken = array_key_exists('nextPageToken', $responseArray) ? $responseArray['nextPageToken'] : false;
// Ignore entity type key from response, ex.: developer, apiproduct,
// etc.
$responseArray = reset($responseArray);
Expand All @@ -123,30 +129,26 @@ protected function listEntities(PagerInterface $pager = null, array $query_param
return [];
}
$entities = $this->responseArrayToArrayOfEntities($responseArray, $key_provider);
$lastEntity = end($entities);
$lastId = $lastEntity->{$key_provider}();
do {
$tmp = $this->getResultsInRange($this->createPager(0, $lastId), $query_params);
// Ignore entity type key from response, ex.: developer,
// apiproduct, etc.
$tmp = reset($tmp);
// Remove the first item from the list because it is the same
// as the last item of $entities at this moment.
// Apigee X response always starts with the requested entity
// (pageToken).
array_shift($tmp);
$tmpEntities = $this->responseArrayToArrayOfEntities($tmp, $key_provider);

if (count($tmpEntities) > 0) {

if ($nextPageToken) {
do {
$tmp = $this->getResultsInRange($this->createPager($pageSize, $nextPageToken), $query_params);
// Check the flag 'nextPageToken' to get next items from the list.
$nextPageToken = array_key_exists('nextPageToken', $tmp) ? $tmp['nextPageToken'] : false;
// Ignore entity type key from response, ex.: developer,
// apiproduct, etc.
$tmp = reset($tmp);
// Remove the first item from the list because it is the same
// as the last item of $entities at this moment.
// Apigee X response always starts with the requested entity
// (pageToken).
array_shift($tmp);
$tmpEntities = $this->responseArrayToArrayOfEntities($tmp, $key_provider);
// The returned entity array is keyed by entity id which
// is unique so we can do this.
$entities += $tmpEntities;
$lastEntity = end($tmpEntities);
$lastId = $lastEntity->{$key_provider}();
} else {
$lastId = false;
}
} while ($lastId);
} while ($nextPageToken);
}

return $entities;
}
Expand All @@ -155,7 +157,7 @@ protected function listEntities(PagerInterface $pager = null, array $query_param
/**
* Gets entities and entity ids in a provided range from Apigee X.
*
* @param \Apigee\Edge\Api\ApigeeX\Structure\PagerInterface $pager
* @param PagerInterface $pager
* limit object with configured pageToken and limit.
* @param array $query_params
* Query parameters for the API call.
Expand Down
10 changes: 8 additions & 2 deletions src/Api/ApigeeX/Entity/AppGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@

namespace Apigee\Edge\Api\ApigeeX\Entity;

use Apigee\Edge\Api\Management\Entity\AppOwner;
use Apigee\Edge\Entity\CommonEntityPropertiesAwareTrait;
use Apigee\Edge\Entity\Entity;
use Apigee\Edge\Entity\Property\AttributesPropertyAwareTrait;
use Apigee\Edge\Entity\Property\DisplayNamePropertyAwareTrait;
use Apigee\Edge\Entity\Property\NamePropertyAwareTrait;
use Apigee\Edge\Entity\Property\StatusPropertyAwareTrait;
use Apigee\Edge\Structure\AttributesProperty;

/**
* Describes an AppGroup entity.
*/
class AppGroup extends AppOwner implements AppGroupInterface
class AppGroup extends Entity implements AppGroupInterface
{
use DisplayNamePropertyAwareTrait;
use NamePropertyAwareTrait;
use AttributesPropertyAwareTrait;
use CommonEntityPropertiesAwareTrait;
use StatusPropertyAwareTrait;

/** @var string|null */
protected $channelUri;
Expand Down
10 changes: 7 additions & 3 deletions src/Api/ApigeeX/Entity/AppGroupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

namespace Apigee\Edge\Api\ApigeeX\Entity;

use Apigee\Edge\Api\Management\Entity\AppOwnerInterface;
use Apigee\Edge\Entity\CommonEntityPropertiesInterface;
use Apigee\Edge\Entity\Property\AttributesPropertyInterface;
use Apigee\Edge\Entity\Property\DisplayNamePropertyInterface;
use Apigee\Edge\Entity\Property\NamePropertyInterface;
use Apigee\Edge\Entity\Property\StatusPropertyInterface;

/**
* Interface AppGroupInterface.
*/
interface AppGroupInterface extends AppOwnerInterface,
interface AppGroupInterface extends AttributesPropertyInterface,
DisplayNamePropertyInterface,
NamePropertyInterface
NamePropertyInterface,
StatusPropertyInterface,
CommonEntityPropertiesInterface
{
/**
* @param string $channelUri
Expand Down
11 changes: 7 additions & 4 deletions src/Api/Management/Entity/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Apigee\Edge\Entity\Property\ScopesPropertyAwareTrait;
use Apigee\Edge\Entity\Property\StatusPropertyAwareTrait;
use Apigee\Edge\Structure\AttributesProperty;
use LogicException;

/**
* Class App.
Expand Down Expand Up @@ -55,7 +56,7 @@ abstract class App extends Entity implements AppInterface
/** @var string Url, used for "three-legged" OAuth grant type flows. */
protected $callbackUrl;

/** @var \Apigee\Edge\Api\Management\Entity\AppCredential[] */
/** @var AppCredential[] */
protected $credentials = [];

/** @var string[] */
Expand Down Expand Up @@ -187,6 +188,8 @@ public function setCallbackUrl(string $callbackUrl): void
*/
public function getCredentials(): array
{
usort($this->credentials, static fn (AppCredentialInterface $a, AppCredentialInterface $b) => $b->getIssuedAt() <=> $a->getIssuedAt());

return $this->credentials;
}

Expand All @@ -195,7 +198,7 @@ public function getCredentials(): array
*
* Credentials, included in app, can not be changed by modifying them on the entity level.
*
* @param \Apigee\Edge\Api\Management\Entity\AppCredentialInterface ...$credentials
* @param AppCredentialInterface ...$credentials
*
* @internal
*/
Expand Down Expand Up @@ -238,14 +241,14 @@ final public function getApiProducts(): array
*
* @param array $initialApiProducts
*
* @throws \LogicException If used to update existing App.
* @throws LogicException If used to update existing App.
*/
final public function setInitialApiProducts(array $initialApiProducts): void
{
if (!$this->appId) {
$this->initialApiProducts = $initialApiProducts;
} else {
throw new \LogicException('This method is only supported for creating a new app.');
throw new LogicException('This method is only supported for creating a new app.');
}
}
}
Loading

0 comments on commit 225dd93

Please sign in to comment.