Comments

Xiaohua Guan created an issue. See original summary.

xiaohua guan’s picture

StatusFileSize
new39.1 KB
xiaohua guan’s picture

Status: Active » Needs review

@yas

Please review the patch file. Thanks.

yas’s picture

Status: Needs review » Needs work

@xiaohua-guan

Thank you for providing the patch. I tried to apply it, but it got behind due to previous merge? Could you please re-create the patch again?

$ git apply -v /tmp/3108485-2.patch 
Checking patch modules/cloud_service_providers/aws_cloud/aws_cloud.info.yml...
Checking patch modules/cloud_service_providers/aws_cloud/aws_cloud.module...
Checking patch modules/cloud_service_providers/aws_cloud/aws_cloud.services.yml...
Checking patch modules/cloud_service_providers/aws_cloud/composer.json...
Checking patch modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php...
error: while searching for:
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\aws_cloud\Service\Pricing\GoogleSpreadsheetService;
use Drupal\aws_cloud\Service\Pricing\PricingService;
use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface;
use Drupal\Core\Config\Config;

error: patch failed: modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php:7
error: modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php: patch does not apply
Checking patch modules/cloud_service_providers/aws_cloud/src/Service/Pricing/GoogleSpreadsheetService.php...
error: while searching for:
<?php

namespace Drupal\aws_cloud\Service\Pricing;

use Google_Client;
use Google_Service_Exception;
use Google_Service_Drive;
use Google_Service_Drive_Permission;
use Google_Service_Sheets;
use Google_Service_Sheets_Spreadsheet;
use Google_Service_Sheets_ValueRange;
use Google_Service_Sheets_BatchUpdateSpreadsheetRequest;
use Google_Service_Sheets_Request;

use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * The google spreadsheet service.
 */
class GoogleSpreadsheetService {

  use StringTranslationTrait;

  /**
   * The Messenger service.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * The config factory.
   *
   * Subclasses should use the self::config() method, which may be overridden to
   * address specific needs when loading config, rather than this property
   * directly. See \Drupal\Core\Form\ConfigFormBase::config() for an example of
   * this.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The price data provider.
   *
   * @var \Drupal\aws_cloud\Service\pricing\InstanceTypePriceDataProvider
   */
  protected $dataProvider;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   The messenger service.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   A configuration factory.
   * @param \Drupal\aws_cloud\Service\pricing\InstanceTypePriceDataProvider $data_provider
   *   The price data provider.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   */
  public function __construct(
    MessengerInterface $messenger,
    ConfigFactoryInterface $config_factory,
    InstanceTypePriceDataProvider $data_provider,
    TranslationInterface $string_translation
  ) {
    $this->messenger = $messenger;
    $this->configFactory = $config_factory;
    $this->dataProvider = $data_provider;
    $this->stringTranslation = $string_translation;
  }

