From 23e1ab1b4789bf3e79c1f88815b80bc7786ab817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E7=A5=9E=E5=AE=97?= Date: Fri, 22 May 2020 22:39:20 +0800 Subject: [PATCH] Optimize global product support (#216) --- CHANGELOG.md | 3 ++ src/AlibabaCloud.php | 2 +- src/Config/Data.php | 1 - src/Request/Traits/AcsTrait.php | 4 +++ src/Traits/EndpointTrait.php | 11 +++++++ tests/Feature/Product/RamTest.php | 40 +++++++++++++++++++++++++ tests/Unit/Traits/EndpointTraitTest.php | 14 ++++++++- 7 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/Product/RamTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f3ca565..e103ed10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 1.5.23 - 2020-05-22 +- Optimized global product support. + ## 1.5.22 - 2020-05-12 - Updated Endpoints. diff --git a/src/AlibabaCloud.php b/src/AlibabaCloud.php index 7c272f50..6aa99a11 100644 --- a/src/AlibabaCloud.php +++ b/src/AlibabaCloud.php @@ -30,7 +30,7 @@ class AlibabaCloud /** * Version of the Client */ - const VERSION = '1.5.22'; + const VERSION = '1.5.23'; /** * This static method can directly call the specific service. diff --git a/src/Config/Data.php b/src/Config/Data.php index d5c0c822..b2b29e54 100644 --- a/src/Config/Data.php +++ b/src/Config/Data.php @@ -5,7 +5,6 @@ [ 'dysmsapi' => [ - 'global' => 'dysmsapi.aliyuncs.com', 'cn-hangzhou' => 'dysmsapi.aliyuncs.com', 'ap-southeast-1' => 'dysmsapi.ap-southeast-1.aliyuncs.com', ], diff --git a/src/Request/Traits/AcsTrait.php b/src/Request/Traits/AcsTrait.php index 571ed76e..5b2dd6bf 100644 --- a/src/Request/Traits/AcsTrait.php +++ b/src/Request/Traits/AcsTrait.php @@ -250,6 +250,10 @@ public function realRegionId() return AlibabaCloud::getDefaultRegionId(); } + if ($this->product && AlibabaCloud::isGlobalProduct($this->product)) { + return 'global'; + } + throw new ClientException("Missing required 'RegionId' for Request", SDK::INVALID_REGION_ID); } } diff --git a/src/Traits/EndpointTrait.php b/src/Traits/EndpointTrait.php index 9c737818..33c229c8 100644 --- a/src/Traits/EndpointTrait.php +++ b/src/Traits/EndpointTrait.php @@ -53,6 +53,17 @@ public static function resolveHost($product, $regionId = LocationService::GLOBAL return $domain; } + /** + * @param $productCode + * + * @return bool + */ + public static function isGlobalProduct($productCode) + { + $productCode = strtolower($productCode); + return (bool)Config::get("endpoints.{$productCode}.global"); + } + /** * @param string $product * @param string $regionId diff --git a/tests/Feature/Product/RamTest.php b/tests/Feature/Product/RamTest.php new file mode 100644 index 00000000..9dd588a6 --- /dev/null +++ b/tests/Feature/Product/RamTest.php @@ -0,0 +1,40 @@ +asDefaultClient(); + } + + /** + * @throws ClientException + * @throws \AlibabaCloud\Client\Exception\ServerException + */ + public function testRamByCore() + { + $result = AlibabaCloud::rpc() + ->product('ram') + ->version('2015-05-01') + ->method('POST') + ->action('ListAccessKeys') + ->scheme('https') + ->connectTimeout(25) + ->timeout(30) + ->request(); + self::assertTrue(isset($result['AccessKeys'])); + } +} diff --git a/tests/Unit/Traits/EndpointTraitTest.php b/tests/Unit/Traits/EndpointTraitTest.php index c637b407..80259f84 100644 --- a/tests/Unit/Traits/EndpointTraitTest.php +++ b/tests/Unit/Traits/EndpointTraitTest.php @@ -185,10 +185,22 @@ public function testAddGlobalHost() public function testGlobal() { // Assert - self::assertEquals('dysmsapi.aliyuncs.com', AlibabaCloud::resolveHost('dysmsapi')); + self::assertEquals('', AlibabaCloud::resolveHost('dysmsapi')); self::assertEquals('dysmsapi.aliyuncs.com', AlibabaCloud::resolveHost('dysmsapi', 'cn-hangzhou')); } + + public function testIsGlobalProduct() + { + self::assertTrue(AlibabaCloud::isGlobalProduct('ccc')); + self::assertFalse(AlibabaCloud::isGlobalProduct('no')); + self::assertTrue(AlibabaCloud::isGlobalProduct('Ram')); + self::assertTrue(AlibabaCloud::isGlobalProduct('ram')); + self::assertFalse(AlibabaCloud::isGlobalProduct('tdsr')); + self::assertFalse(AlibabaCloud::isGlobalProduct('')); + self::assertFalse(AlibabaCloud::isGlobalProduct(null)); + } + /** * Test for Null *