Skip to content

Commit

Permalink
improved endpoint map (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliguyong authored Jul 18, 2019
1 parent 407913b commit 68b4fb1
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 17 deletions.
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.12';
const VERSION = '1.5.13';

/**
* This static method can directly call the specific service.
Expand Down
115 changes: 102 additions & 13 deletions src/Config/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@
'ap-southeast-1' => 'live.aliyuncs.com',
'ap-northeast-1' => 'live.aliyuncs.com',
'eu-central-1' => 'live.aliyuncs.com',
'ap-southeast-5' => 'live.aliyuncs.com',
'ap-south-1' => 'live.aliyuncs.com',
],
'ubsms' =>
[
Expand Down Expand Up @@ -1678,6 +1680,10 @@
'cn-shenzhen' => 'polardb.aliyuncs.com',
'cn-hongkong' => 'polardb.aliyuncs.com',
'cn-zhangjiakou' => 'polardb.cn-zhangjiakou.aliyuncs.com',
'ap-southeast-1' => 'polardb.aliyuncs.com',
'ap-southeast-3' => 'polardb.ap-southeast-3.aliyuncs.com',
'ap-southeast-5' => 'polardb.ap-southeast-5.aliyuncs.com',
'us-west-1' => 'polardb.us-west-1us-west-1.aliyuncs.com',
],
'actiontrail' =>
[
Expand Down Expand Up @@ -1842,7 +1848,8 @@
],
'cloudfirewall' =>
[
'cn-hangzhou' => 'cloudfw.cn-hangzhou.aliyuncs.com',
'cn-hangzhou' => 'cloudfw.cn-hangzhou.aliyuncs.com',
'ap-southeast-1' => 'cloudfw.ap-southeast-1.aliyuncs.com',
],
'ens' =>
[
Expand Down Expand Up @@ -1947,10 +1954,16 @@
'cn-beijing' => 'baas.aliyuncs.com',
'cn-shanghai' => 'baas.aliyuncs.com',
'cn-shenzhen' => 'baas.aliyuncs.com',
'cn-hongkong' => 'baas.aliyuncs.com',
'ap-southeast-2' => 'baas.aliyuncs.com',
'us-east-1' => 'baas.aliyuncs.com',
'cn-hongkong' => 'baas.cn-hongkong.aliyuncs.com',
'ap-southeast-2' => 'baas.ap-southeast-2.aliyuncs.com',
'us-east-1' => 'baas.us-east-1.aliyuncs.com',
'eu-central-1' => 'baas.aliyuncs.com',
'cn-qingdao' => 'baas.aliyuncs.com',
'cn-zhangjiakou' => 'baas.aliyuncs.com',
'cn-huhehaote' => 'baas.aliyuncs.com',
'eu-west-1' => 'baas.eu-west-1.aliyuncs.com',
'us-west-1' => 'baas.aliyuncs.com',
'ap-south-1' => 'baas.aliyuncs.com',
],
'alimt' =>
[
Expand Down Expand Up @@ -2118,15 +2131,17 @@
'ap-southeast-1' => 'drds.ap-southeast-1.aliyuncs.com',
'cn-shanghai' => 'drds.cn-shanghai.aliyuncs.com',
'cn-hongkong' => 'drds.cn-hangzhou.aliyuncs.com',
'cn-huhehaote' => 'drds.cn-huhehaote.aliyuncs.com',
],
'drdspre' =>
[
'cn-qingdao' => 'drds.cn-qingdao.aliyuncs.com',
'cn-beijing' => 'drds.cn-beijing.aliyuncs.com',
'cn-hangzhou' => 'drds.cn-hangzhou.aliyuncs.com',
'cn-shanghai' => 'drds.cn-shanghai.aliyuncs.com',
'cn-shenzhen' => 'drds.cn-shenzhen.aliyuncs.com',
'cn-hongkong' => 'drds.cn-hangzhou.aliyuncs.com',
'cn-qingdao' => 'drds.cn-qingdao.aliyuncs.com',
'cn-beijing' => 'drds.cn-beijing.aliyuncs.com',
'cn-hangzhou' => 'drds.cn-hangzhou.aliyuncs.com',
'cn-shanghai' => 'drds.cn-shanghai.aliyuncs.com',
'cn-shenzhen' => 'drds.cn-shenzhen.aliyuncs.com',
'cn-hongkong' => 'drds.cn-hangzhou.aliyuncs.com',
'cn-huhehaote' => 'drds.cn-huhehaote.aliyuncs.com',
],
'acr' =>
[
Expand Down Expand Up @@ -2183,7 +2198,7 @@
'vcsbasic' =>
[
'cn-hangzhou' => 'vcsbasic.aliyuncs.com',
'cn-shanghai' => 'vcsbasic.cn-shanghai.aliyuncs.com',
'cn-shanghai' => 'vcs.cn-shanghai.aliyuncs.com',
],
'hbr' =>
[
Expand All @@ -2206,6 +2221,7 @@
'cn-beijing' => 'webplus.cn-hangzhou.aliyuncs.com',
'cn-zhangjiakou' => 'webplus.cn-hangzhou.aliyuncs.com',
'cn-shanghai' => 'webplus.cn-hangzhou.aliyuncs.com',
'cn-hangzhou' => 'webplus.cn-hangzhou.aliyuncs.com',
],
'sddp' =>
[
Expand All @@ -2214,6 +2230,8 @@
'oos' =>
[
'cn-hangzhou' => 'oos.cn-hangzhou.aliyuncs.com',
'cn-shanghai' => 'oos.cn-shanghai.aliyuncs.com',
'cn-shenzhen' => 'oos.cn-shenzhen.aliyuncs.com',
],
'fnf' =>
[
Expand All @@ -2222,8 +2240,25 @@
],
'smc' =>
[
'cn-huhehaote' => 'smc.aliyuncs.com',
'cn-hangzhou' => 'smc.aliyuncs.com',
'cn-huhehaote' => 'smc.aliyuncs.com',
'cn-hangzhou' => 'smc.aliyuncs.com',
'cn-qingdao' => 'smc.aliyuncs.com',
'cn-beijing' => 'smc.aliyuncs.com',
'cn-zhangjiakou' => 'smc.aliyuncs.com',
'cn-shanghai' => 'smc.aliyuncs.com',
'cn-shenzhen' => 'smc.aliyuncs.com',
'cn-hongkong' => 'smc.aliyuncs.com',
'ap-southeast-1' => 'smc.aliyuncs.com',
'ap-southeast-2' => 'smc.aliyuncs.com',
'ap-southeast-3' => 'smc.aliyuncs.com',
'ap-southeast-5' => 'smc.aliyuncs.com',
'ap-northeast-1' => 'smc.aliyuncs.com',
'eu-west-1' => 'smc.aliyuncs.com',
'us-west-1' => 'smc.aliyuncs.com',
'us-east-1' => 'smc.aliyuncs.com',
'eu-central-1' => 'smc.aliyuncs.com',
'me-east-1' => 'smc.aliyuncs.com',
'ap-south-1' => 'smc.aliyuncs.com',
],
'foasconsole' =>
[
Expand All @@ -2243,5 +2278,59 @@
'cn-hangzhou' => 'sae.cn-hangzhou.aliyuncs.com',
'cn-shanghai' => 'sae.cn-shanghai.aliyuncs.com',
],
'ivpd' =>
[
'cn-huhehaote' => 'ivpd.cn-huhehaote.aliyuncs.com',
'cn-shanghai' => 'ivpd.cn-shanghai.aliyuncs.com',
],
'hivisengine' =>
[
'cn-huhehaote' => 'hivisengine.aliyuncs.com',
'cn-shanghai' => 'hivisengine.cn-shanghai.aliyuncs.com',
],
'hiknoengine' =>
[
'cn-huhehaote' => 'hiknoengine.aliyuncs.com',
'cn-shanghai' => 'hiknoengine.cn-shanghai.aliyuncs.com',
],
'clouddev' =>
[
'cn-hangzhou' => 'mpserverless.aliyuncs.com',
'cn-shanghai' => 'mpserverless.aliyuncs.com',
],
'premiumpics' =>
[
'cn-hangzhou' => 'premiumpics.aliyuncs.com',
],
'composer' =>
[
'cn-hangzhou' => 'composer.cn-hangzhou.aliyuncs.com',
'cn-shanghai' => 'composer.cn-shanghai.aliyuncs.com',
],
'cloudesl' =>
[
'cn-hangzhou' => 'cloudesl.cn-hangzhou.aliyuncs.com',
],
'amscloudapp' =>
[
'cn-hangzhou' => 'mpca.cn-hangzhou.aliyuncs.com',
'cn-shanghai' => 'mpca.cn-shanghai.aliyuncs.com',
],
'mse' =>
[
'cn-hangzhou' => 'mse.cn-hangzhou.aliyuncs.com',
],
'dg' =>
[
'cn-hangzhou' => 'dg.cn-hangzhou.aliyuncs.com',
],
'graphcompute' =>
[
'cn-shanghai' => 'gcs.cn-shanghai.aliyuncs.com',
],
'cds' =>
[
'ap-southeast-1' => 'cassandra.aliyuncs.com',
],
],
];
56 changes: 55 additions & 1 deletion src/Filter/ApiFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,61 @@ public static function action($action)
}

/**
* @param $version
* @codeCoverageIgnore
*
* @param string $endpointSuffix
*
* @return mixed
* @throws ClientException
*/
public static function endpointSuffix($endpointSuffix)
{
if (!is_string($endpointSuffix)) {
throw new ClientException(
'Endpoint Suffix must be a string',
SDK::INVALID_ARGUMENT
);
}

if ($endpointSuffix === '') {
throw new ClientException(
'Endpoint Suffix cannot be empty',
SDK::INVALID_ARGUMENT
);
}

return $endpointSuffix;
}

/**
* @codeCoverageIgnore
*
* @param string $network
*
* @return mixed
* @throws ClientException
*/
public static function network($network)
{
if (!is_string($network)) {
throw new ClientException(
'Network Suffix must be a string',
SDK::INVALID_ARGUMENT
);
}

if ($network === '') {
throw new ClientException(
'Network Suffix cannot be empty',
SDK::INVALID_ARGUMENT
);
}

return $network;
}

/**
* @param string $version
*
* @return mixed
* @throws ClientException
Expand Down
25 changes: 25 additions & 0 deletions src/Request/Traits/AcsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ public function action($action)
return $this;
}

/**
* @codeCoverageIgnore
*
* @param string $endpointSuffix
*
* @return AcsTrait
* @throws ClientException
*/
public function endpointSuffix($endpointSuffix)
{
$this->endpointSuffix = ApiFilter::endpointSuffix($endpointSuffix);

return $this;
}

/**
* @param string $network
*/
public function network($network)
{
$this->network = ApiFilter::network($network);

return $this;
}

/**
* @param string $version
*
Expand Down
29 changes: 27 additions & 2 deletions src/Resolver/ApiResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace AlibabaCloud\Client\Resolver;

use ReflectionObject;
use AlibabaCloud\Client\Request\Request;
use AlibabaCloud\Client\Exception\ClientException;

/**
Expand Down Expand Up @@ -38,10 +40,10 @@ public function __call($api, $arguments)

if (\class_exists($class)) {
if (isset($arguments[0])) {
return new $class($arguments[0]);
return $this->warpEndpoint(new $class($arguments[0]));
}

return new $class();
return $this->warpEndpoint(new $class());
}

throw new ClientException(
Expand All @@ -50,6 +52,29 @@ public function __call($api, $arguments)
);
}

/**
* @param Request $request
*
* @return Request
*/
public function warpEndpoint(Request $request)
{
$reflect = new ReflectionObject($request);
$product_dir = dirname(dirname($reflect->getFileName()));
$endpoints_json = "$product_dir/endpoints.json";
if (file_exists($endpoints_json)) {
$endpoints = json_decode(file_get_contents($endpoints_json), true);
if (isset($endpoints['endpoint_map'])) {
$request->endpointMap = $endpoints['endpoint_map'];
}
if (isset($endpoints['endpoint_regional'])) {
$request->endpointRegional = $endpoints['endpoint_regional'];
}
}

return $request;
}

/**
* @return mixed
* @throws ClientException
Expand Down

0 comments on commit 68b4fb1

Please sign in to comment.