  /**
   * Create or update a spreadsheet.
   *
   * @param string $spreadsheet_url
   *   The url of the spreadsheet.
   * @param string $region
   *   The name of an Amazon EC2 region.
   * @param string $title
   *   The title of the spreadsheet.
   *
   * @return string
   *   The url of the spreadsheet created.
   */
  public function createOrUpdate($spreadsheet_url, $region, $title) {
    try {
      $spreadsheet_id = NULL;
      if (!empty($spreadsheet_url)) {
        if (preg_match('/spreadsheets\/d\/(.+)\/edit/', $spreadsheet_url, $matches)) {
          $spreadsheet_id = $matches[1];
        }
      }

      // Get the API client and construct the service object.
      $client = $this->getClient();
      $service = new Google_Service_Sheets($client);

      // Create spreadsheet if spreadsheet ID is NULL.
      if (empty($spreadsheet_id)) {
        $spreadsheet = $this->createSpreadsheet($client, $service, $title);
        $spreadsheet_id = $spreadsheet->getSpreadsheetId();
      }
      else {
        $spreadsheet = $service->spreadsheets->get($spreadsheet_id);
      }

      // Add or update the sheet for region.
      $sheet = $this->findSheet($service, $spreadsheet, $region);
      if ($sheet === NULL) {
        $sheet = $this->createSheet($service, $spreadsheet, $region);
      }

      $sheet_id = $sheet->getProperties()->getSheetId();
      $sheet_title = $sheet->getProperties()->getTitle();

      // Append data.
      $values = $this->getValues(
        $this->dataProvider->getFields(),
        $this->dataProvider->getDataByRegion($region)
      );
      $request_body = new Google_Service_Sheets_ValueRange(['values' => $values]);
      $service->spreadsheets_values->update(
        $spreadsheet_id,
        $sheet_title . '!A1',
        $request_body,
        ['valueInputOption' => 'USER_ENTERED']
      );

      $requests = [];
    
error: patch failed: modules/cloud_service_providers/aws_cloud/src/Service/Pricing/GoogleSpreadsheetService.php:1
error: modules/cloud_service_providers/aws_cloud/src/Service/Pricing/GoogleSpreadsheetService.php: patch does not apply
Checking patch modules/cloud_service_providers/aws_cloud/tests/src/Functional/AwsCloudTestCase.php...
Hunk #3 succeeded at 197 (offset 3 lines).
Checking patch modules/gapps/composer.json...
Checking patch modules/gapps/gapps.info.yml...
Checking patch modules/gapps/gapps.services.yml...
Checking patch modules/gapps/src/Service/GoogleSpreadsheetService.php...
xiaohua guan’s picture

StatusFileSize
new38.98 KB
xiaohua guan’s picture

Status: Needs work » Needs review

@yas

I created a new patch file. Please review it. Thanks.

yas’s picture

Status: Needs review » Needs work

@xiaohua-guan

Thank you for the update. One more thing, could you please sort out the namespace by alphabetical order? Please refer to the patch at #3107638

xiaohua guan’s picture

StatusFileSize
new40.11 KB
xiaohua guan’s picture

Status: Needs work » Needs review

@yas

I reordered import codes. Please review the new patch file. Thanks.

yas’s picture

Status: Needs review » Needs work
StatusFileSize
new1.08 MB

@xiaohua-guan

Thank you for the update.

I tested the patch again manually, and I received the following Internal Server Error when I access to AWS Cloud settings:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "gapps.google_spreadsheet". in Drupal\Component\DependencyInjection\Container->get() (line 153 of /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php).

It happens when Google Application module is not enabled. The above error might not happen because AWS Cloud, K8s to S3 and S3 to K8s module requires Google Application module, but could you please take care of the dependency just in case?

screenshot-20200130a.png

xiaohua guan’s picture

StatusFileSize
new77.61 KB
xiaohua guan’s picture

@yas

Please review the patch file. Thanks.

xiaohua guan’s picture

Status: Needs work » Needs review
yas’s picture

StatusFileSize
new745.14 KB
new696.54 KB
new597.63 KB

@xiaohua-guan

Thank you for the update. I found the following:

  1. I received Failed to create spreadsheet due to the Exception with error "file "private://gapps/.gapps/client_secret.json" does not exist The private directory (sites/default/files/private) has full permissions (777).
    screenshot-2020-02-02a.png
    $ pwd
    /var/www/html/web/sites/default/files/private
    $ ls -la .
    total 16
    drwxrwxrwx  3 ubuntu ubuntu 4096 Jun 29  2019 .
    drwxrwxrwx 10 ubuntu ubuntu 4096 Dec 11 14:48 ..
    drwxrwxrwx  3 ubuntu ubuntu 4096 Jun 29  2019 aws_cloud
    -rwxrwxrwx  1 ubuntu ubuntu  686 Jun 29  2019 .htaccess
    
  2. Instance Types Price Spreadsheet option should be placed to gapps settings? Or we need to check module_exists?
    screenshot-2020-02-02b.png
  3. Could you please put a fieldset to Gapps admin settings?
    screenshot-20200202c.png
  4. Now I wonder what the appropriate name about Google Apps. G Suite, G Apps, GApps, Google Apps, Google Application, Google Applications, GApps? We should respect the third-party's product name or trademarks. What do you think?
yas’s picture

Status: Needs review » Needs work
xiaohua guan’s picture

StatusFileSize
new77.75 KB
xiaohua guan’s picture

@yas

Thanks for your comment.

About 3, I added a field set.

About 1, I think it should configure credentials in gapps admin page.

About 2, I've added module_exists to check gapps. If gapps doesn't exist, I disabled the checkbox.

About 4, The gapps is good to me. It would be better to change upper case to GApps.

xiaohua guan’s picture

Status: Needs work » Needs review
yas’s picture

Status: Needs review » Needs work
StatusFileSize
new1.12 MB
new1.01 MB
new1.29 MB

@xiaohua-guan

Thank you for the update. I tested it, and found the following:

screenshot--2020-02-03a.png
screenshot--2020-02-03b.png
screenshot--2020-02-03c.png

Could you please double-check the ones?

xiaohua guan’s picture

StatusFileSize
new77.88 KB
xiaohua guan’s picture

@yas

I am sorry for the mistakes. I fixed them.

About "After input '{"aaa": "bbb"}' and save it, the google credential is empty", it's the spec as same as before. At that time, due to the security, the credential wasn't shown in the page.

yas’s picture

Issue summary: View changes
StatusFileSize
new913.07 KB
new797.58 KB
yas’s picture

Issue summary: View changes

@xiaohua-guan

Thank you for the update. I tried to test the patch:

  1. I couldn't find GApps Settings menu in Admin | Configuration. I also try to access http://example.com/admin/config/services/cloud/gapps/settings but it showed Page not found. I cleared the caches or rebuilt menus. Could you please double-check? The previous patch worked.
  2. The Instance Types Prices Spreadsheet option is disabled while the Google Application module is disabled, this is good (thanks), however I think it is better to have check-off state. If enabled, the option should be enabled with check-on state.
    screenshot-2020-02-04a.png
  3. When we want to uninstall Google Application module, it needs to remove cloud server template type entities. Probably this issue needs to separate to another issue.
    screenshot-2020-02-04b.png
xiaohua guan’s picture

StatusFileSize
new79.36 KB
xiaohua guan’s picture

Status: Needs work » Needs review

@yas

I changed DOMAIN to example.com, and added description below.

Please review the patch file. Thanks.

      '#description' => $this->t('Enable Instance Type Prices Spreadsheet. If this checkbox is disabled, please install the module %name in %link.',
        [
          '%name' => 'Google Application',
          '%link' => Link::fromTextAndUrl(
            $this->t('Extend'),
            Url::fromRoute(
              'system.modules_list', []
            )
          )->toString(),
        ]
      ),
yas’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new828.52 KB

@xiaohua-guan

Thank you for the update. I tested it and looks good to me now. I'll merge the patch to 8.x-1.x and 8.x-2.x and close this issue as Fixed.

screenshot-20200205a.png

  • yas committed afcf07e on 8.x-1.x authored by Xiaohua Guan
    Issue #3108485 by Xiaohua Guan, yas: Separate a module for Google...

  • yas committed 7c2a456 on 8.x-2.x authored by Xiaohua Guan
    Issue #3108485 by Xiaohua Guan, yas: Separate a module for Google...
yas’s picture

Status: Reviewed & tested by the community » Fixed
yas’s picture

xiaohua guan’s picture

Status: Fixed » Needs work
xiaohua guan’s picture

StatusFileSize
new274 bytes
xiaohua guan’s picture

@yas

I fixed the bug in the composer.json. Please review the patch file. Thanks.

xiaohua guan’s picture

Status: Needs work » Needs review
yas’s picture

Status: Needs review » Reviewed & tested by the community

@xiaohua-guan

Thank you for fixing the issue. I'll merge the patch to 8.x-1.x and 8.x-2.x and close this issue as Fixed.

  • yas committed 9075125 on 8.x-1.x authored by Xiaohua Guan
    Issue #3108485 by Xiaohua Guan, yas: Hotfix - Separate a module for...

  • yas committed c7bf28c on 8.x-2.x authored by Xiaohua Guan
    Issue #3108485 by Xiaohua Guan, yas: Hotfix - Separate a module for...
yas’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.