From 1e16a4c6598d0a679a3e8cd1e0250351e48ca92d Mon Sep 17 00:00:00 2001 From: phdhiren Date: Tue, 27 Jul 2021 10:53:29 +0000 Subject: [PATCH 1/4] [#603] Change ClientInterface constant names and HybridOauth2 (#604) * [#603] Change ClientInterface constant names and HybridOauth2 * Required apigee-client-php library to 2.0.9 --- composer.json | 2 +- src/Command/Util/ApigeeEdgeManagementCliService.php | 2 +- src/Connector/HybridAuthentication.php | 4 ++-- src/KeyEntityFormEnhancer.php | 4 ++-- src/Plugin/EdgeKeyTypeBase.php | 6 +++--- .../Command/Util/ApigeeEdgeManagementCliServiceTest.php | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 8eec86c2..89460787 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": ">=7.1", "ext-json": "*", - "apigee/apigee-client-php": "^2.0.6", + "apigee/apigee-client-php": "^2.0.9", "drupal/core": "^8.7.7 || ^9", "drupal/entity": "^1.0", "drupal/key": "^1.8", diff --git a/src/Command/Util/ApigeeEdgeManagementCliService.php b/src/Command/Util/ApigeeEdgeManagementCliService.php index 65d8361f..8a1c5f60 100644 --- a/src/Command/Util/ApigeeEdgeManagementCliService.php +++ b/src/Command/Util/ApigeeEdgeManagementCliService.php @@ -62,7 +62,7 @@ public function createEdgeRoleForDrupal(StyleInterface $io, // Set default base URL if var is null or empty string. if (empty($base_url)) { - $base_url = ApigeeClientInterface::DEFAULT_ENDPOINT; + $base_url = ApigeeClientInterface::EDGE_ENDPOINT; } else { // Validate it is a valid URL. diff --git a/src/Connector/HybridAuthentication.php b/src/Connector/HybridAuthentication.php index 9ef7bbfd..8ea45869 100644 --- a/src/Connector/HybridAuthentication.php +++ b/src/Connector/HybridAuthentication.php @@ -21,13 +21,13 @@ namespace Drupal\apigee_edge\Connector; use Apigee\Edge\ClientInterface; -use Apigee\Edge\HttpClient\Plugin\Authentication\HybridOauth2; +use Apigee\Edge\HttpClient\Plugin\Authentication\ApigeeOnGcpOauth2; use Apigee\Edge\HttpClient\Plugin\Authentication\NullAuthentication; /** * Decorator for Hybrid authentication plugin. */ -class HybridAuthentication extends HybridOauth2 { +class HybridAuthentication extends ApigeeOnGcpOauth2 { /** * {@inheritdoc} diff --git a/src/KeyEntityFormEnhancer.php b/src/KeyEntityFormEnhancer.php index c40c4de6..6928a3ee 100644 --- a/src/KeyEntityFormEnhancer.php +++ b/src/KeyEntityFormEnhancer.php @@ -21,7 +21,7 @@ namespace Drupal\apigee_edge; use Apigee\Edge\Exception\ApiRequestException; -use Apigee\Edge\Exception\HybridOauth2AuthenticationException; +use Apigee\Edge\Exception\ApigeeOnGcpOauth2AuthenticationException; use Apigee\Edge\Exception\OauthAuthenticationException; use Apigee\Edge\HttpClient\Plugin\Authentication\Oauth; use Drupal\apigee_edge\Exception\AuthenticationKeyException; @@ -475,7 +475,7 @@ private function createSuggestion(\Exception $exception, KeyInterface $key): Mar ]); } - elseif ($exception instanceof HybridOauth2AuthenticationException) { + elseif ($exception instanceof ApigeeOnGcpOauth2AuthenticationException) { $fail_text = $this->t('Failed to connect to the authorization server.'); // General error message. $suggestion = $this->t('@fail_text Check the debug information below for more details.', [ diff --git a/src/Plugin/EdgeKeyTypeBase.php b/src/Plugin/EdgeKeyTypeBase.php index 34684c64..d89523fa 100644 --- a/src/Plugin/EdgeKeyTypeBase.php +++ b/src/Plugin/EdgeKeyTypeBase.php @@ -69,10 +69,10 @@ public function getAuthenticationType(KeyInterface $key): string { */ public function getEndpoint(KeyInterface $key): string { if ($this->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) { - return ClientInterface::HYBRID_ENDPOINT; + return ClientInterface::APIGEE_ON_GCP_ENDPOINT; } elseif ($this->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC) { - return Client::DEFAULT_ENDPOINT; + return Client::EDGE_ENDPOINT; } return $key->getKeyValues()['endpoint']; } @@ -100,7 +100,7 @@ public function getInstanceType(KeyInterface $key): string { } // Backwards compatibility, before Hybrid support. - if (empty($key_values['endpoint']) || $key_values['endpoint'] === ClientInterface::DEFAULT_ENDPOINT) { + if (empty($key_values['endpoint']) || $key_values['endpoint'] === ClientInterface::EDGE_ENDPOINT) { return EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC; } diff --git a/tests/src/Unit/Command/Util/ApigeeEdgeManagementCliServiceTest.php b/tests/src/Unit/Command/Util/ApigeeEdgeManagementCliServiceTest.php index 5dddaf9c..6d05e401 100644 --- a/tests/src/Unit/Command/Util/ApigeeEdgeManagementCliServiceTest.php +++ b/tests/src/Unit/Command/Util/ApigeeEdgeManagementCliServiceTest.php @@ -153,7 +153,7 @@ public function testCreateEdgeRoleForDrupalDefaultRoleAndBaseUrl() { ->shouldBeCalledTimes(1) ->willReturn('{ "name": "' . $this->org . '" }'); $this->httpClient - ->get(Argument::exact(ApigeeClientInterface::DEFAULT_ENDPOINT . '/o/' . $this->org), Argument::type('array')) + ->get(Argument::exact(ApigeeClientInterface::EDGE_ENDPOINT . '/o/' . $this->org), Argument::type('array')) ->shouldBeCalledTimes(1) ->willReturn($response_org->reveal()); @@ -163,17 +163,17 @@ public function testCreateEdgeRoleForDrupalDefaultRoleAndBaseUrl() { $response_role->getStatusCode()->willReturn(404); $exception = new ClientException('Forbidden', $request_role->reveal(), $response_role->reveal()); $this->httpClient - ->get(Argument::exact(ApigeeClientInterface::DEFAULT_ENDPOINT . '/o/' . $this->org . '/userroles/' . ApigeeEdgeManagementCliServiceInterface::DEFAULT_ROLE_NAME), Argument::type('array')) + ->get(Argument::exact(ApigeeClientInterface::EDGE_ENDPOINT . '/o/' . $this->org . '/userroles/' . ApigeeEdgeManagementCliServiceInterface::DEFAULT_ROLE_NAME), Argument::type('array')) ->willThrow($exception); // The role should be created. $this->httpClient - ->post(Argument::exact(ApigeeClientInterface::DEFAULT_ENDPOINT . '/o/' . $this->org . '/userroles'), Argument::type('array')) + ->post(Argument::exact(ApigeeClientInterface::EDGE_ENDPOINT . '/o/' . $this->org . '/userroles'), Argument::type('array')) ->shouldBeCalledTimes(1); // The permissions should be set. $this->httpClient - ->post(Argument::exact(ApigeeClientInterface::DEFAULT_ENDPOINT . '/o/' . $this->org . '/userroles/' . ApigeeEdgeManagementCliServiceInterface::DEFAULT_ROLE_NAME . '/permissions'), Argument::type('array')) + ->post(Argument::exact(ApigeeClientInterface::EDGE_ENDPOINT . '/o/' . $this->org . '/userroles/' . ApigeeEdgeManagementCliServiceInterface::DEFAULT_ROLE_NAME . '/permissions'), Argument::type('array')) ->shouldBeCalledTimes(12); $apigee_edge_management_cli_service = new ApigeeEdgeManagementCliService($this->httpClient->reveal()); From ffe510fb523e4541519d5ab207db89202997290e Mon Sep 17 00:00:00 2001 From: Shishir <75600200+shishir-intelli@users.noreply.github.com> Date: Tue, 31 Aug 2021 11:26:54 +0530 Subject: [PATCH 2/4] Fix error when logging with new SAML user (#615) --- src/UserDeveloperConverter.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/UserDeveloperConverter.php b/src/UserDeveloperConverter.php index c28f624f..a8fb6dab 100644 --- a/src/UserDeveloperConverter.php +++ b/src/UserDeveloperConverter.php @@ -90,9 +90,12 @@ public function __construct(ConfigFactory $config_factory, EntityTypeManagerInte */ public function convertUser(UserInterface $user): UserToDeveloperConversionResult { $problems = []; + $developer = NULL; $successful_changes = 0; $email = isset($user->original) ? $user->original->getEmail() : $user->getEmail(); - $developer = $this->entityTypeManager->getStorage('developer')->load($email); + if ($email) { + $developer = $this->entityTypeManager->getStorage('developer')->load($email); + } if (!$developer) { /** @var \Drupal\apigee_edge\Entity\DeveloperInterface $developer */ $developer = $this->entityTypeManager->getStorage('developer')->create([]); From 28dba02b397d0eeb9b3ef1e799e34918f4420051 Mon Sep 17 00:00:00 2001 From: Gitesh Koli Date: Thu, 2 Sep 2021 14:38:20 -0400 Subject: [PATCH 3/4] Added the stale plugin to close issues with no activity. (#613) * Added the stale plugin to close issues with no activity. * We no longer use Travis on this repository Remove Travis configuration file. --- .github/workflows/stale.yml | 28 ++++++++++++ .travis.yml | 88 ------------------------------------- 2 files changed, 28 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/stale.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 00000000..ab88493b --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,28 @@ +name: Mark stale issues and pull requests + +on: + schedule: + - cron: '05 00 * * *' + +jobs: + stale: + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + stale-pr-message: > + This pull request has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + stale-issue-label: 'no-issue-activity' + stale-pr-label: 'no-pr-activity' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2c291363..00000000 --- a/.travis.yml +++ /dev/null @@ -1,88 +0,0 @@ -language: php - -sudo: required - -services: - - docker - -addons: - apt: - packages: - - docker-ce - -cache: - directories: - - $HOME/.composer/cache/files - -notifications: - email: false - -jobs: - include: - # Create a new stage to check coding standards that can run in sequence of test jobs. - - stage: lint - name: "Validate Coding Standards" - script: docker-compose run php phpcs -p -s -n --colors --standard=/opt/drupal-module/phpcs.xml.dist /opt/drupal-module/ - -# Run the lint stage before starting tests. The test job is the default name for the matrix tests. -stages: - - lint - - name: test - if: env(TRAVIS_PULL_REQUEST) = true - -env: - global: - - DOCKER_COMPOSE_VERSION=1.18.0 - - THREADS=4 - matrix: - # Apigee Edge module tests. - - PHP_VERSION=7.1 DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/tests" DB_DRIVER=pgsql DB_IMAGE=wodby/postgres:9.6-1.3.1 - - PHP_VERSION=7.2 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/tests" PHP_IMAGE=wodby/drupal-php:7.2-dev-4.5.0 - - PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/tests" - # Apigee Edge API product RBAC module tests. - - PHP_VERSION=7.1 DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apiproduct_rbac/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apiproduct_rbac/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apiproduct_rbac/tests" DB_DRIVER=pgsql DB_IMAGE=wodby/postgres:9.6-1.3.1 - - PHP_VERSION=7.2 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apiproduct_rbac/tests" PHP_IMAGE=wodby/drupal-php:7.2-dev-4.5.0 - - PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apiproduct_rbac/tests" - # Apigee Edge Teams module tests. - - PHP_VERSION=7.1 DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_teams/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_teams/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_teams/tests" DB_DRIVER=pgsql DB_IMAGE=wodby/postgres:9.6-1.3.1 - - PHP_VERSION=7.2 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_teams/tests" PHP_IMAGE=wodby/drupal-php:7.2-dev-4.5.0 - - PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_teams/tests" - # Apigee Edge API Docs module tests. - - PHP_VERSION=7.1 DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apidocs/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apidocs/tests" - - PHP_VERSION=7.1 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apidocs/tests" DB_DRIVER=pgsql DB_IMAGE=wodby/postgres:9.6-1.3.1 - - PHP_VERSION=7.2 DEPENDENCIES="" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apidocs/tests" PHP_IMAGE=wodby/drupal-php:7.2-dev-4.5.0 - - PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apidocs/tests" -matrix: - allow_failures: - - env: PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/tests" - - env: PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apiproduct_rbac/tests" - - env: PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_teams/tests" - - env: PHP_VERSION=7.1 DRUPAL_CORE=8.7.x-dev DEPENDENCIES="--prefer-lowest" TEST_ROOT="modules/contrib/apigee_edge/modules/apigee_edge_apidocs/tests" - fast_finish: true - -# TODO Cache Docker images and PHP service build (common parts of the built, like Drupal core install, for a day). -before_install: - - sudo rm /usr/local/bin/docker-compose - - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose - - chmod +x docker-compose - - sudo mv docker-compose /usr/local/bin - - cd .travis && chmod u+x *.sh - - docker-compose up -d --build - - docker-compose ps - -script: - # Do not exit if a PHPUnit test fails, we would like to run everything from - # after_* sections. - - set +e - - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then docker-compose run php /opt/drupal-module/.travis/run-test.sh; fi - -after_failure: - # Push log file and browser output to an our logs repository. - - ./push-logs.sh From 0afecaebd5174fb9726062aa030f059cec130de3 Mon Sep 17 00:00:00 2001 From: phdhiren Date: Mon, 6 Sep 2021 10:25:56 +0000 Subject: [PATCH 4/4] Basic Auth is not deprecated for OPDK, Removed deprecated message for private cloud (#619) Fixes #608 --- apigee_edge.install | 3 +- apigee_edge.libraries.yml | 4 +- js/apigee_edge.admin.js | 44 ++++++++++++++++++++++ src/Plugin/KeyInput/ApigeeAuthKeyInput.php | 5 ++- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 js/apigee_edge.admin.js diff --git a/apigee_edge.install b/apigee_edge.install index c7092815..14559ade 100644 --- a/apigee_edge.install +++ b/apigee_edge.install @@ -84,7 +84,8 @@ function apigee_edge_requirements($phase) { // Warning message in status report if using basic auth. try { if ($key && $key->getKeyType() instanceof EdgeKeyTypeInterface && - $key->getKeyType()->getAuthenticationType($key) === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC) { + $key->getKeyType()->getAuthenticationType($key) === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC && + $key->getKeyType()->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC) { $requirements['apigee_edge_http_basic_auth'] = [ 'title' => t('Apigee Edge'), 'description' => t('Apigee Edge HTTP basic authentication will be deprecated. Please choose another authentication method. Visit the Apigee Edge general settings page to get more information.', [ diff --git a/apigee_edge.libraries.yml b/apigee_edge.libraries.yml index e6b09ae6..3b0cea2e 100644 --- a/apigee_edge.libraries.yml +++ b/apigee_edge.libraries.yml @@ -1,8 +1,10 @@ apigee_edge.admin: - version: 1.1 + version: 1.2 css: theme: css/apigee_edge.admin.css: {} + js: + js/apigee_edge.admin.js: {} apigee_edge.analytics: version: 1.0 diff --git a/js/apigee_edge.admin.js b/js/apigee_edge.admin.js new file mode 100644 index 00000000..bfe6b99e --- /dev/null +++ b/js/apigee_edge.admin.js @@ -0,0 +1,44 @@ +/* + * Copyright 2021 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. + */ + +/** + * @file + * Javascript functions related to the Analytics page of app entities. + */ +(function ($, Drupal, drupalSettings) { + + 'use strict'; + + /** + * Apigee edge admin configuration. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + */ + Drupal.behaviors.apigeeEdgeAuthForm = { + attach: function attach(context, drupalSettings) { + $('#edit-key-input-settings-instance-type input:radio').click(function() { + if ($(this).val() === 'private') { + $('#edit-key-input-settings-auth-type option[value="basic"]').text(Drupal.t('HTTP basic')); + } else if ($(this).val() === 'public') { + $('#edit-key-input-settings-auth-type option[value="basic"]').text(Drupal.t('HTTP basic (deprecated)')); + } + }); + } + } +})(jQuery, Drupal, drupalSettings); diff --git a/src/Plugin/KeyInput/ApigeeAuthKeyInput.php b/src/Plugin/KeyInput/ApigeeAuthKeyInput.php index dc1a09fd..b1128163 100644 --- a/src/Plugin/KeyInput/ApigeeAuthKeyInput.php +++ b/src/Plugin/KeyInput/ApigeeAuthKeyInput.php @@ -46,7 +46,7 @@ class ApigeeAuthKeyInput extends KeyInputBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $values = $this->getFormDefaultValues($form_state); - if (!empty($values['auth_type']) && $values['auth_type'] == EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC) { + if (!empty($values['auth_type']) && $values['auth_type'] == EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC && !empty($values['instance_type']) && $values['instance_type'] == EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC) { $this->messenger()->addWarning($this->t('HTTP basic authentication will be deprecated. Please choose another authentication method.')); } @@ -89,6 +89,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta 'required' => [$state_for_public, $state_for_private], ], ]; + if (!empty($values['instance_type']) && EdgeKeyTypeInterface::INSTANCE_TYPE_PRIVATE === $values['instance_type']) { + $form['auth_type']['#options'][EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC] = $this->t('HTTP basic'); + } $form['organization'] = [ '#type' => 'textfield', '#title' => $this->t('Organization'),