由丰鲁成发起的CORE SDK自动发布, BUILD_ID=186, 版本号:1.2.9
Signed-off-by: haowei.yao <haowei.yao@alibaba-inc.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
2018-03-14 Version: 1.2.9
|
||||
1, Support predefine endpoints parse
|
||||
|
||||
2018-03-13 Version: 1.2.8
|
||||
1, API GetQuotaHistoryInfo fix field error.
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
#define ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include "AsyncCallerContext.h"
|
||||
#include "ClientConfiguration.h"
|
||||
#include "CoreExport.h"
|
||||
#include "CoreClient.h"
|
||||
#include "CredentialsProvider.h"
|
||||
#include "EndpointProvider.h"
|
||||
#include "CommonRequest.h"
|
||||
#include "CommonResponse.h"
|
||||
#include "CredentialsProvider.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
@@ -50,7 +50,6 @@ namespace AlibabaCloud
|
||||
HttpRequest buildHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
|
||||
HttpRequest buildRoaHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
|
||||
HttpRequest buildRpcHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
|
||||
virtual EndpointOutcome endpoint() const override;
|
||||
JsonOutcome makeRequest(const std::string &endpoint, const CommonRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
|
||||
|
||||
private:
|
||||
@@ -58,7 +57,6 @@ namespace AlibabaCloud
|
||||
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const;
|
||||
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<EndpointProvider> endpointProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -33,20 +33,19 @@ namespace AlibabaCloud
|
||||
class ALIBABACLOUD_CORE_EXPORT CoreClient
|
||||
{
|
||||
public:
|
||||
CoreClient(const ClientConfiguration &configuration);
|
||||
CoreClient(const std::string & servicename, const ClientConfiguration &configuration);
|
||||
virtual ~CoreClient();
|
||||
|
||||
ClientConfiguration configuration()const;
|
||||
std::string serviceName()const;
|
||||
protected:
|
||||
typedef Outcome<Error, std::string> EndpointOutcome;
|
||||
|
||||
HttpClient::HttpResponseOutcome AttemptRequest(const std::string & endpoint, const ServiceRequest &request, HttpRequest::Method method)const;
|
||||
Error buildCoreError(const HttpResponse &response)const;
|
||||
bool hasResponseError(const HttpResponse &response)const;
|
||||
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const = 0;
|
||||
void asyncExecute(Runnable * r)const;
|
||||
virtual EndpointOutcome endpoint()const = 0;
|
||||
private:
|
||||
std::string serviceName_;
|
||||
ClientConfiguration configuration_;
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
HttpClient *httpClient_;
|
||||
|
||||
@@ -19,25 +19,42 @@
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <alibabacloud/core/location/LocationClient.h>
|
||||
#include <alibabacloud/core/CoreClient.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT EndpointProvider
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, std::string> EndpointOutcome;
|
||||
|
||||
EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient,
|
||||
const std::string regionId,
|
||||
const std::string serviceCode,
|
||||
const std::string product,
|
||||
const std::string serviceCode = std::string(),
|
||||
int durationSeconds = 3600);
|
||||
~EndpointProvider();
|
||||
|
||||
std::string getEndpoint();
|
||||
|
||||
EndpointOutcome getEndpoint();
|
||||
private:
|
||||
void loadEndpoint();
|
||||
struct Product
|
||||
{
|
||||
std::string code;
|
||||
std::string locationServiceCode;
|
||||
std::string documentId;
|
||||
std::map<std::string, std::string> regionalEndpoints;
|
||||
std::string globalEndpoint;
|
||||
std::string regionalEndpointPattern;
|
||||
};
|
||||
|
||||
EndpointOutcome loadRemoteEndpoint();
|
||||
bool checkExpiry()const;
|
||||
bool loadInternalProductsInfo();
|
||||
std::string internalEndpoint(const std::string regionId, const std::string product);
|
||||
|
||||
std::mutex cachedMutex_;
|
||||
std::string cachedEndpoint_;
|
||||
@@ -45,7 +62,9 @@ namespace AlibabaCloud
|
||||
int durationSeconds_;
|
||||
std::chrono::system_clock::time_point expiry_;
|
||||
std::string regionId_;
|
||||
std::string product_;
|
||||
std::string serviceCode_;
|
||||
std::list<Product> internalProductsInfo_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -34,7 +34,7 @@ namespace AlibabaCloud
|
||||
public:
|
||||
typedef Outcome<Error, std::string> JsonOutcome;
|
||||
|
||||
RoaServiceClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
RoaServiceClient(const std::string & servicename, const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::shared_ptr<Signer> &signer = std::make_shared<HmacSha1Signer>());
|
||||
virtual ~RoaServiceClient();
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace AlibabaCloud
|
||||
public:
|
||||
typedef Outcome<Error, std::string> JsonOutcome;
|
||||
|
||||
RpcServiceClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
RpcServiceClient(const std::string & servicename, const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::shared_ptr<Signer> &signer = std::make_shared<HmacSha1Signer>());
|
||||
virtual ~RpcServiceClient();
|
||||
|
||||
@@ -42,8 +42,6 @@ namespace AlibabaCloud
|
||||
DescribeEndpointsOutcome describeEndpoints(const Model::DescribeEndpointsRequest &request)const;
|
||||
void describeEndpointsAsync(const Model::DescribeEndpointsRequest& request, const DescribeEndpointsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
|
||||
DescribeEndpointsOutcomeCallable describeEndpointsCallable(const Model::DescribeEndpointsRequest& request) const;
|
||||
private:
|
||||
virtual EndpointOutcome endpoint()const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,6 @@ namespace AlibabaCloud
|
||||
GetCallerIdentityOutcome getCallerIdentity(const Model::GetCallerIdentityRequest &request)const;
|
||||
void getCallerIdentityAsync(const Model::GetCallerIdentityRequest& request, const GetCallerIdentityAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
|
||||
GetCallerIdentityOutcomeCallable getCallerIdentityCallable(const Model::GetCallerIdentityRequest& request) const;
|
||||
private:
|
||||
virtual EndpointOutcome endpoint()const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,39 +28,28 @@ using namespace Location;
|
||||
|
||||
namespace
|
||||
{
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
const std::string SERVICE_NAME = "Common";
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const Credentials &credentials, const ClientConfiguration &configuration) :
|
||||
CoreClient(configuration),
|
||||
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(credentials))
|
||||
CoreClient(SERVICE_NAME, configuration),
|
||||
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(credentials)),
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "ecs");
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
|
||||
CoreClient(configuration),
|
||||
CoreClient(SERVICE_NAME, configuration),
|
||||
credentialsProvider_(credentialsProvider),
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
credentialsProvider_ = credentialsProvider;
|
||||
auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "ecs");
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
|
||||
CoreClient(configuration),
|
||||
CoreClient(SERVICE_NAME, configuration),
|
||||
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret)),
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
credentialsProvider_ = std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret);
|
||||
|
||||
auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "ecs");
|
||||
}
|
||||
|
||||
CommonClient::~CommonClient()
|
||||
@@ -109,11 +98,6 @@ CommonClient::CommonResponseOutcomeCallable CommonClient::commonResponseCallable
|
||||
return task->get_future();
|
||||
}
|
||||
|
||||
CoreClient::EndpointOutcome CommonClient::endpoint() const
|
||||
{
|
||||
return EndpointOutcome();
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint, const ServiceRequest & msg, HttpRequest::Method method) const
|
||||
{
|
||||
return buildHttpRequest(endpoint, dynamic_cast<const CommonRequest& >(msg), method);
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
CoreClient::CoreClient(const ClientConfiguration &configuration) :
|
||||
CoreClient::CoreClient(const std::string & servicename, const ClientConfiguration &configuration) :
|
||||
serviceName_(servicename),
|
||||
configuration_(configuration),
|
||||
httpClient_(new CurlHttpClient)
|
||||
{
|
||||
@@ -44,6 +45,11 @@ ClientConfiguration CoreClient::configuration()const
|
||||
return configuration_;
|
||||
}
|
||||
|
||||
std::string CoreClient::serviceName()const
|
||||
{
|
||||
return serviceName_;
|
||||
}
|
||||
|
||||
void CoreClient::asyncExecute(Runnable * r)const
|
||||
{
|
||||
Executor::instance()->execute(r);
|
||||
|
||||
@@ -17,25 +17,117 @@
|
||||
#include <alibabacloud/core/EndpointProvider.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <json/json.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Location;
|
||||
|
||||
EndpointProvider::EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient, const std::string regionId, const std::string serviceCode, int durationSeconds) :
|
||||
namespace
|
||||
{
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
const std::string jsondata = "{\"products\":["
|
||||
"{\"code\":\"aegis\",\"document_id\":\"28449\",\"location_service_code\":\"vipaegis\",\"regional_endpoints\":[],\"global_endpoint\":\"aegis.cn-hangzhou.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"alidns\",\"document_id\":\"29739\",\"location_service_code\":\"alidns\",\"regional_endpoints\":[],\"global_endpoint\":\"alidns.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"arms\",\"document_id\":\"42924\",\"location_service_code\":\"\",\"regional_endpoints\":[{\"region\":\"ap-southeast-1\",\"endpoint\":\"arms.ap-southeast-1.aliyuncs.com\"},{\"region\":\"cn-beijing\",\"endpoint\":\"arms.cn-beijing.aliyuncs.com\"},{\"region\":\"cn-hangzhou\",\"endpoint\":\"arms.cn-hangzhou.aliyuncs.com\"},{\"region\":\"cn-hongkong\",\"endpoint\":\"arms.cn-hongkong.aliyuncs.com\"},{\"region\":\"cn-qingdao\",\"endpoint\":\"arms.cn-qingdao.aliyuncs.com\"},{\"region\":\"cn-shanghai\",\"endpoint\":\"arms.cn-shanghai.aliyuncs.com\"},{\"region\":\"cn-shenzhen\",\"endpoint\":\"arms.cn-shenzhen.aliyuncs.com\"}],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"arms.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"batchcompute\",\"document_id\":\"44717\",\"location_service_code\":\"\",\"regional_endpoints\":[{\"region\":\"ap-southeast-1\",\"endpoint\":\"batchcompute.ap-southeast-1.aliyuncs.com\"},{\"region\":\"cn-beijing\",\"endpoint\":\"batchcompute.cn-beijing.aliyuncs.com\"},{\"region\":\"cn-hangzhou\",\"endpoint\":\"batchcompute.cn-hangzhou.aliyuncs.com\"},{\"region\":\"cn-huhehaote\",\"endpoint\":\"batchcompute.cn-huhehaote.aliyuncs.com\"},{\"region\":\"cn-qingdao\",\"endpoint\":\"batchcompute.cn-qingdao.aliyuncs.com\"},{\"region\":\"cn-shanghai\",\"endpoint\":\"batchcompute.cn-shanghai.aliyuncs.com\"},{\"region\":\"cn-shenzhen\",\"endpoint\":\"batchcompute.cn-shenzhen.aliyuncs.com\"},{\"region\":\"cn-zhangjiakou\",\"endpoint\":\"batchcompute.cn-zhangjiakou.aliyuncs.com\"},{\"region\":\"us-west-1\",\"endpoint\":\"batchcompute.us-west-1.aliyuncs.com\"}],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"batchcompute.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"ccc\",\"document_id\":\"63027\",\"location_service_code\":\"ccc\",\"regional_endpoints\":[{\"region\":\"cn-hangzhou\",\"endpoint\":\"ccc.cn-hangzhou.aliyuncs.com\"},{\"region\":\"cn-shanghai\",\"endpoint\":\"ccc.cn-shanghai.aliyuncs.com\"}],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"ccc.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"cdn\",\"document_id\":\"27148\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"cdn.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"cds\",\"document_id\":\"62887\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"cds.cn-beijing.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"chatbot\",\"document_id\":\"60760\",\"location_service_code\":\"beebot\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"chatbot.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"cloudapi\",\"document_id\":\"43590\",\"location_service_code\":\"apigateway\",\"regional_endpoints\":[{\"region\":\"ap-northeast-1\",\"endpoint\":\"apigateway.ap-northeast-1.aliyuncs.com\"},{\"region\":\"us-west-1\",\"endpoint\":\"apigateway.us-west-1.aliyuncs.com\"}],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"apigateway.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"cloudauth\",\"document_id\":\"60687\",\"location_service_code\":\"cloudauth\",\"regional_endpoints\":[],\"global_endpoint\":\"cloudauth.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"cloudphoto\",\"document_id\":\"59902\",\"location_service_code\":\"cloudphoto\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"cloudphoto.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"cloudwf\",\"document_id\":\"58111\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"cloudwf.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"cms\",\"document_id\":\"28615\",\"location_service_code\":\"cms\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"cr\",\"document_id\":\"60716\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"cr.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"cs\",\"document_id\":\"26043\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"cs.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"csb\",\"document_id\":\"64837\",\"location_service_code\":\"\",\"regional_endpoints\":[{\"region\":\"cn-beijing\",\"endpoint\":\"csb.cn-beijing.aliyuncs.com\"},{\"region\":\"cn-hangzhou\",\"endpoint\":\"csb.cn-hangzhou.aliyuncs.com\"}],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"csb.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"dds\",\"document_id\":\"61715\",\"location_service_code\":\"dds\",\"regional_endpoints\":[],\"global_endpoint\":\"mongodb.aliyuncs.com\",\"regional_endpoint_pattern\":\"mongodb.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"dm\",\"document_id\":\"29434\",\"location_service_code\":\"\",\"regional_endpoints\":[{\"region\":\"ap-southeast-1\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"ap-southeast-2\",\"endpoint\":\"dm.ap-southeast-2.aliyuncs.com\"},{\"region\":\"cn-beijing\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"cn-hangzhou\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"cn-hongkong\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"cn-qingdao\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"cn-shanghai\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"cn-shenzhen\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"us-east-1\",\"endpoint\":\"dm.aliyuncs.com\"},{\"region\":\"us-west-1\",\"endpoint\":\"dm.aliyuncs.com\"}],\"global_endpoint\":\"dm.aliyuncs.com\",\"regional_endpoint_pattern\":\"dm.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"domain\",\"document_id\":\"42875\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"domain.aliyuncs.com\",\"regional_endpoint_pattern\":\"domain.aliyuncs.com\"},"
|
||||
"{\"code\":\"domain-intl\",\"document_id\":\"\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"domain-intl.aliyuncs.com\",\"regional_endpoint_pattern\":\"domain-intl.aliyuncs.com\"},"
|
||||
"{\"code\":\"drds\",\"document_id\":\"51111\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"drds.aliyuncs.com\",\"regional_endpoint_pattern\":\"drds.aliyuncs.com\"},"
|
||||
"{\"code\":\"ecs\",\"document_id\":\"25484\",\"location_service_code\":\"ecs\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"emr\",\"document_id\":\"28140\",\"location_service_code\":\"emr\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"emr.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"ess\",\"document_id\":\"25925\",\"location_service_code\":\"ess\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"ess.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"green\",\"document_id\":\"28427\",\"location_service_code\":\"green\",\"regional_endpoints\":[],\"global_endpoint\":\"green.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"hpc\",\"document_id\":\"35201\",\"location_service_code\":\"hpc\",\"regional_endpoints\":[],\"global_endpoint\":\"hpc.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"httpdns\",\"document_id\":\"52679\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"httpdns-api.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"iot\",\"document_id\":\"30557\",\"location_service_code\":\"iot\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"iot.[RegionId].aliyuncs.com\"},"
|
||||
"{\"code\":\"itaas\",\"document_id\":\"55759\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"itaas.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"jaq\",\"document_id\":\"35037\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"jaq.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"live\",\"document_id\":\"48207\",\"location_service_code\":\"live\",\"regional_endpoints\":[],\"global_endpoint\":\"live.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"mts\",\"document_id\":\"29212\",\"location_service_code\":\"mts\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"nas\",\"document_id\":\"62598\",\"location_service_code\":\"nas\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"ons\",\"document_id\":\"44416\",\"location_service_code\":\"ons\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"polardb\",\"document_id\":\"58764\",\"location_service_code\":\"polardb\",\"regional_endpoints\":[{\"region\":\"ap-south-1\",\"endpoint\":\"polardb.ap-south-1.aliyuncs.com\"},{\"region\":\"ap-southeast-5\",\"endpoint\":\"polardb.ap-southeast-5.aliyuncs.com\"}],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"polardb.aliyuncs.com\"},"
|
||||
"{\"code\":\"push\",\"document_id\":\"30074\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"cloudpush.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"qualitycheck\",\"document_id\":\"50807\",\"location_service_code\":\"\",\"regional_endpoints\":[{\"region\":\"cn-hangzhou\",\"endpoint\":\"qualitycheck.cn-hangzhou.aliyuncs.com\"}],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"r-kvstore\",\"document_id\":\"60831\",\"location_service_code\":\"redisa\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"ram\",\"document_id\":\"28672\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"ram.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"rds\",\"document_id\":\"26223\",\"location_service_code\":\"rds\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"ros\",\"document_id\":\"28899\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"ros.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"sas-api\",\"document_id\":\"28498\",\"location_service_code\":\"sas\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"slb\",\"document_id\":\"27565\",\"location_service_code\":\"slb\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"sts\",\"document_id\":\"28756\",\"location_service_code\":\"\",\"regional_endpoints\":[],\"global_endpoint\":\"sts.aliyuncs.com\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"vod\",\"document_id\":\"60574\",\"location_service_code\":\"vod\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"vpc\",\"document_id\":\"34962\",\"location_service_code\":\"vpc\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"},"
|
||||
"{\"code\":\"waf\",\"document_id\":\"62847\",\"location_service_code\":\"waf\",\"regional_endpoints\":[],\"global_endpoint\":\"\",\"regional_endpoint_pattern\":\"\"}"
|
||||
"]}";
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient, const std::string regionId, const std::string product, const std::string serviceCode, int durationSeconds) :
|
||||
locationClient_(locationClient),
|
||||
regionId_(regionId),
|
||||
product_(product),
|
||||
serviceCode_(serviceCode),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedEndpoint_(),
|
||||
expiry_()
|
||||
expiry_(),
|
||||
internalProductsInfo_()
|
||||
{
|
||||
loadInternalProductsInfo();
|
||||
}
|
||||
|
||||
EndpointProvider::~EndpointProvider()
|
||||
{
|
||||
}
|
||||
|
||||
bool EndpointProvider::loadInternalProductsInfo()
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
if (!reader.parse(jsondata, value))
|
||||
return false;
|
||||
|
||||
auto productsNode = value["products"];
|
||||
for (auto value : productsNode)
|
||||
{
|
||||
Product p;
|
||||
p.code = value["code"].asString();
|
||||
p.documentId = value["document_id"].asString();
|
||||
p.locationServiceCode = value["location_service_code"].asString();
|
||||
p.globalEndpoint = value["global_endpoint"].asString();
|
||||
p.regionalEndpointPattern = value["regional_endpoint_pattern"].asString();
|
||||
|
||||
auto regionalEndpointsNode = value["regional_endpoints"];
|
||||
for (auto value : regionalEndpointsNode)
|
||||
{
|
||||
p.regionalEndpoints.insert(std::make_pair(value["region"].asString(),
|
||||
value["endpoint"].asString()));
|
||||
}
|
||||
internalProductsInfo_.push_back(p);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EndpointProvider::checkExpiry()const
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
@@ -44,14 +136,45 @@ bool EndpointProvider::checkExpiry()const
|
||||
return (diff > 0 - 60);
|
||||
}
|
||||
|
||||
std::string EndpointProvider::getEndpoint()
|
||||
std::string EndpointProvider::internalEndpoint(const std::string regionId, const std::string product)
|
||||
{
|
||||
loadEndpoint();
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
return cachedEndpoint_;
|
||||
for (Product p : internalProductsInfo_)
|
||||
{
|
||||
if (strcasecmp(p.code.c_str(), product.c_str()) != 0)
|
||||
continue;
|
||||
|
||||
for (auto e : p.regionalEndpoints)
|
||||
{
|
||||
if (strcasecmp(e.first.c_str(), regionId.c_str()) != 0)
|
||||
continue;
|
||||
|
||||
return e.second;
|
||||
}
|
||||
return p.globalEndpoint;
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void EndpointProvider::loadEndpoint()
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::getEndpoint()
|
||||
{
|
||||
if (!serviceCode_.empty())
|
||||
{
|
||||
EndpointOutcome outcome = loadRemoteEndpoint();
|
||||
if (outcome.isSuccess())
|
||||
return outcome;
|
||||
if (outcome.error().errorCode() != "InvalidRegionId"
|
||||
&& outcome.error().errorCode() != "Illegal Parameter")
|
||||
return outcome;
|
||||
}
|
||||
|
||||
std::string endpoint = internalEndpoint(regionId_, product_);
|
||||
if (!endpoint.empty())
|
||||
return EndpointOutcome(endpoint);
|
||||
|
||||
return EndpointOutcome(Error("InvalidRegionId", "The specified region does not exist."));
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::loadRemoteEndpoint()
|
||||
{
|
||||
if (checkExpiry())
|
||||
{
|
||||
@@ -63,15 +186,17 @@ void EndpointProvider::loadEndpoint()
|
||||
request.setServiceCode(serviceCode_);
|
||||
request.setType("openAPI");
|
||||
auto outcome = locationClient_->describeEndpoints(request);
|
||||
if (outcome.isSuccess())
|
||||
{
|
||||
auto all = outcome.result().endpoints();
|
||||
if (all.size() > 0)
|
||||
cachedEndpoint_ = all.front().endpoint;
|
||||
if (!outcome.isSuccess())
|
||||
return EndpointOutcome(outcome.error());
|
||||
|
||||
std::time_t t = std::time(nullptr) + durationSeconds_;
|
||||
expiry_ = std::chrono::system_clock::from_time_t(t);
|
||||
}
|
||||
auto all = outcome.result().endpoints();
|
||||
if (all.size() > 0)
|
||||
cachedEndpoint_ = all.front().endpoint;
|
||||
|
||||
std::time_t t = std::time(nullptr) + durationSeconds_;
|
||||
expiry_ = std::chrono::system_clock::from_time_t(t);
|
||||
}
|
||||
}
|
||||
|
||||
return EndpointOutcome(cachedEndpoint_);
|
||||
}
|
||||
@@ -24,10 +24,10 @@
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
RoaServiceClient::RoaServiceClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
RoaServiceClient::RoaServiceClient(const std::string & servicename, const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::shared_ptr<Signer> &signer) :
|
||||
CoreClient(configuration),
|
||||
CoreClient(servicename, configuration),
|
||||
credentialsProvider_(credentialsProvider),
|
||||
signer_(signer)
|
||||
{
|
||||
|
||||
@@ -20,14 +20,13 @@
|
||||
#include <sstream>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
#include "Utils.h"
|
||||
//#include <alibabacloud/core/RpcErrorMarshaller.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
RpcServiceClient::RpcServiceClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
RpcServiceClient::RpcServiceClient(const std::string & servicename, const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::shared_ptr<Signer> &signer) :
|
||||
CoreClient(configuration),
|
||||
CoreClient(servicename, configuration),
|
||||
credentialsProvider_(credentialsProvider),
|
||||
signer_(signer)
|
||||
{
|
||||
|
||||
@@ -20,36 +20,33 @@
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Location;
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string SERVICE_NAME = "Location";
|
||||
const std::string ENDPOINT = "location.aliyuncs.com";
|
||||
}
|
||||
|
||||
LocationClient::LocationClient(const Credentials &credentials, const ClientConfiguration &configuration) :
|
||||
RpcServiceClient(std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
|
||||
{
|
||||
}
|
||||
|
||||
LocationClient::LocationClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(credentialsProvider, configuration)
|
||||
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
|
||||
{
|
||||
}
|
||||
|
||||
LocationClient::LocationClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
|
||||
{
|
||||
}
|
||||
|
||||
LocationClient::~LocationClient()
|
||||
{}
|
||||
|
||||
CoreClient::EndpointOutcome LocationClient::endpoint()const
|
||||
{
|
||||
return CoreClient::EndpointOutcome("location.aliyuncs.com");
|
||||
}
|
||||
|
||||
LocationClient::DescribeEndpointsOutcome LocationClient::describeEndpoints(const Model::DescribeEndpointsRequest &request) const
|
||||
{
|
||||
auto endpointOutcome = endpoint();
|
||||
if (!endpointOutcome.isSuccess())
|
||||
return DescribeEndpointsOutcome(endpointOutcome.error());
|
||||
|
||||
auto outcome = makeRequest(endpointOutcome.result(), request);
|
||||
auto outcome = makeRequest(ENDPOINT, request);
|
||||
|
||||
if (outcome.isSuccess())
|
||||
return DescribeEndpointsOutcome(Model::DescribeEndpointsResult(outcome.result()));
|
||||
|
||||
@@ -16,23 +16,30 @@
|
||||
|
||||
#include <alibabacloud/core/sts/StsClient.h>
|
||||
#include <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
#include <alibabacloud/core/EndpointProvider.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Sts;
|
||||
using namespace AlibabaCloud::Sts::Model;
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string SERVICE_NAME = "Sts";
|
||||
const std::string ENDPOINT = "sts.aliyuncs.com";
|
||||
}
|
||||
|
||||
StsClient::StsClient(const Credentials &credentials, const ClientConfiguration &configuration) :
|
||||
RpcServiceClient(std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
|
||||
{
|
||||
}
|
||||
|
||||
StsClient::StsClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(credentialsProvider, configuration)
|
||||
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
|
||||
{
|
||||
}
|
||||
|
||||
StsClient::StsClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,18 +47,9 @@ StsClient::~StsClient()
|
||||
{
|
||||
}
|
||||
|
||||
CoreClient::EndpointOutcome StsClient::endpoint()const
|
||||
{
|
||||
return CoreClient::EndpointOutcome("sts.aliyuncs.com");
|
||||
}
|
||||
|
||||
StsClient::AssumeRoleOutcome StsClient::assumeRole(const Model::AssumeRoleRequest &request)const
|
||||
{
|
||||
auto endpointOutcome = endpoint();
|
||||
if (!endpointOutcome.isSuccess())
|
||||
return AssumeRoleOutcome(endpointOutcome.error());
|
||||
|
||||
auto outcome = makeRequest(endpointOutcome.result(), request);
|
||||
auto outcome = makeRequest(ENDPOINT, request);
|
||||
|
||||
if (outcome.isSuccess())
|
||||
return AssumeRoleOutcome(AssumeRoleResult(outcome.result()));
|
||||
@@ -83,11 +81,7 @@ StsClient::AssumeRoleOutcomeCallable StsClient::assumeRoleCallable(const Model::
|
||||
|
||||
StsClient::GetCallerIdentityOutcome StsClient::getCallerIdentity(const GetCallerIdentityRequest &request) const
|
||||
{
|
||||
auto endpointOutcome = endpoint();
|
||||
if (!endpointOutcome.isSuccess())
|
||||
return GetCallerIdentityOutcome(endpointOutcome.error());
|
||||
|
||||
auto outcome = makeRequest(endpointOutcome.result(), request);
|
||||
auto outcome = makeRequest(ENDPOINT, request);
|
||||
|
||||
if (outcome.isSuccess())
|
||||
return GetCallerIdentityOutcome(GetCallerIdentityResult(outcome.result()));
|
||||
|
||||
Reference in New Issue
Block a user