Skip to content

Commit

Permalink
Optimize global product support (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliguyong authored May 22, 2020
1 parent ae6d8f7 commit 23e1ab1
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 1.5.23 - 2020-05-22
- Optimized global product support.

## 1.5.22 - 2020-05-12
- Updated Endpoints.

Expand Down
2 changes: 1 addition & 1 deletion src/AlibabaCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/Config/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[
'dysmsapi' =>
[
'global' => 'dysmsapi.aliyuncs.com',
'cn-hangzhou' => 'dysmsapi.aliyuncs.com',
'ap-southeast-1' => 'dysmsapi.ap-southeast-1.aliyuncs.com',
],
Expand Down
4 changes: 4 additions & 0 deletions src/Request/Traits/AcsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions src/Traits/EndpointTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions tests/Feature/Product/RamTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace AlibabaCloud\Client\Tests\Feature\Product;

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use PHPUnit\Framework\TestCase;


class RamTest extends TestCase
{
/**
* @throws ClientException
*/
public function setUp()
{
parent::setUp();

AlibabaCloud::accessKeyClient(\getenv('ACCESS_KEY_ID'), \getenv('ACCESS_KEY_SECRET'))
->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']));
}
}
14 changes: 13 additions & 1 deletion tests/Unit/Traits/EndpointTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 23e1ab1

Please sign in to comment.