Skip to content

Commit 23e1ab1

Browse files
authored
Optimize global product support (#216)
1 parent ae6d8f7 commit 23e1ab1

File tree

7 files changed

+72
-3
lines changed

7 files changed

+72
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 1.5.23 - 2020-05-22
4+
- Optimized global product support.
5+
36
## 1.5.22 - 2020-05-12
47
- Updated Endpoints.
58

src/AlibabaCloud.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AlibabaCloud
3030
/**
3131
* Version of the Client
3232
*/
33-
const VERSION = '1.5.22';
33+
const VERSION = '1.5.23';
3434

3535
/**
3636
* This static method can directly call the specific service.

src/Config/Data.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[
66
'dysmsapi' =>
77
[
8-
'global' => 'dysmsapi.aliyuncs.com',
98
'cn-hangzhou' => 'dysmsapi.aliyuncs.com',
109
'ap-southeast-1' => 'dysmsapi.ap-southeast-1.aliyuncs.com',
1110
],

src/Request/Traits/AcsTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ public function realRegionId()
250250
return AlibabaCloud::getDefaultRegionId();
251251
}
252252

253+
if ($this->product && AlibabaCloud::isGlobalProduct($this->product)) {
254+
return 'global';
255+
}
256+
253257
throw new ClientException("Missing required 'RegionId' for Request", SDK::INVALID_REGION_ID);
254258
}
255259
}

src/Traits/EndpointTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ public static function resolveHost($product, $regionId = LocationService::GLOBAL
5353
return $domain;
5454
}
5555

56+
/**
57+
* @param $productCode
58+
*
59+
* @return bool
60+
*/
61+
public static function isGlobalProduct($productCode)
62+
{
63+
$productCode = strtolower($productCode);
64+
return (bool)Config::get("endpoints.{$productCode}.global");
65+
}
66+
5667
/**
5768
* @param string $product
5869
* @param string $regionId

tests/Feature/Product/RamTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace AlibabaCloud\Client\Tests\Feature\Product;
4+
5+
use AlibabaCloud\Client\AlibabaCloud;
6+
use AlibabaCloud\Client\Exception\ClientException;
7+
use PHPUnit\Framework\TestCase;
8+
9+
10+
class RamTest extends TestCase
11+
{
12+
/**
13+
* @throws ClientException
14+
*/
15+
public function setUp()
16+
{
17+
parent::setUp();
18+
19+
AlibabaCloud::accessKeyClient(\getenv('ACCESS_KEY_ID'), \getenv('ACCESS_KEY_SECRET'))
20+
->asDefaultClient();
21+
}
22+
23+
/**
24+
* @throws ClientException
25+
* @throws \AlibabaCloud\Client\Exception\ServerException
26+
*/
27+
public function testRamByCore()
28+
{
29+
$result = AlibabaCloud::rpc()
30+
->product('ram')
31+
->version('2015-05-01')
32+
->method('POST')
33+
->action('ListAccessKeys')
34+
->scheme('https')
35+
->connectTimeout(25)
36+
->timeout(30)
37+
->request();
38+
self::assertTrue(isset($result['AccessKeys']));
39+
}
40+
}

tests/Unit/Traits/EndpointTraitTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,22 @@ public function testAddGlobalHost()
185185
public function testGlobal()
186186
{
187187
// Assert
188-
self::assertEquals('dysmsapi.aliyuncs.com', AlibabaCloud::resolveHost('dysmsapi'));
188+
self::assertEquals('', AlibabaCloud::resolveHost('dysmsapi'));
189189
self::assertEquals('dysmsapi.aliyuncs.com', AlibabaCloud::resolveHost('dysmsapi', 'cn-hangzhou'));
190190
}
191191

192+
193+
public function testIsGlobalProduct()
194+
{
195+
self::assertTrue(AlibabaCloud::isGlobalProduct('ccc'));
196+
self::assertFalse(AlibabaCloud::isGlobalProduct('no'));
197+
self::assertTrue(AlibabaCloud::isGlobalProduct('Ram'));
198+
self::assertTrue(AlibabaCloud::isGlobalProduct('ram'));
199+
self::assertFalse(AlibabaCloud::isGlobalProduct('tdsr'));
200+
self::assertFalse(AlibabaCloud::isGlobalProduct(''));
201+
self::assertFalse(AlibabaCloud::isGlobalProduct(null));
202+
}
203+
192204
/**
193205
* Test for Null
194206
*

0 commit comments

Comments
 (0)