Skip to content
Snippets Groups Projects
Commit e5ca6744 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3089560 by Xiaohua Guan, yas: Make the $ec2PricingEndpoint variable...

Issue #3089560 by Xiaohua Guan, yas: Make the $ec2PricingEndpoint variable configurable for AWS Pricing API
parent f38b3d24
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\aws_cloud\Service\Pricing\PricingService;
/**
* Implements hook_uninstall().
*/
......@@ -1572,6 +1574,16 @@ function aws_cloud_update_8188() {
$config->save();
}
/**
* Add EC2 pricing endpoint configuration item.
*/
function aws_cloud_update_8189() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('aws_cloud.settings');
$config->set('aws_cloud_ec2_pricing_endpoint', PricingService::DEFAULT_ENDPOINT);
$config->save();
}
/**
* Helper function to add fields to the entity type.
*
......
......@@ -39,4 +39,5 @@ aws_cloud_instance_type_cost_list: true
aws_cloud_instance_list_cost_column: true
google_credential_file_path: 'private://aws_cloud/.gapps/client_secrets.json'
google_credential_signature: ''
aws_cloud_ec2_pricing_endpoint: 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current'
aws_cloud_price_rate_ec2: 100
......@@ -105,5 +105,7 @@ aws_cloud.settings:
type: string
google_credential_signature:
type: string
aws_cloud_ec2_pricing_endpoint:
type: string
aws_cloud_price_rate_ec2:
type: integer
......@@ -8,6 +8,7 @@ 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;
......@@ -589,6 +590,16 @@ class AwsCloudAdminSettings extends ConfigFormBase {
'#default_value' => $config->get('aws_cloud_instance_list_cost_column'),
];
$form['cost_management']['aws_cloud_ec2_pricing_endpoint'] = [
'#type' => 'textfield',
'#title' => $this->t('EC2 Pricing Endpoint'),
'#description' => $this->t('The endpoint of EC2 pricing service.'),
'#size' => 80,
'#default_value' =>
$config->get('aws_cloud_ec2_pricing_endpoint')
?: PricingService::DEFAULT_ENDPOINT,
];
$form['price_rate'] = [
'#type' => 'details',
'#title' => $this->t('Price Rate'),
......
......@@ -18,6 +18,8 @@ class PricingService implements PricingServiceInterface {
use StringTranslationTrait;
const DEFAULT_ENDPOINT = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current';
/**
* The Messenger service.
*
......@@ -72,13 +74,6 @@ class PricingService implements PricingServiceInterface {
*/
private $dryRun;
/**
* The base url for the pricing endpoint.
*
* @var string
*/
private $ec2PricingEndpoint = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current';
/**
* The cloud service provider (CloudConfig) entity.
*
......@@ -147,7 +142,15 @@ class PricingService implements PricingServiceInterface {
private function getPricingEndpoint() {
$endpoint = FALSE;
if ($this->cloudConfigEntity != FALSE) {
$endpoint = $this->ec2PricingEndpoint . "/{$this->cloudConfigEntity->get('field_region')->value}/index.json";
$pricing_endpoint = $this->configFactory
->get('aws_cloud.settings')
->get('aws_cloud_ec2_pricing_endpoint');
if (empty($pricing_endpoint)) {
$pricing_endpoint = self::DEFAULT_ENDPOINT;
}
$endpoint = "$pricing_endpoint/{$this->cloudConfigEntity->get('field_region')->value}/index.json";
}
return $endpoint;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment