Merge pull request #57 from aliyun/supported_json_param
upgrade sdk core
This commit is contained in:
@@ -59,6 +59,7 @@ set(core_public_header
|
||||
include/alibabacloud/core/SimpleCredentialsProvider.h
|
||||
include/alibabacloud/core/StsAssumeRoleCredentialsProvider.h
|
||||
include/alibabacloud/core/Url.h
|
||||
include/alibabacloud/core/Utils.h
|
||||
)
|
||||
|
||||
set(core_public_header_location
|
||||
@@ -120,7 +121,6 @@ set(core_src
|
||||
src/SimpleCredentialsProvider.cc
|
||||
src/StsAssumeRoleCredentialsProvider.cc
|
||||
src/Url.cc
|
||||
src/Utils.h
|
||||
src/Utils.cc
|
||||
src/location/LocationClient.cc
|
||||
src/location/LocationRequest.cc
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
|
||||
#include <map>
|
||||
#include "CoreExport.h"
|
||||
#include "Url.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
@@ -63,8 +63,8 @@ class ALIBABACLOUD_CORE_EXPORT ServiceRequest {
|
||||
void setCoreParameter(const ParameterNameType &name,
|
||||
const ParameterValueType &value);
|
||||
|
||||
|
||||
void setParameters(const ParameterCollection ¶ms);
|
||||
void setJsonParameters(const ParameterNameType &name, const ParameterCollection ¶ms);
|
||||
void setResourcePath(const std::string &path);
|
||||
void setProduct(const std::string &product);
|
||||
void setVersion(const std::string &version);
|
||||
|
||||
@@ -17,22 +17,27 @@
|
||||
#ifndef CORE_SRC_UTILS_H_
|
||||
#define CORE_SRC_UTILS_H_
|
||||
|
||||
#include <alibabacloud/core/HttpRequest.h>
|
||||
#include <alibabacloud/core/HttpMessage.h>
|
||||
#include <string>
|
||||
#include <alibabacloud/core/HttpRequest.h>
|
||||
#include <json/json.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
std::string ComputeContentMD5(const char *data, size_t size);
|
||||
std::string GenerateUuid();
|
||||
std::string HttpMethodToString(HttpRequest::Method method);
|
||||
void StringReplace(std::string &src,
|
||||
const std::string &s1, const std::string &s2);
|
||||
void StringReplace(std::string &src, const std::string &s1,
|
||||
const std::string &s2);
|
||||
std::string UrlEncode(const std::string &src);
|
||||
std::string UrlDecode(const std::string &src);
|
||||
std::string canonicalizedQuery(const std::map <std::string,
|
||||
std::string> ¶ms);
|
||||
std::string
|
||||
canonicalizedQuery(const std::map<std::string, std::string> ¶ms);
|
||||
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers);
|
||||
std::string GetEnv(const std::string env);
|
||||
Json::Value ReadJson(const std::string str);
|
||||
std::string MapToJson(const std::map<std::string, std::string> &maps);
|
||||
std::map<std::string, std::string> JsonToMap(const std::string &json);
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_SRC_UTILS_H_
|
||||
@@ -15,26 +15,30 @@
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include "Utils.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
|
||||
AsyncCallerContext::AsyncCallerContext() :
|
||||
uuid_(GenerateUuid()) {
|
||||
AsyncCallerContext::AsyncCallerContext() : uuid_(GenerateUuid())
|
||||
{
|
||||
}
|
||||
|
||||
AsyncCallerContext::AsyncCallerContext(const std::string &uuid) :
|
||||
uuid_(uuid) {
|
||||
AsyncCallerContext::AsyncCallerContext(const std::string &uuid) : uuid_(uuid)
|
||||
{
|
||||
}
|
||||
|
||||
AsyncCallerContext::~AsyncCallerContext() {
|
||||
AsyncCallerContext::~AsyncCallerContext()
|
||||
{
|
||||
}
|
||||
|
||||
std::string AsyncCallerContext::uuid()const {
|
||||
std::string AsyncCallerContext::uuid() const
|
||||
{
|
||||
return uuid_;
|
||||
}
|
||||
|
||||
void AsyncCallerContext::setUuid(const std::string &uuid) {
|
||||
void AsyncCallerContext::setUuid(const std::string &uuid)
|
||||
{
|
||||
uuid_ = uuid;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,44 +23,48 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include "Utils.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
const std::string SERVICE_NAME = "Common";
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const Credentials &credentials,
|
||||
const ClientConfiguration &configuration) :
|
||||
CoreClient(SERVICE_NAME, configuration),
|
||||
const ClientConfiguration &configuration) : CoreClient(SERVICE_NAME, configuration),
|
||||
credentialsProvider_(
|
||||
std::make_shared<SimpleCredentialsProvider>(credentials)),
|
||||
signer_(std::make_shared<HmacSha1Signer>()) {
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(
|
||||
const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
const ClientConfiguration & configuration) :
|
||||
CoreClient(SERVICE_NAME, configuration),
|
||||
const ClientConfiguration &configuration) : CoreClient(SERVICE_NAME, configuration),
|
||||
credentialsProvider_(credentialsProvider),
|
||||
signer_(std::make_shared<HmacSha1Signer>()) {
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const std::string &accessKeyId,
|
||||
const std::string &accessKeySecret,
|
||||
const ClientConfiguration & configuration) :
|
||||
CoreClient(SERVICE_NAME, configuration),
|
||||
const ClientConfiguration &configuration) : CoreClient(SERVICE_NAME, configuration),
|
||||
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(accessKeyId,
|
||||
accessKeySecret)),
|
||||
signer_(std::make_shared<HmacSha1Signer>()) {
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
}
|
||||
|
||||
CommonClient::~CommonClient() {
|
||||
CommonClient::~CommonClient()
|
||||
{
|
||||
}
|
||||
|
||||
CommonClient::JsonOutcome CommonClient::makeRequest(const std::string &endpoint,
|
||||
const CommonRequest &msg, HttpRequest::Method method)const {
|
||||
const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
auto outcome = AttemptRequest(endpoint, msg, method);
|
||||
if (outcome.isSuccess())
|
||||
return JsonOutcome(std::string(outcome.result().body(),
|
||||
@@ -70,7 +74,8 @@ CommonClient::JsonOutcome CommonClient::makeRequest(const std::string &endpoint,
|
||||
}
|
||||
|
||||
CommonClient::CommonResponseOutcome CommonClient::commonResponse(
|
||||
const CommonRequest & request) const {
|
||||
const CommonRequest &request) const
|
||||
{
|
||||
auto outcome = makeRequest(request.domain(), request, request.httpMethod());
|
||||
if (outcome.isSuccess())
|
||||
return CommonResponseOutcome(CommonResponse(outcome.result()));
|
||||
@@ -80,7 +85,8 @@ CommonClient::CommonResponseOutcome CommonClient::commonResponse(
|
||||
|
||||
void CommonClient::commonResponseAsync(const CommonRequest &request,
|
||||
const CommonResponseAsyncHandler &handler,
|
||||
const std::shared_ptr<const AsyncCallerContext>& context) const {
|
||||
const std::shared_ptr<const AsyncCallerContext> &context) const
|
||||
{
|
||||
auto fn = [this, request, handler, context]() {
|
||||
handler(this, request, commonResponse(request), context);
|
||||
};
|
||||
@@ -89,7 +95,8 @@ void CommonClient::commonResponseAsync(const CommonRequest & request,
|
||||
}
|
||||
|
||||
CommonClient::CommonResponseOutcomeCallable
|
||||
CommonClient::commonResponseCallable(const CommonRequest & request) const {
|
||||
CommonClient::commonResponseCallable(const CommonRequest &request) const
|
||||
{
|
||||
auto task = std::make_shared<std::packaged_task<CommonResponseOutcome()>>(
|
||||
[this, request]() {
|
||||
return this->commonResponse(request);
|
||||
@@ -100,13 +107,15 @@ CommonClient::commonResponseCallable(const CommonRequest & request) const {
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildHttpRequest(const std::string &endpoint,
|
||||
const ServiceRequest & msg, HttpRequest::Method method) const {
|
||||
const ServiceRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
return buildHttpRequest(endpoint,
|
||||
dynamic_cast<const CommonRequest &>(msg), method);
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildHttpRequest(const std::string &endpoint,
|
||||
const CommonRequest &msg, HttpRequest::Method method) const {
|
||||
const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
if (msg.requestPattern() == CommonRequest::RpcPattern)
|
||||
return buildRpcHttpRequest(endpoint, msg, method);
|
||||
else
|
||||
@@ -114,13 +123,17 @@ HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint,
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildRoaHttpRequest(const std::string &endpoint,
|
||||
const CommonRequest &msg, HttpRequest::Method method) const {
|
||||
const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
Url url;
|
||||
if (msg.scheme().empty()) {
|
||||
if (msg.scheme().empty())
|
||||
{
|
||||
url.setScheme("https");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
url.setScheme(msg.scheme());
|
||||
}
|
||||
url.setHost(endpoint);
|
||||
@@ -128,14 +141,17 @@ HttpRequest CommonClient::buildRoaHttpRequest(const std::string & endpoint,
|
||||
|
||||
auto params = msg.headerParameters();
|
||||
std::map<std::string, std::string> queryParams;
|
||||
for (const auto &p : params) {
|
||||
for (const auto &p : params)
|
||||
{
|
||||
if (!p.second.empty())
|
||||
queryParams[p.first] = p.second;
|
||||
}
|
||||
|
||||
if (!queryParams.empty()) {
|
||||
if (!queryParams.empty())
|
||||
{
|
||||
std::stringstream queryString;
|
||||
for (const auto &p : queryParams) {
|
||||
for (const auto &p : queryParams)
|
||||
{
|
||||
if (p.second.empty())
|
||||
queryString << "&" << p.first;
|
||||
else
|
||||
@@ -147,30 +163,42 @@ HttpRequest CommonClient::buildRoaHttpRequest(const std::string & endpoint,
|
||||
HttpRequest request(url);
|
||||
request.setMethod(method);
|
||||
|
||||
if (msg.connectTimeout() != kInvalidTimeout) {
|
||||
if (msg.connectTimeout() != kInvalidTimeout)
|
||||
{
|
||||
request.setConnectTimeout(msg.connectTimeout());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
request.setConnectTimeout(configuration().connectTimeout());
|
||||
}
|
||||
|
||||
if (msg.readTimeout() != kInvalidTimeout) {
|
||||
if (msg.readTimeout() != kInvalidTimeout)
|
||||
{
|
||||
request.setReadTimeout(msg.readTimeout());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
request.setReadTimeout(configuration().readTimeout());
|
||||
}
|
||||
|
||||
if (msg.headerParameter("Accept").empty()) {
|
||||
if (msg.headerParameter("Accept").empty())
|
||||
{
|
||||
request.setHeader("Accept", "application/json");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
request.setHeader("Accept", msg.headerParameter("Accept"));
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << msg.contentSize();
|
||||
request.setHeader("Content-Length", ss.str());
|
||||
if (msg.headerParameter("Content-Type").empty()) {
|
||||
if (msg.headerParameter("Content-Type").empty())
|
||||
{
|
||||
request.setHeader("Content-Type", "application/octet-stream");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
request.setHeader("Content-Type", msg.headerParameter("Content-Type"));
|
||||
}
|
||||
request.setHeader("Content-MD5",
|
||||
@@ -220,13 +248,17 @@ HttpRequest CommonClient::buildRoaHttpRequest(const std::string & endpoint,
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildRpcHttpRequest(const std::string &endpoint,
|
||||
const CommonRequest &msg, HttpRequest::Method method) const {
|
||||
const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
Url url;
|
||||
if (msg.scheme().empty()) {
|
||||
if (msg.scheme().empty())
|
||||
{
|
||||
url.setScheme("https");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
url.setScheme(msg.scheme());
|
||||
}
|
||||
url.setHost(endpoint);
|
||||
@@ -234,7 +266,8 @@ HttpRequest CommonClient::buildRpcHttpRequest(const std::string & endpoint,
|
||||
|
||||
auto params = msg.queryParameters();
|
||||
std::map<std::string, std::string> queryParams;
|
||||
for (const auto &p : params) {
|
||||
for (const auto &p : params)
|
||||
{
|
||||
if (!p.second.empty())
|
||||
queryParams[p.first] = p.second;
|
||||
}
|
||||
@@ -274,15 +307,21 @@ HttpRequest CommonClient::buildRpcHttpRequest(const std::string & endpoint,
|
||||
url.setQuery(queryString.str().substr(1));
|
||||
|
||||
HttpRequest request(url);
|
||||
if (msg.connectTimeout() != kInvalidTimeout) {
|
||||
if (msg.connectTimeout() != kInvalidTimeout)
|
||||
{
|
||||
request.setConnectTimeout(msg.connectTimeout());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
request.setConnectTimeout(configuration().connectTimeout());
|
||||
}
|
||||
|
||||
if (msg.readTimeout() != kInvalidTimeout) {
|
||||
if (msg.readTimeout() != kInvalidTimeout)
|
||||
{
|
||||
request.setReadTimeout(msg.readTimeout());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
request.setReadTimeout(configuration().readTimeout());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/CoreClient.h>
|
||||
#include <json/json.h>
|
||||
#include <alibabacloud/core/Signer.h>
|
||||
#include "CurlHttpClient.h"
|
||||
#include "Executor.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
#include <alibabacloud/core/CoreClient.h>
|
||||
#include <alibabacloud/core/Signer.h>
|
||||
#include <json/json.h>
|
||||
|
||||
/*!
|
||||
* \class AlibabaCloud::CoreClient CoreClient.h <alibabacloud/core/CoreClient.h>
|
||||
@@ -28,32 +29,26 @@
|
||||
namespace AlibabaCloud {
|
||||
|
||||
CoreClient::CoreClient(const std::string &servicename,
|
||||
const ClientConfiguration &configuration) :
|
||||
serviceName_(servicename),
|
||||
configuration_(configuration),
|
||||
const ClientConfiguration &configuration)
|
||||
: serviceName_(servicename), configuration_(configuration),
|
||||
httpClient_(new CurlHttpClient) {
|
||||
httpClient_->setProxy(configuration.proxy());
|
||||
}
|
||||
|
||||
CoreClient::~CoreClient() {
|
||||
delete httpClient_;
|
||||
}
|
||||
CoreClient::~CoreClient() { delete httpClient_; }
|
||||
|
||||
ClientConfiguration CoreClient::configuration()const {
|
||||
return configuration_;
|
||||
}
|
||||
ClientConfiguration CoreClient::configuration() const { return configuration_; }
|
||||
|
||||
std::string CoreClient::serviceName()const {
|
||||
return serviceName_;
|
||||
}
|
||||
std::string CoreClient::serviceName() const { return serviceName_; }
|
||||
|
||||
void CoreClient::asyncExecute(Runnable *r) const {
|
||||
Executor::instance()->execute(r);
|
||||
}
|
||||
|
||||
HttpClient::HttpResponseOutcome CoreClient::AttemptRequest(
|
||||
const std::string & endpoint,
|
||||
const ServiceRequest & request, HttpRequest::Method method) const {
|
||||
HttpClient::HttpResponseOutcome
|
||||
CoreClient::AttemptRequest(const std::string &endpoint,
|
||||
const ServiceRequest &request,
|
||||
HttpRequest::Method method) const {
|
||||
auto r = buildHttpRequest(endpoint, request, method);
|
||||
auto outcome = httpClient_->makeRequest(r);
|
||||
if (!outcome.isSuccess())
|
||||
@@ -67,10 +62,14 @@ HttpClient::HttpResponseOutcome CoreClient::AttemptRequest(
|
||||
Error CoreClient::buildCoreError(const HttpResponse &response) const {
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
if (!reader.parse(std::string(response.body(), response.bodySize()), value)) {
|
||||
if (response.bodySize() > 0) {
|
||||
if (!reader.parse(std::string(response.body(), response.bodySize()), value))
|
||||
{
|
||||
if (response.bodySize() > 0)
|
||||
{
|
||||
return Error("InvalidResponse", response.body());
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return Error("InvalidResponse", "body is empty");
|
||||
}
|
||||
}
|
||||
@@ -80,7 +79,8 @@ Error CoreClient::buildCoreError(const HttpResponse &response)const {
|
||||
error.setErrorMessage(value["Message"].asString());
|
||||
error.setHost(value["HostId"].asString());
|
||||
error.setRequestId(value["RequestId"].asString());
|
||||
if (value["Code"].asString().empty() || value["Message"].asString().empty()) {
|
||||
if (value["Code"].asString().empty() || value["Message"].asString().empty())
|
||||
{
|
||||
error.setDetail(std::string(response.body()));
|
||||
}
|
||||
return error;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "CurlHttpClient.h"
|
||||
#include "Utils.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -14,20 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/EndpointProvider.h>
|
||||
#include <json/json.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <alibabacloud/core/EndpointProvider.h>
|
||||
#include <iomanip>
|
||||
#include <json/json.h>
|
||||
#include <sstream>
|
||||
|
||||
#ifndef WIN32
|
||||
#include "LocalEndpoints.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
#else
|
||||
#include "LocalEndpointsForWindows.h"
|
||||
#endif
|
||||
|
||||
namespace AlibabaCloud {
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
@@ -42,7 +46,8 @@ typedef std::string endpointType;
|
||||
typedef std::string mappingType;
|
||||
typedef std::vector<regionType> regionsType;
|
||||
typedef std::map<productType, endpointType> regionalType;
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
regionsType regions;
|
||||
regionalType regional;
|
||||
} productInfoType;
|
||||
@@ -51,172 +56,192 @@ static std::vector<regionType> allRegions;
|
||||
static std::vector<productType> allProductsInLocalEndpoints;
|
||||
static std::map<productType, productInfoType> allLocalEndpoints;
|
||||
|
||||
static void LoadLocalEndpoints() {
|
||||
static void LoadLocalEndpoints()
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
|
||||
if (local_endpoints_loaded) {
|
||||
if (local_endpoints_loaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
std::string LOCAL_ENDPOINTS_CONFIG = WIN_LOCAL_ENDPOINTS_CONFIG_1 +
|
||||
WIN_LOCAL_ENDPOINTS_CONFIG_2 + WIN_LOCAL_ENDPOINTS_CONFIG_3;
|
||||
WIN_LOCAL_ENDPOINTS_CONFIG_2 +
|
||||
WIN_LOCAL_ENDPOINTS_CONFIG_3;
|
||||
#endif
|
||||
|
||||
if (!reader.parse(LOCAL_ENDPOINTS_CONFIG, value)){
|
||||
try
|
||||
{
|
||||
if (!reader.parse(LOCAL_ENDPOINTS_CONFIG, value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto regions = value["regions"];
|
||||
for (const auto ®ion : regions) {
|
||||
for (const auto ®ion : regions)
|
||||
{
|
||||
allRegions.push_back(region.asString());
|
||||
}
|
||||
|
||||
auto products = value["products"];
|
||||
for (const auto &product : products) {
|
||||
for (const auto &product : products)
|
||||
{
|
||||
allProductsInLocalEndpoints.push_back(product.asString());
|
||||
}
|
||||
|
||||
auto endpoints = value["endpoints"];
|
||||
for (auto &product : allProductsInLocalEndpoints ) {
|
||||
for (auto &product : allProductsInLocalEndpoints)
|
||||
{
|
||||
auto endpoint_per_product = endpoints[product];
|
||||
productInfoType p;
|
||||
|
||||
auto regions = endpoint_per_product["regions"];
|
||||
auto regional = endpoint_per_product["regional"];
|
||||
|
||||
for (auto & r : regions) {
|
||||
for (auto &r : regions)
|
||||
{
|
||||
const std::string region = r.asString();
|
||||
p.regions.push_back(region);
|
||||
p.regional[region] = endpoint_per_product["regional"][region].asString();
|
||||
p.regional[region] =
|
||||
endpoint_per_product["regional"][region].asString();
|
||||
}
|
||||
allLocalEndpoints[product] = p;
|
||||
}
|
||||
local_endpoints_loaded = true;
|
||||
}
|
||||
catch (JSONCPP_STRING errs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
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_() {
|
||||
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_()
|
||||
{
|
||||
transform(product_.begin(), product_.end(), product_.begin(), ::tolower);
|
||||
loadLocalProductsInfo();
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointProvider(
|
||||
const Credentials& credentials,
|
||||
EndpointProvider::EndpointProvider(const Credentials &credentials,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::string ®ionId,
|
||||
const std::string &product,
|
||||
const std::string &serviceCode,
|
||||
int durationSeconds) :
|
||||
LocationClient(credentials, configuration),
|
||||
regionId_(regionId),
|
||||
product_(product),
|
||||
serviceCode_(serviceCode),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedEndpoint_(),
|
||||
expiry_() {
|
||||
int durationSeconds)
|
||||
: LocationClient(credentials, configuration), regionId_(regionId),
|
||||
product_(product), serviceCode_(serviceCode),
|
||||
durationSeconds_(durationSeconds), cachedMutex_(), cachedEndpoint_(),
|
||||
expiry_()
|
||||
{
|
||||
transform(product_.begin(), product_.end(), product_.begin(), ::tolower);
|
||||
loadLocalProductsInfo();
|
||||
}
|
||||
|
||||
EndpointProvider::~EndpointProvider() {
|
||||
}
|
||||
EndpointProvider::~EndpointProvider() {}
|
||||
|
||||
|
||||
bool EndpointProvider::loadLocalProductsInfo() {
|
||||
bool EndpointProvider::loadLocalProductsInfo()
|
||||
{
|
||||
LoadLocalEndpoints();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string EndpointProvider::localEndpoint(
|
||||
const std::string regionId, const std::string product) {
|
||||
std::string EndpointProvider::localEndpoint(const std::string regionId,
|
||||
const std::string product)
|
||||
{
|
||||
|
||||
if (!local_endpoints_loaded) {
|
||||
if (!local_endpoints_loaded)
|
||||
{
|
||||
// impossible
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<regionType>::iterator allRegionsit;
|
||||
allRegionsit = std::find(allRegions.begin(), allRegions.end(), regionId);
|
||||
if (allRegionsit == allRegions.end()) {
|
||||
if (allRegionsit == allRegions.end())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<productType>::iterator allProductsInLocalEndpointsit;
|
||||
allProductsInLocalEndpointsit = std::find(allProductsInLocalEndpoints.begin(), allProductsInLocalEndpoints.end(), product);
|
||||
if (allProductsInLocalEndpointsit == allProductsInLocalEndpoints.end()) {
|
||||
allProductsInLocalEndpointsit =
|
||||
std::find(allProductsInLocalEndpoints.begin(),
|
||||
allProductsInLocalEndpoints.end(), product);
|
||||
if (allProductsInLocalEndpointsit == allProductsInLocalEndpoints.end())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<regionType> vec = allLocalEndpoints[product].regions;
|
||||
std::vector<regionType>::iterator it;
|
||||
it = std::find(vec.begin(), vec.end(), regionId);
|
||||
if (it == vec.end()) {
|
||||
if (it == vec.end())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
return allLocalEndpoints[product].regional[regionId];
|
||||
}
|
||||
|
||||
|
||||
bool EndpointProvider::checkExpiry()const {
|
||||
bool EndpointProvider::checkExpiry() const
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto diff =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
|
||||
return (diff > 0 - 60);
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::getEndpoint() {
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::getEndpoint()
|
||||
{
|
||||
// 1st priority: user specified via configuration
|
||||
if (!configuration().endpoint().empty()) {
|
||||
if (!configuration().endpoint().empty())
|
||||
{
|
||||
return EndpointOutcome(configuration().endpoint());
|
||||
}
|
||||
|
||||
// 2nd priority: local configuration
|
||||
std::string endpoint = localEndpoint(regionId_, product_);
|
||||
if (!endpoint.empty()) {
|
||||
if (!endpoint.empty())
|
||||
{
|
||||
return EndpointOutcome(endpoint);
|
||||
}
|
||||
|
||||
// service code is mandatory for location service.
|
||||
if (serviceCode_.empty()) {
|
||||
if (serviceCode_.empty())
|
||||
{
|
||||
return EndpointOutcome(
|
||||
Error("InvalidRegionId",
|
||||
"Product[" + product_ + "] at region[" +
|
||||
Error("InvalidRegionId", "Product[" + product_ + "] at region[" +
|
||||
regionId_ + "] does not exist."));
|
||||
}
|
||||
|
||||
// 3rd priority: request from location service
|
||||
EndpointOutcome outcome = loadRemoteEndpoint();
|
||||
if (outcome.isSuccess()) {
|
||||
if (outcome.isSuccess())
|
||||
{
|
||||
return outcome;
|
||||
}
|
||||
|
||||
if (outcome.error().errorCode() == "Illegal Parameter") {
|
||||
return EndpointOutcome(Error("InvalidProduct",
|
||||
"Prodcut[" + serviceCode_ + "] does not exist."));
|
||||
if (outcome.error().errorCode() == "Illegal Parameter")
|
||||
{
|
||||
return EndpointOutcome(Error("InvalidProduct", "Prodcut[" + serviceCode_ +
|
||||
"] does not exist."));
|
||||
}
|
||||
return outcome;
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::loadRemoteEndpoint() {
|
||||
if (checkExpiry()) {
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::loadRemoteEndpoint()
|
||||
{
|
||||
if (checkExpiry())
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
if (checkExpiry()) {
|
||||
if (checkExpiry())
|
||||
{
|
||||
Location::Model::DescribeEndpointsRequest request;
|
||||
request.setId(regionId_);
|
||||
request.setServiceCode(serviceCode_);
|
||||
|
||||
@@ -14,38 +14,38 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/InstanceProfileCredentialsProvider.h>
|
||||
#include <json/json.h>
|
||||
#include "EcsMetadataFetcher.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
#include <alibabacloud/core/InstanceProfileCredentialsProvider.h>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <json/json.h>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace AlibabaCloud {
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
|
||||
InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(
|
||||
const std::string & roleName, int durationSeconds):
|
||||
CredentialsProvider(),
|
||||
EcsMetadataFetcher(),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedCredentials_("", ""),
|
||||
expiry_() {
|
||||
const std::string &roleName, int durationSeconds)
|
||||
: CredentialsProvider(), EcsMetadataFetcher(),
|
||||
durationSeconds_(durationSeconds), cachedMutex_(),
|
||||
cachedCredentials_("", ""), expiry_()
|
||||
{
|
||||
setRoleName(roleName);
|
||||
}
|
||||
|
||||
InstanceProfileCredentialsProvider::~InstanceProfileCredentialsProvider() {
|
||||
}
|
||||
InstanceProfileCredentialsProvider::~InstanceProfileCredentialsProvider() {}
|
||||
|
||||
Credentials InstanceProfileCredentialsProvider::getCredentials() {
|
||||
Credentials InstanceProfileCredentialsProvider::getCredentials()
|
||||
{
|
||||
loadCredentials();
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
return cachedCredentials_;
|
||||
}
|
||||
|
||||
bool InstanceProfileCredentialsProvider::checkExpiry()const {
|
||||
bool InstanceProfileCredentialsProvider::checkExpiry() const
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto diff =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
|
||||
@@ -53,19 +53,20 @@ bool InstanceProfileCredentialsProvider::checkExpiry()const {
|
||||
return (diff > 0 - 60);
|
||||
}
|
||||
|
||||
void InstanceProfileCredentialsProvider::loadCredentials() {
|
||||
if (checkExpiry()) {
|
||||
void InstanceProfileCredentialsProvider::loadCredentials()
|
||||
{
|
||||
if (checkExpiry())
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
if (checkExpiry()) {
|
||||
if (checkExpiry())
|
||||
{
|
||||
auto outcome = getMetadata();
|
||||
Json::Value value;
|
||||
Json::Reader reader;
|
||||
if (reader.parse(outcome, value)) {
|
||||
if (value["Code"].empty()
|
||||
&&value["AccessKeyId"].empty()
|
||||
&&value["AccessKeySecret"].empty()
|
||||
&&value["SecurityToken"].empty()
|
||||
&&value["Expiration"].empty()) {
|
||||
if (reader.parse(outcome, value))
|
||||
{
|
||||
if (value["Code"].empty() && value["AccessKeyId"].empty() && value["AccessKeySecret"].empty() && value["SecurityToken"].empty() && value["Expiration"].empty())
|
||||
{
|
||||
cachedCredentials_ = Credentials("", "");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "Utils.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
|
||||
|
||||
@@ -18,16 +18,18 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "Utils.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
|
||||
RoaServiceRequest::RoaServiceRequest(const std::string &product,
|
||||
const std::string & version) :
|
||||
ServiceRequest(product, version) {
|
||||
const std::string &version) : ServiceRequest(product, version)
|
||||
{
|
||||
}
|
||||
|
||||
RoaServiceRequest::~RoaServiceRequest() {
|
||||
RoaServiceRequest::~RoaServiceRequest()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "Utils.h"
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
#include <alibabacloud/core/ServiceRequest.h>
|
||||
#include <alibabacloud/core/AlibabaCloud.h>
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
|
||||
namespace AlibabaCloud {
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
|
||||
ServiceRequest::ServiceRequest(const std::string &product,
|
||||
const std::string &version) :
|
||||
content_(nullptr),
|
||||
const std::string &version) : content_(nullptr),
|
||||
contentSize_(0),
|
||||
params_(),
|
||||
product_(product),
|
||||
@@ -29,11 +30,11 @@ ServiceRequest::ServiceRequest(const std::string &product,
|
||||
version_(version),
|
||||
scheme_("https"),
|
||||
connectTimeout_(kInvalidTimeout),
|
||||
readTimeout_(kInvalidTimeout) {
|
||||
readTimeout_(kInvalidTimeout)
|
||||
{
|
||||
}
|
||||
|
||||
ServiceRequest::ServiceRequest(const ServiceRequest &other) :
|
||||
content_(nullptr),
|
||||
ServiceRequest::ServiceRequest(const ServiceRequest &other) : content_(nullptr),
|
||||
contentSize_(other.contentSize_),
|
||||
params_(other.params_),
|
||||
product_(other.product_),
|
||||
@@ -41,16 +42,20 @@ ServiceRequest::ServiceRequest(const ServiceRequest &other) :
|
||||
version_(other.version_),
|
||||
scheme_(other.scheme_),
|
||||
connectTimeout_(other.connectTimeout_),
|
||||
readTimeout_(other.readTimeout_) {
|
||||
readTimeout_(other.readTimeout_)
|
||||
{
|
||||
setContent(other.content_, other.contentSize_);
|
||||
}
|
||||
|
||||
ServiceRequest::ServiceRequest(ServiceRequest &&other) {
|
||||
ServiceRequest::ServiceRequest(ServiceRequest &&other)
|
||||
{
|
||||
*this = std::move(other);
|
||||
}
|
||||
|
||||
ServiceRequest& ServiceRequest::operator=(const ServiceRequest &other) {
|
||||
if (this != &other) {
|
||||
ServiceRequest &ServiceRequest::operator=(const ServiceRequest &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
content_ = nullptr;
|
||||
contentSize_ = 0;
|
||||
params_ = other.params_;
|
||||
@@ -61,35 +66,42 @@ ServiceRequest& ServiceRequest::operator=(const ServiceRequest &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
ServiceRequest& ServiceRequest::operator=(ServiceRequest &&other) {
|
||||
ServiceRequest &ServiceRequest::operator=(ServiceRequest &&other)
|
||||
{
|
||||
if (this != &other)
|
||||
*this = std::move(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ServiceRequest::~ServiceRequest() {
|
||||
ServiceRequest::~ServiceRequest()
|
||||
{
|
||||
if (content_)
|
||||
delete content_;
|
||||
}
|
||||
|
||||
const char * ServiceRequest::content() const {
|
||||
const char *ServiceRequest::content() const
|
||||
{
|
||||
return content_;
|
||||
}
|
||||
|
||||
size_t ServiceRequest::contentSize() const {
|
||||
size_t ServiceRequest::contentSize() const
|
||||
{
|
||||
return contentSize_;
|
||||
}
|
||||
|
||||
bool ServiceRequest::hasContent() const {
|
||||
bool ServiceRequest::hasContent() const
|
||||
{
|
||||
return (contentSize_ != 0);
|
||||
}
|
||||
|
||||
void ServiceRequest::setContent(const char * data, size_t size) {
|
||||
void ServiceRequest::setContent(const char *data, size_t size)
|
||||
{
|
||||
if (content_)
|
||||
delete content_;
|
||||
content_ = nullptr;
|
||||
contentSize_ = 0;
|
||||
if (size) {
|
||||
if (size)
|
||||
{
|
||||
contentSize_ = size;
|
||||
content_ = new char[size];
|
||||
std::copy(data, data + size, content_);
|
||||
@@ -97,93 +109,118 @@ void ServiceRequest::setContent(const char * data, size_t size) {
|
||||
}
|
||||
|
||||
void ServiceRequest::addParameter(const ParameterNameType &name,
|
||||
const ParameterValueType & value) {
|
||||
const ParameterValueType &value)
|
||||
{
|
||||
setParameter(name, value);
|
||||
}
|
||||
|
||||
ServiceRequest::ParameterValueType ServiceRequest::parameter(
|
||||
const ParameterNameType &name)const {
|
||||
const ParameterNameType &name) const
|
||||
{
|
||||
ParameterCollection::const_iterator it = params_.find(name);
|
||||
if (it == params_.end()) {
|
||||
if (it == params_.end())
|
||||
{
|
||||
return ParameterValueType("");
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
ServiceRequest::ParameterValueType ServiceRequest::coreParameter(
|
||||
const ParameterNameType &name)const {
|
||||
const ParameterNameType &name) const
|
||||
{
|
||||
return parameter(name);
|
||||
}
|
||||
|
||||
ServiceRequest::ParameterCollection ServiceRequest::parameters() const {
|
||||
ServiceRequest::ParameterCollection ServiceRequest::parameters() const
|
||||
{
|
||||
return params_;
|
||||
}
|
||||
|
||||
void ServiceRequest::removeParameter(const ParameterNameType & name) {
|
||||
void ServiceRequest::removeParameter(const ParameterNameType &name)
|
||||
{
|
||||
params_.erase(name);
|
||||
}
|
||||
|
||||
void ServiceRequest::setParameter(const ParameterNameType &name,
|
||||
const ParameterValueType &value) {
|
||||
const ParameterValueType &value)
|
||||
{
|
||||
params_[name] = value;
|
||||
}
|
||||
|
||||
void ServiceRequest::setCoreParameter(const ParameterNameType &name,
|
||||
const ParameterValueType &value) {
|
||||
void ServiceRequest::setCoreParameter(const ParameterNameType &name, const ParameterValueType &value)
|
||||
{
|
||||
setParameter(name, value);
|
||||
}
|
||||
|
||||
|
||||
void ServiceRequest::setParameters(const ParameterCollection & params) {
|
||||
void ServiceRequest::setParameters(const ParameterCollection ¶ms)
|
||||
{
|
||||
params_ = params;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::version()const {
|
||||
void ServiceRequest::setJsonParameters(const ParameterNameType &name, const ParameterCollection ¶ms)
|
||||
{
|
||||
params_ = params;
|
||||
params_ = params;
|
||||
setCoreParameter(name, AlibabaCloud::MapToJson(params));
|
||||
}
|
||||
|
||||
std::string ServiceRequest::version() const
|
||||
{
|
||||
return version_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setVersion(const std::string &version) {
|
||||
void ServiceRequest::setVersion(const std::string &version)
|
||||
{
|
||||
version_ = version;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::product() const {
|
||||
std::string ServiceRequest::product() const
|
||||
{
|
||||
return product_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setProduct(const std::string & product) {
|
||||
void ServiceRequest::setProduct(const std::string &product)
|
||||
{
|
||||
product_ = product;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::resourcePath() const {
|
||||
std::string ServiceRequest::resourcePath() const
|
||||
{
|
||||
return resourcePath_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setResourcePath(const std::string & path) {
|
||||
void ServiceRequest::setResourcePath(const std::string &path)
|
||||
{
|
||||
resourcePath_ = path;
|
||||
}
|
||||
|
||||
void ServiceRequest::setScheme(const std::string scheme) {
|
||||
void ServiceRequest::setScheme(const std::string scheme)
|
||||
{
|
||||
scheme_ = scheme;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::scheme() const {
|
||||
std::string ServiceRequest::scheme() const
|
||||
{
|
||||
return scheme_;
|
||||
}
|
||||
|
||||
long ServiceRequest::connectTimeout() const{
|
||||
long ServiceRequest::connectTimeout() const
|
||||
{
|
||||
return connectTimeout_;
|
||||
}
|
||||
|
||||
long ServiceRequest::readTimeout() const{
|
||||
long ServiceRequest::readTimeout() const
|
||||
{
|
||||
return readTimeout_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setConnectTimeout(const long connectTimeout) {
|
||||
void ServiceRequest::setConnectTimeout(const long connectTimeout)
|
||||
{
|
||||
connectTimeout_ = connectTimeout;
|
||||
}
|
||||
|
||||
void ServiceRequest::setReadTimeout(const long readTimeout) {
|
||||
void ServiceRequest::setReadTimeout(const long readTimeout)
|
||||
{
|
||||
readTimeout_ = readTimeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "Utils.h"
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
@@ -26,8 +27,10 @@
|
||||
#include <uuid/uuid.h>
|
||||
#endif
|
||||
#include <curl/curl.h>
|
||||
#include <json/json.h>
|
||||
|
||||
std::string AlibabaCloud::GenerateUuid() {
|
||||
std::string AlibabaCloud::GenerateUuid()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char *data;
|
||||
UUID uuidhandle;
|
||||
@@ -45,7 +48,8 @@ std::string AlibabaCloud::GenerateUuid() {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::UrlEncode(const std::string & src) {
|
||||
std::string AlibabaCloud::UrlEncode(const std::string &src)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
char *output = curl_easy_escape(curl, src.c_str(), src.size());
|
||||
std::string result(output);
|
||||
@@ -54,7 +58,8 @@ std::string AlibabaCloud::UrlEncode(const std::string & src) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::UrlDecode(const std::string & src) {
|
||||
std::string AlibabaCloud::UrlDecode(const std::string &src)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
int outlength = 0;
|
||||
char *output = curl_easy_unescape(curl, src.c_str(), src.size(), &outlength);
|
||||
@@ -64,7 +69,8 @@ std::string AlibabaCloud::UrlDecode(const std::string & src) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::ComputeContentMD5(const char * data, size_t size) {
|
||||
std::string AlibabaCloud::ComputeContentMD5(const char *data, size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HCRYPTPROV hProv = 0;
|
||||
HCRYPTHASH hHash = 0;
|
||||
@@ -83,34 +89,39 @@ std::string AlibabaCloud::ComputeContentMD5(const char * data, size_t size) {
|
||||
CryptBinaryToString(pbHash, dwDataLen,
|
||||
CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, NULL, &dlen);
|
||||
char *dest = new char[dlen];
|
||||
CryptBinaryToString(pbHash,
|
||||
dwDataLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, dest, &dlen);
|
||||
CryptBinaryToString(pbHash, dwDataLen,
|
||||
CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, dest, &dlen);
|
||||
|
||||
std::string ret = std::string(dest, dlen);
|
||||
delete dest;
|
||||
return ret;
|
||||
#else
|
||||
unsigned char md[MD5_DIGEST_LENGTH];
|
||||
MD5(reinterpret_cast<const unsigned char*>(data), size, (unsigned char*)&md);
|
||||
MD5(reinterpret_cast<const unsigned char *>(data), size,
|
||||
(unsigned char *)&md);
|
||||
|
||||
char encodedData[100];
|
||||
EVP_EncodeBlock(reinterpret_cast<unsigned char*>(encodedData),
|
||||
md, MD5_DIGEST_LENGTH);
|
||||
EVP_EncodeBlock(reinterpret_cast<unsigned char *>(encodedData), md,
|
||||
MD5_DIGEST_LENGTH);
|
||||
return encodedData;
|
||||
#endif
|
||||
}
|
||||
|
||||
void AlibabaCloud::StringReplace(std::string & src,
|
||||
const std::string & s1, const std::string & s2) {
|
||||
void AlibabaCloud::StringReplace(std::string &src, const std::string &s1,
|
||||
const std::string &s2)
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = src.find(s1, pos)) != std::string::npos) {
|
||||
while ((pos = src.find(s1, pos)) != std::string::npos)
|
||||
{
|
||||
src.replace(pos, s1.length(), s2);
|
||||
pos += s2.length();
|
||||
}
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::HttpMethodToString(HttpRequest::Method method) {
|
||||
switch (method) {
|
||||
std::string AlibabaCloud::HttpMethodToString(HttpRequest::Method method)
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case HttpRequest::Method::Head:
|
||||
return "HEAD";
|
||||
break;
|
||||
@@ -142,13 +153,15 @@ std::string AlibabaCloud::HttpMethodToString(HttpRequest::Method method) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::canonicalizedQuery(const std::map<std::string,
|
||||
std::string>& params) {
|
||||
std::string AlibabaCloud::canonicalizedQuery(
|
||||
const std::map<std::string, std::string> ¶ms)
|
||||
{
|
||||
if (params.empty())
|
||||
return std::string();
|
||||
|
||||
std::stringstream ss;
|
||||
for (const auto &p : params) {
|
||||
for (const auto &p : params)
|
||||
{
|
||||
std::string key = UrlEncode(p.first);
|
||||
StringReplace(key, "+", "%20");
|
||||
StringReplace(key, "*", "%2A");
|
||||
@@ -163,9 +176,11 @@ std::string AlibabaCloud::canonicalizedQuery(const std::map<std::string,
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::canonicalizedHeaders(
|
||||
const HttpMessage::HeaderCollection &headers) {
|
||||
const HttpMessage::HeaderCollection &headers)
|
||||
{
|
||||
std::map<std::string, std::string> materials;
|
||||
for (const auto &p : headers) {
|
||||
for (const auto &p : headers)
|
||||
{
|
||||
std::string key = p.first;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
if (key.find("x-acs-") != 0)
|
||||
@@ -188,25 +203,111 @@ std::string AlibabaCloud::canonicalizedHeaders(
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::GetEnv(const std::string env) {
|
||||
Json::Value AlibabaCloud::ReadJson(const std::string str)
|
||||
{
|
||||
Json::CharReaderBuilder builder;
|
||||
Json::CharReader *reader = builder.newCharReader();
|
||||
Json::Value *val;
|
||||
Json::Value value;
|
||||
JSONCPP_STRING *errs;
|
||||
reader->parse(str.data(), str.data() + str.size(), val, errs);
|
||||
if (errs == NULL)
|
||||
{
|
||||
value = *val;
|
||||
return value;
|
||||
}
|
||||
throw errs;
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::GetEnv(const std::string env)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char *buf = nullptr;
|
||||
size_t sz = 0;
|
||||
if (_dupenv_s(&buf, &sz, env.c_str()) == 0 && buf != nullptr) {
|
||||
if (_dupenv_s(&buf, &sz, env.c_str()) == 0 && buf != nullptr)
|
||||
{
|
||||
std::string var(buf);
|
||||
free(buf);
|
||||
return var;
|
||||
} else {
|
||||
if (buf) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buf)
|
||||
{
|
||||
free(buf);
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
#else
|
||||
char *var = getenv(env.c_str());
|
||||
if (var) {
|
||||
if (var)
|
||||
{
|
||||
return std::string(var);
|
||||
}
|
||||
return std::string();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string AlibabaCloud::MapToJson(const std::map<std::string, std::string> &maps)
|
||||
{
|
||||
Json::Value jsonObject;
|
||||
for (std::map<std::string, std::string>::const_iterator iter = maps.begin(); iter != maps.end(); ++iter)
|
||||
{
|
||||
jsonObject[iter->first] = iter->second;
|
||||
}
|
||||
return jsonObject.toStyledString();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> AlibabaCloud::JsonToMap(const std::string &json)
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
std::map<std::string, std::string> maps;
|
||||
|
||||
if (json.length() > 0)
|
||||
{
|
||||
if (reader.parse(json, value))
|
||||
{
|
||||
Json::Value::Members members = value.getMemberNames();
|
||||
for (Json::Value::Members::iterator it = members.begin(); it != members.end(); it++)
|
||||
{
|
||||
Json::ValueType vt = value[*it].type();
|
||||
switch (vt)
|
||||
{
|
||||
case Json::stringValue:
|
||||
{
|
||||
maps.insert(std::pair<std::string, std::string>(*it, value[*it].asString()));
|
||||
break;
|
||||
}
|
||||
case Json::intValue:
|
||||
{
|
||||
int inttmp = value[*it].asInt();
|
||||
maps.insert(std::pair<std::string, std::string>(*it, std::to_string(inttmp)));
|
||||
break;
|
||||
}
|
||||
case Json::arrayValue:
|
||||
{
|
||||
std::string strid;
|
||||
for (unsigned int i = 0; i < value[*it].size(); i++)
|
||||
{
|
||||
strid += value[*it][i].asString();
|
||||
strid += ",";
|
||||
}
|
||||
if (!strid.empty())
|
||||
{
|
||||
strid = strid.substr(0, strid.size() - 1);
|
||||
}
|
||||
maps.insert(std::pair<std::string, std::string>(*it, strid));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return maps;
|
||||
}
|
||||
@@ -14,18 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
#include <alibabacloud/core/location/model/DescribeEndpointsResult.h>
|
||||
#include <json/json.h>
|
||||
|
||||
using namespace AlibabaCloud::Location;
|
||||
using namespace AlibabaCloud::Location::Model;
|
||||
|
||||
DescribeEndpointsResult::DescribeEndpointsResult() :
|
||||
ServiceResult() {
|
||||
}
|
||||
DescribeEndpointsResult::DescribeEndpointsResult() : ServiceResult() {}
|
||||
|
||||
DescribeEndpointsResult::DescribeEndpointsResult(const std::string &payload) :
|
||||
ServiceResult() {
|
||||
DescribeEndpointsResult::DescribeEndpointsResult(const std::string &payload)
|
||||
: ServiceResult() {
|
||||
parse(payload);
|
||||
}
|
||||
|
||||
@@ -65,9 +64,7 @@ void DescribeEndpointsResult::setEndpoints(
|
||||
endpoints_ = endpoints;
|
||||
}
|
||||
|
||||
bool DescribeEndpointsResult::success()const {
|
||||
return success_;
|
||||
}
|
||||
bool DescribeEndpointsResult::success() const { return success_; }
|
||||
|
||||
void DescribeEndpointsResult::setSuccess(const bool &success) {
|
||||
success_ = success;
|
||||
|
||||
@@ -14,37 +14,36 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
#include <alibabacloud/core/sts/model/AssumeRoleResult.h>
|
||||
#include <json/json.h>
|
||||
|
||||
using namespace AlibabaCloud::Sts;
|
||||
using namespace AlibabaCloud::Sts::Model;
|
||||
|
||||
AssumeRoleResult::AssumeRoleResult() :
|
||||
ServiceResult(),
|
||||
assumedRoleUser_(),
|
||||
credentials_() {
|
||||
}
|
||||
AssumeRoleResult::AssumeRoleResult()
|
||||
: ServiceResult(), assumedRoleUser_(), credentials_() {}
|
||||
|
||||
AssumeRoleResult::AssumeRoleResult(const std::string & payload) :
|
||||
ServiceResult(),
|
||||
assumedRoleUser_(),
|
||||
credentials_() {
|
||||
AssumeRoleResult::AssumeRoleResult(const std::string &payload)
|
||||
: ServiceResult(), assumedRoleUser_(), credentials_()
|
||||
{
|
||||
parse(payload);
|
||||
}
|
||||
|
||||
AssumeRoleResult::~AssumeRoleResult() {
|
||||
}
|
||||
AssumeRoleResult::~AssumeRoleResult() {}
|
||||
|
||||
AssumeRoleResult::AssumedRoleUser AssumeRoleResult::assumedRoleUser() const {
|
||||
AssumeRoleResult::AssumedRoleUser AssumeRoleResult::assumedRoleUser() const
|
||||
{
|
||||
return assumedRoleUser_;
|
||||
}
|
||||
|
||||
AssumeRoleResult::Credentials AssumeRoleResult::credentials() const {
|
||||
AssumeRoleResult::Credentials AssumeRoleResult::credentials() const
|
||||
{
|
||||
return credentials_;
|
||||
}
|
||||
|
||||
void AssumeRoleResult::parse(const std::string & payload) {
|
||||
void AssumeRoleResult::parse(const std::string &payload)
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
reader.parse(payload, value);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/Utils.h>
|
||||
#include <alibabacloud/core/sts/model/GetCallerIdentityResult.h>
|
||||
#include <json/json.h>
|
||||
|
||||
@@ -21,35 +22,21 @@ using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Sts;
|
||||
using namespace AlibabaCloud::Sts::Model;
|
||||
|
||||
GetCallerIdentityResult::GetCallerIdentityResult() :
|
||||
ServiceResult(),
|
||||
accountId_(),
|
||||
arn_(),
|
||||
userId_() {
|
||||
}
|
||||
GetCallerIdentityResult::GetCallerIdentityResult()
|
||||
: ServiceResult(), accountId_(), arn_(), userId_() {}
|
||||
|
||||
GetCallerIdentityResult::GetCallerIdentityResult(const std::string & payload) :
|
||||
ServiceResult(),
|
||||
accountId_(),
|
||||
arn_(),
|
||||
userId_() {
|
||||
GetCallerIdentityResult::GetCallerIdentityResult(const std::string &payload)
|
||||
: ServiceResult(), accountId_(), arn_(), userId_() {
|
||||
parse(payload);
|
||||
}
|
||||
|
||||
GetCallerIdentityResult::~GetCallerIdentityResult() {
|
||||
}
|
||||
GetCallerIdentityResult::~GetCallerIdentityResult() {}
|
||||
|
||||
std::string GetCallerIdentityResult::accountId() {
|
||||
return accountId_;
|
||||
}
|
||||
std::string GetCallerIdentityResult::accountId() { return accountId_; }
|
||||
|
||||
std::string GetCallerIdentityResult::arn() const {
|
||||
return arn_;
|
||||
}
|
||||
std::string GetCallerIdentityResult::arn() const { return arn_; }
|
||||
|
||||
std::string GetCallerIdentityResult::userId() const {
|
||||
return userId_;
|
||||
}
|
||||
std::string GetCallerIdentityResult::userId() const { return userId_; }
|
||||
|
||||
void GetCallerIdentityResult::parse(const std::string &payload) {
|
||||
Json::Reader reader;
|
||||
|
||||
Reference in New Issue
Block a user