Skip to content

Commit

Permalink
Support for Add AppGroup team and update App credentials with ApiProd…
Browse files Browse the repository at this point in the history
…uct (#251)

* Support for Add Team/AppGroup and update App credentials with ApiProduct

* Fix import order
  • Loading branch information
shishir-intelli committed Mar 24, 2023
1 parent ab272c3 commit 4489adc
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
63 changes: 63 additions & 0 deletions src/Api/ApigeeX/Controller/AppGroupAppCredentialController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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\Controller\CompanyAppCredentialController;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Serializer\EntitySerializerInterface;
use Psr\Http\Message\UriInterface;

/**
* Class AppGroupAppCredentialController.
*/
class AppGroupAppCredentialController extends CompanyAppCredentialController
{
/** @var string appgroup name. */
protected $appGroup;

/**
* DeveloperAppCredentialController constructor.
*
* @param string $organization
* @param string $appGroup
* @param string $appName
* @param \Apigee\Edge\ClientInterface $client
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer
*/
public function __construct(
string $organization,
string $appGroup,
string $appName,
ClientInterface $client,
?EntitySerializerInterface $entitySerializer = null
) {
$this->appGroup = $appGroup;
parent::__construct($organization, $appGroup, $appName, $client, $entitySerializer);
}

/**
* {@inheritdoc}
*/
protected function getBaseEndpointUri(): UriInterface
{
$appName = rawurlencode($this->appName);

return $this->client->getUriFactory()->createUri("/organizations/{$this->organization}/appgroups/{$this->appGroup}/apps/{$appName}");
}
}
18 changes: 18 additions & 0 deletions src/Api/ApigeeX/Controller/AppGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
use Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerTrait;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Controller\EntityController;
use Apigee\Edge\Controller\EntityCreateOperationControllerTrait;
use Apigee\Edge\Controller\EntityCrudOperationsControllerTrait;
use Apigee\Edge\Controller\EntityListingControllerTrait;
use Apigee\Edge\Controller\StatusAwareEntityControllerTrait;
use Apigee\Edge\Entity\EntityInterface;
use Apigee\Edge\Serializer\EntitySerializerInterface;
use Psr\Http\Message\UriInterface;

Expand All @@ -38,6 +40,7 @@ class AppGroupController extends EntityController implements AppGroupControllerI
use EntityCrudOperationsControllerTrait;
use EntityListingControllerTrait;
use StatusAwareEntityControllerTrait;
use EntityCreateOperationControllerTrait;

/**
* AppGroupController constructor.
Expand Down Expand Up @@ -87,4 +90,19 @@ protected function getEntityClass(): string
{
return AppGroup::class;
}

/**
* {@inheritdoc}
*/
protected function buildEntityCreatePayload(EntityInterface $entity, array $context = []): string
{
$entitySerializer = $this->getEntitySerializer()->serialize($entity, 'json', $context);

// decode json to associative array
$payload = json_decode($entitySerializer, true);
// Removing property which is not supported for AppGroup.
unset($payload['apps']);

return $this->getEntitySerializer()->serialize($payload, 'json', $context);
}
}
1 change: 0 additions & 1 deletion src/Api/ApigeeX/Normalizer/AppNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function normalize($object, $format = null, array $context = [])

// Remove properties for the AppGroupApp.
unset($normalized->appFamily);
unset($normalized->appGroup);

return $normalized;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Management/Controller/AppCredentialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function generate(
array $scopes = [],
string $keyExpiresIn = '-1'
): AppCredentialInterface {
$response = $this->client->post(
$response = $this->client->put(
$this->getBaseEndpointUri(),
(string) json_encode((object) [
'apiProducts' => $apiProducts,
Expand Down

0 comments on commit 4489adc

Please sign in to comment.