Skip to content

Commit

Permalink
Merge branch '3.x' into issue-335-3x
Browse files Browse the repository at this point in the history
  • Loading branch information
kedarkhaire authored Feb 9, 2024
2 parents be4c4a2 + f0b1790 commit 427c80a
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 71 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# CHANGELOG
## [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
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.');
}
}
}
24 changes: 12 additions & 12 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ interface ClientInterface extends HttpClient
*/
public const APIGEE_ON_GCP_ENDPOINT = 'https://apigee.googleapis.com/v1';

public const VERSION = '3.0.3';
public const VERSION = '3.0.4';

/**
* Allows access to the last request, response and exception.
*
* @return \Apigee\Edge\HttpClient\Utility\JournalInterface
* @return JournalInterface
*/
public function getJournal(): JournalInterface;

Expand Down Expand Up @@ -108,10 +108,10 @@ public function getEndpoint(): string;
* @param \Psr\Http\Message\UriInterface|string $uri
* @param array $headers
*
* @throws \Apigee\Edge\Exception\ApiException
* @throws Exception\ApiException
* @throws \Http\Client\Exception
*
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function get($uri, array $headers = []): ResponseInterface;

Expand All @@ -121,10 +121,10 @@ public function get($uri, array $headers = []): ResponseInterface;
* @param \Psr\Http\Message\UriInterface|string $uri
* @param array $headers
*
* @throws \Apigee\Edge\Exception\ApiException
* @throws Exception\ApiException
* @throws \Http\Client\Exception
*
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function head($uri, array $headers = []): ResponseInterface;

Expand All @@ -135,10 +135,10 @@ public function head($uri, array $headers = []): ResponseInterface;
* @param \Psr\Http\Message\StreamInterface|resource|string|null $body
* @param array $headers
*
* @throws \Apigee\Edge\Exception\ApiException
* @throws Exception\ApiException
* @throws \Http\Client\Exception
*
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function post($uri, $body = null, array $headers = []): ResponseInterface;

Expand All @@ -149,10 +149,10 @@ public function post($uri, $body = null, array $headers = []): ResponseInterface
* @param \Psr\Http\Message\StreamInterface|resource|string|null $body
* @param array $headers
*
* @throws \Apigee\Edge\Exception\ApiException
* @throws Exception\ApiException
* @throws \Http\Client\Exception
*
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function put($uri, $body = null, array $headers = []): ResponseInterface;

Expand All @@ -163,10 +163,10 @@ public function put($uri, $body = null, array $headers = []): ResponseInterface;
* @param \Psr\Http\Message\StreamInterface|resource|string|null $body
* @param array $headers
*
* @throws \Apigee\Edge\Exception\ApiException
* @throws Exception\ApiException
* @throws \Http\Client\Exception
*
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function delete($uri, $body = null, array $headers = []): ResponseInterface;
}
7 changes: 4 additions & 3 deletions src/HttpClient/Plugin/Authentication/GceServiceAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
use Apigee\Edge\Client;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Exception\ApigeeOnGcpOauth2AuthenticationException;
use Http\Client\Exception;
use Http\Message\Authentication\Header;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\NetworkExceptionInterface;

/**
* GCE Service Account authentication plugin for authenticating to Google
Expand Down Expand Up @@ -61,7 +62,7 @@ public function isAvailable(): bool
$this->authClient()->get('');

return true;
} catch (Exception $e) {
} catch (NetworkExceptionInterface $e) {
return false;
}
}
Expand All @@ -85,7 +86,7 @@ protected function getAccessToken(): void
$response = $this->authClient()->get('');
$decoded_token = json_decode((string) $response->getBody(), true);
$this->tokenStorage->saveToken($decoded_token);
} catch (Exception $e) {
} catch (ClientExceptionInterface $e) {
throw new ApigeeOnGcpOauth2AuthenticationException($e->getMessage(), $e->getCode(), $e);
}
}
Expand Down
Loading

0 comments on commit 427c80a

Please sign in to comment.