replace tab with 2 spaces in core dir

Copyright time changed to 1999-2019
This commit is contained in:
zhangzifa
2019-02-01 14:36:14 +08:00
committed by Jackson Tian
parent 138dbdc61e
commit da28515bd8
94 changed files with 2706 additions and 2704 deletions

View File

@@ -1,5 +1,5 @@
#
# Copyright 2009-2017 Alibaba Cloud All rights reserved.
# Copyright 1999-2019 Alibaba Cloud All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,9 +21,9 @@
namespace AlibabaCloud
{
ALIBABACLOUD_CORE_EXPORT void InitializeSdk();
ALIBABACLOUD_CORE_EXPORT bool IsSdkInitialized();
ALIBABACLOUD_CORE_EXPORT void ShutdownSdk();
ALIBABACLOUD_CORE_EXPORT void InitializeSdk();
ALIBABACLOUD_CORE_EXPORT bool IsSdkInitialized();
ALIBABACLOUD_CORE_EXPORT void ShutdownSdk();
}
#endif
#endif

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,17 +22,17 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT AsyncCallerContext
{
public:
AsyncCallerContext();
explicit AsyncCallerContext(const std::string &uuid);
virtual ~AsyncCallerContext();
std::string uuid()const;
void setUuid(const std::string &uuid);
private:
std::string uuid_;
};
class ALIBABACLOUD_CORE_EXPORT AsyncCallerContext
{
public:
AsyncCallerContext();
explicit AsyncCallerContext(const std::string &uuid);
virtual ~AsyncCallerContext();
std::string uuid()const;
void setUuid(const std::string &uuid);
private:
std::string uuid_;
};
}
#endif

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,24 +26,24 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT ClientConfiguration
{
public:
explicit ClientConfiguration(const std::string &regionId = "cn-hangzhou",
const NetworkProxy &proxy = NetworkProxy());
~ClientConfiguration();
class ALIBABACLOUD_CORE_EXPORT ClientConfiguration
{
public:
explicit ClientConfiguration(const std::string &regionId = "cn-hangzhou",
const NetworkProxy &proxy = NetworkProxy());
~ClientConfiguration();
std::string endpoint()const;
NetworkProxy proxy()const;
std::string regionId()const;
void setEndpoint(const std::string &endpoint);
void setProxy(const NetworkProxy &proxy);
void setRegionId(const std::string &regionId);
private:
std::string endpoint_;
NetworkProxy proxy_;
std::string regionId_;
};
std::string endpoint()const;
NetworkProxy proxy()const;
std::string regionId()const;
void setEndpoint(const std::string &endpoint);
void setProxy(const NetworkProxy &proxy);
void setRegionId(const std::string &regionId);
private:
std::string endpoint_;
NetworkProxy proxy_;
std::string regionId_;
};
}
#endif // !ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
#endif // !ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,36 +28,36 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT CommonClient : public CoreClient
{
public:
typedef Outcome<Error, CommonResponse> CommonResponseOutcome;
typedef std::future<CommonResponseOutcome> CommonResponseOutcomeCallable;
typedef std::function<void(const CommonClient*, const CommonRequest&, const CommonResponseOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> CommonResponseAsyncHandler;
typedef Outcome<Error, std::string> JsonOutcome;
class ALIBABACLOUD_CORE_EXPORT CommonClient : public CoreClient
{
public:
typedef Outcome<Error, CommonResponse> CommonResponseOutcome;
typedef std::future<CommonResponseOutcome> CommonResponseOutcomeCallable;
typedef std::function<void(const CommonClient*, const CommonRequest&, const CommonResponseOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> CommonResponseAsyncHandler;
typedef Outcome<Error, std::string> JsonOutcome;
CommonClient(const Credentials &credentials, const ClientConfiguration &configuration);
CommonClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
CommonClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
~CommonClient();
CommonClient(const Credentials &credentials, const ClientConfiguration &configuration);
CommonClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
CommonClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
~CommonClient();
CommonResponseOutcome commonResponse(const CommonRequest &request)const;
void commonResponseAsync(const CommonRequest& request, const CommonResponseAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
CommonResponseOutcomeCallable commonResponseCallable(const CommonRequest& request) const;
CommonResponseOutcome commonResponse(const CommonRequest &request)const;
void commonResponseAsync(const CommonRequest& request, const CommonResponseAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
CommonResponseOutcomeCallable commonResponseCallable(const CommonRequest& request) const;
protected:
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest & msg, HttpRequest::Method method) const override;
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;
JsonOutcome makeRequest(const std::string &endpoint, const CommonRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
using CoreClient::asyncExecute;
private:
std::string canonicalizedQuery(const std::map <std::string, std::string> &params)const;
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const;
protected:
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest & msg, HttpRequest::Method method) const override;
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;
JsonOutcome makeRequest(const std::string &endpoint, const CommonRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
using CoreClient::asyncExecute;
private:
std::string canonicalizedQuery(const std::map <std::string, std::string> &params)const;
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const;
std::shared_ptr<CredentialsProvider> credentialsProvider_;
std::shared_ptr<Signer> signer_;
};
std::shared_ptr<CredentialsProvider> credentialsProvider_;
std::shared_ptr<Signer> signer_;
};
}
#endif // !ALIBABACLOUD_CORE_COMMONCLIENT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,43 +24,43 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT CommonRequest : public ServiceRequest
{
public:
enum RequestPattern
{
RpcPattern,
RoaPattern
};
class ALIBABACLOUD_CORE_EXPORT CommonRequest : public ServiceRequest
{
public:
enum RequestPattern
{
RpcPattern,
RoaPattern
};
explicit CommonRequest(RequestPattern pattern = RpcPattern);
~CommonRequest();
explicit CommonRequest(RequestPattern pattern = RpcPattern);
~CommonRequest();
std::string domain()const;
ParameterValueType headerParameter(const ParameterNameType &name)const;
ParameterCollection headerParameters()const;
HttpRequest::Method httpMethod()const;
ParameterValueType queryParameter(const ParameterNameType &name)const;
ParameterCollection queryParameters()const;
using ServiceRequest::setContent;
void setDomain(const std::string &domain);
void setHeaderParameter(const ParameterNameType &name, const ParameterValueType &value);
void setHttpMethod(HttpRequest::Method method);
void setQueryParameter(const ParameterNameType &name, const ParameterValueType &value);
using ServiceRequest::setResourcePath;
void setRequestPattern(RequestPattern pattern);
using ServiceRequest::setVersion;
using ServiceRequest::setScheme;
RequestPattern requestPattern()const;
protected:
using ServiceRequest::product;
std::string domain()const;
ParameterValueType headerParameter(const ParameterNameType &name)const;
ParameterCollection headerParameters()const;
HttpRequest::Method httpMethod()const;
ParameterValueType queryParameter(const ParameterNameType &name)const;
ParameterCollection queryParameters()const;
using ServiceRequest::setContent;
void setDomain(const std::string &domain);
void setHeaderParameter(const ParameterNameType &name, const ParameterValueType &value);
void setHttpMethod(HttpRequest::Method method);
void setQueryParameter(const ParameterNameType &name, const ParameterValueType &value);
using ServiceRequest::setResourcePath;
void setRequestPattern(RequestPattern pattern);
using ServiceRequest::setVersion;
using ServiceRequest::setScheme;
RequestPattern requestPattern()const;
protected:
using ServiceRequest::product;
private:
std::string domain_;
RequestPattern requestPattern_;
ParameterCollection queryParams_;
ParameterCollection headerParams_;
HttpRequest::Method httpMethod_;
};
private:
std::string domain_;
RequestPattern requestPattern_;
ParameterCollection queryParams_;
ParameterCollection headerParams_;
HttpRequest::Method httpMethod_;
};
}
#endif // !ALIBABACLOUD_CORE_COMMONREQUEST_H_
#endif // !ALIBABACLOUD_CORE_COMMONREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,17 +22,17 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT CommonResponse
{
public:
CommonResponse();
explicit CommonResponse(const std::string &payload);
~CommonResponse();
class ALIBABACLOUD_CORE_EXPORT CommonResponse
{
public:
CommonResponse();
explicit CommonResponse(const std::string &payload);
~CommonResponse();
std::string payload()const;
private:
std::string payload_;
std::string payload()const;
private:
std::string payload_;
};
};
}
#endif // !ALIBABACLOUD_CORE_COMMONRESPONSE_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,25 +30,25 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT CoreClient
{
public:
CoreClient(const std::string & servicename, const ClientConfiguration &configuration);
virtual ~CoreClient();
class ALIBABACLOUD_CORE_EXPORT CoreClient
{
public:
CoreClient(const std::string & servicename, const ClientConfiguration &configuration);
virtual ~CoreClient();
ClientConfiguration configuration()const;
std::string serviceName()const;
protected:
virtual 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;
private:
std::string serviceName_;
ClientConfiguration configuration_;
std::shared_ptr<CredentialsProvider> credentialsProvider_;
HttpClient *httpClient_;
};
ClientConfiguration configuration()const;
std::string serviceName()const;
protected:
virtual 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;
private:
std::string serviceName_;
ClientConfiguration configuration_;
std::shared_ptr<CredentialsProvider> credentialsProvider_;
HttpClient *httpClient_;
};
}
#endif

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,13 +20,13 @@
#include "Global.h"
#if defined(ALIBABACLOUD_SHARED)
# if defined(ALIBABACLOUD_CORE_LIBRARY)
# define ALIBABACLOUD_CORE_EXPORT ALIBABACLOUD_DECL_EXPORT
# else
# define ALIBABACLOUD_CORE_EXPORT ALIBABACLOUD_DECL_IMPORT
# endif
# if defined(ALIBABACLOUD_CORE_LIBRARY)
# define ALIBABACLOUD_CORE_EXPORT ALIBABACLOUD_DECL_EXPORT
# else
# define ALIBABACLOUD_CORE_EXPORT ALIBABACLOUD_DECL_IMPORT
# endif
#else
# define ALIBABACLOUD_CORE_EXPORT
# define ALIBABACLOUD_CORE_EXPORT
#endif
#endif // !ALIBABACLOUD_CORE_COREEXPORT_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,26 +22,26 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT Credentials
{
public:
Credentials(const std::string &accessKeyId,
const std::string &accessKeySecret,
const std::string &sessionToken="");
~Credentials();
class ALIBABACLOUD_CORE_EXPORT Credentials
{
public:
Credentials(const std::string &accessKeyId,
const std::string &accessKeySecret,
const std::string &sessionToken="");
~Credentials();
std::string accessKeyId () const;
std::string accessKeySecret () const;
void setAccessKeyId(const std::string &accessKeyId);
void setAccessKeySecret(const std::string &accessKeySecret);
void setSessionToken (const std::string &sessionToken);
std::string sessionToken () const;
std::string accessKeyId () const;
std::string accessKeySecret () const;
void setAccessKeyId(const std::string &accessKeyId);
void setAccessKeySecret(const std::string &accessKeySecret);
void setSessionToken (const std::string &sessionToken);
std::string sessionToken () const;
private:
std::string accessKeyId_;
std::string accessKeySecret_;
std::string sessionToken_;
};
private:
std::string accessKeyId_;
std::string accessKeySecret_;
std::string sessionToken_;
};
}
#endif // !ALIBABACLOUD_CORE_CREDENTIAL_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,15 +22,15 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT CredentialsProvider
{
public:
CredentialsProvider() = default;
virtual ~CredentialsProvider() = default;
class ALIBABACLOUD_CORE_EXPORT CredentialsProvider
{
public:
CredentialsProvider() = default;
virtual ~CredentialsProvider() = default;
virtual Credentials getCredentials() = 0;
private:
virtual Credentials getCredentials() = 0;
private:
};
};
}
#endif
#endif

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,52 +27,52 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT EndpointProvider : public Location::LocationClient
{
public:
typedef Outcome<Error, std::string> EndpointOutcome;
class ALIBABACLOUD_CORE_EXPORT EndpointProvider : public Location::LocationClient
{
public:
typedef Outcome<Error, std::string> EndpointOutcome;
EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient,
const std::string regionId,
const std::string product,
const std::string serviceCode = std::string(),
int durationSeconds = 3600);
EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient,
const std::string regionId,
const std::string product,
const std::string serviceCode = std::string(),
int durationSeconds = 3600);
EndpointProvider(
const Credentials &credentials,
const ClientConfiguration &configuration,
const std::string &regionId,
const std::string &product,
const std::string &serviceCode = std::string(),
int durationSeconds = 3600);
~EndpointProvider();
EndpointProvider(
const Credentials &credentials,
const ClientConfiguration &configuration,
const std::string &regionId,
const std::string &product,
const std::string &serviceCode = std::string(),
int durationSeconds = 3600);
~EndpointProvider();
EndpointOutcome getEndpoint();
using LocationClient::describeEndpoints;
private:
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 getEndpoint();
using LocationClient::describeEndpoints;
private:
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);
EndpointOutcome loadRemoteEndpoint();
bool checkExpiry()const;
bool loadInternalProductsInfo();
std::string internalEndpoint(const std::string regionId, const std::string product);
std::mutex cachedMutex_;
std::string cachedEndpoint_;
int durationSeconds_;
std::chrono::system_clock::time_point expiry_;
std::string regionId_;
std::string product_;
std::string serviceCode_;
std::list<Product> internalProductsInfo_;
};
std::mutex cachedMutex_;
std::string cachedEndpoint_;
int durationSeconds_;
std::chrono::system_clock::time_point expiry_;
std::string regionId_;
std::string product_;
std::string serviceCode_;
std::list<Product> internalProductsInfo_;
};
}
#endif
#endif

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,27 +22,27 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT Error
{
public:
Error() = default;
Error(std::string code, const std::string message);
~Error() = default;
class ALIBABACLOUD_CORE_EXPORT Error
{
public:
Error() = default;
Error(std::string code, const std::string message);
~Error() = default;
std::string errorCode()const;
std::string errorMessage() const;
std::string host() const;
std::string requestId() const;
void setErrorCode(const std::string &code);
void setErrorMessage(const std::string& message);
void setHost(const std::string& host);
void setRequestId(const std::string& request);
private:
std::string errorCode_;
std::string message_;
std::string host_;
std::string requestId_;
};
std::string errorCode()const;
std::string errorMessage() const;
std::string host() const;
std::string requestId() const;
void setErrorCode(const std::string &code);
void setErrorMessage(const std::string& message);
void setHost(const std::string& host);
void setRequestId(const std::string& request);
private:
std::string errorCode_;
std::string message_;
std::string host_;
std::string requestId_;
};
}
#endif // !ALIBABACLOUD_CORE_ERROR_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,22 +20,22 @@
#include "Config.h"
#if defined(_WIN32)
# ifdef _MSC_VER
# pragma warning(disable : 4251)
# endif // _MSC_VER
# define ALIBABACLOUD_DECL_EXPORT __declspec(dllexport)
# define ALIBABACLOUD_DECL_IMPORT __declspec(dllimport)
# ifdef _MSC_VER
# pragma warning(disable : 4251)
# endif // _MSC_VER
# define ALIBABACLOUD_DECL_EXPORT __declspec(dllexport)
# define ALIBABACLOUD_DECL_IMPORT __declspec(dllimport)
#elif defined(__linux__)
# define ALIBABACLOUD_DECL_EXPORT __attribute__((visibility("default")))
# define ALIBABACLOUD_DECL_IMPORT __attribute__((visibility("default")))
# define ALIBABACLOUD_DECL_EXPORT __attribute__((visibility("default")))
# define ALIBABACLOUD_DECL_IMPORT __attribute__((visibility("default")))
#endif
#if !defined(ALIBABACLOUD_DECL_EXPORT)
# define ALIBABACLOUD_DECL_EXPORT
# define ALIBABACLOUD_DECL_EXPORT
#endif
#if !defined(ALIBABACLOUD_DECL_IMPORT)
# define ALIBABACLOUD_DECL_IMPORT
# define ALIBABACLOUD_DECL_IMPORT
#endif
#endif // !ALIBABACLOUD_CORE_GLOBAL_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,14 +21,14 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT HmacSha1Signer : public Signer
{
public:
HmacSha1Signer();
~HmacSha1Signer();
class ALIBABACLOUD_CORE_EXPORT HmacSha1Signer : public Signer
{
public:
HmacSha1Signer();
~HmacSha1Signer();
virtual std::string generate(const std::string &src, const std::string &secret)const override;
};
virtual std::string generate(const std::string &src, const std::string &secret)const override;
};
}
#endif // !ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,19 +25,19 @@
namespace AlibabaCloud
{
class HttpClient
{
public:
typedef Outcome<Error, HttpResponse> HttpResponseOutcome;
class HttpClient
{
public:
typedef Outcome<Error, HttpResponse> HttpResponseOutcome;
HttpClient();
virtual ~HttpClient();
HttpClient();
virtual ~HttpClient();
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) = 0;
NetworkProxy proxy()const;
void setProxy(const NetworkProxy &proxy);
private:
NetworkProxy proxy_;
};
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) = 0;
NetworkProxy proxy()const;
void setProxy(const NetworkProxy &proxy);
private:
NetworkProxy proxy_;
};
}
#endif
#endif

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,60 +23,60 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT HttpMessage
{
private:
struct ALIBABACLOUD_CORE_EXPORT nocaseLess
{
bool operator() (const std::string & s1, const std::string & s2) const;
};
public:
enum KnownHeader
{
Accept,
AcceptCharset,
AcceptEncoding,
AcceptLanguage,
Authorization,
Connection,
ContentLength,
ContentMD5,
ContentType,
Date,
Host,
Server,
UserAgent
};
class ALIBABACLOUD_CORE_EXPORT HttpMessage
{
private:
struct ALIBABACLOUD_CORE_EXPORT nocaseLess
{
bool operator() (const std::string & s1, const std::string & s2) const;
};
public:
enum KnownHeader
{
Accept,
AcceptCharset,
AcceptEncoding,
AcceptLanguage,
Authorization,
Connection,
ContentLength,
ContentMD5,
ContentType,
Date,
Host,
Server,
UserAgent
};
typedef std::string HeaderNameType;
typedef std::string HeaderValueType;
typedef std::map<HeaderNameType, HeaderValueType, nocaseLess> HeaderCollection;
typedef std::string HeaderNameType;
typedef std::string HeaderValueType;
typedef std::map<HeaderNameType, HeaderValueType, nocaseLess> HeaderCollection;
HttpMessage(const HttpMessage &other);
HttpMessage(HttpMessage &&other);
HttpMessage& operator=(const HttpMessage &other);
HttpMessage& operator=(HttpMessage &&other);
virtual ~HttpMessage();
HttpMessage(const HttpMessage &other);
HttpMessage(HttpMessage &&other);
HttpMessage& operator=(const HttpMessage &other);
HttpMessage& operator=(HttpMessage &&other);
virtual ~HttpMessage();
void addHeader(const HeaderNameType &name, const HeaderValueType &value);
void addHeader(KnownHeader header, const HeaderValueType &value);
const char* body()const;
size_t bodySize()const;
bool hasBody()const;
HeaderValueType header(const HeaderNameType &name)const;
HeaderValueType header(KnownHeader header)const;
HeaderCollection headers()const;
void removeHeader(const HeaderNameType &name);
void removeHeader(KnownHeader header);
void setBody(const char *data, size_t size);
void setHeader(const HeaderNameType &name, const HeaderValueType &value);
void setHeader(KnownHeader header, const std::string &value);
protected:
HttpMessage();
private:
char *body_;
size_t bodySize_;
HeaderCollection headers_;
};
void addHeader(const HeaderNameType &name, const HeaderValueType &value);
void addHeader(KnownHeader header, const HeaderValueType &value);
const char* body()const;
size_t bodySize()const;
bool hasBody()const;
HeaderValueType header(const HeaderNameType &name)const;
HeaderValueType header(KnownHeader header)const;
HeaderCollection headers()const;
void removeHeader(const HeaderNameType &name);
void removeHeader(KnownHeader header);
void setBody(const char *data, size_t size);
void setHeader(const HeaderNameType &name, const HeaderValueType &value);
void setHeader(KnownHeader header, const std::string &value);
protected:
HttpMessage();
private:
char *body_;
size_t bodySize_;
HeaderCollection headers_;
};
}
#endif // !ALIBABACLOUD_CORE_HTTPMESSAGE_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,31 +23,31 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT HttpRequest : public HttpMessage
{
public:
enum Method
{
Get,
Head,
Post,
Put,
Delete,
Connect,
Options,
Patch,
Trace
};
explicit HttpRequest(const Url &url = Url(), Method method = Get);
~HttpRequest();
class ALIBABACLOUD_CORE_EXPORT HttpRequest : public HttpMessage
{
public:
enum Method
{
Get,
Head,
Post,
Put,
Delete,
Connect,
Options,
Patch,
Trace
};
explicit HttpRequest(const Url &url = Url(), Method method = Get);
~HttpRequest();
Method method()const;
void setMethod(Method method);
void setUrl(const Url &url);
Url url()const;
private:
Method method_;
Url url_;
};
Method method()const;
void setMethod(Method method);
void setUrl(const Url &url);
Url url()const;
private:
Method method_;
Url url_;
};
}
#endif

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,20 +24,20 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT HttpResponse : public HttpMessage
{
public:
HttpResponse();
explicit HttpResponse(const HttpRequest & request);
~HttpResponse();
class ALIBABACLOUD_CORE_EXPORT HttpResponse : public HttpMessage
{
public:
HttpResponse();
explicit HttpResponse(const HttpRequest & request);
~HttpResponse();
HttpRequest request()const;
void setStatusCode(int code);
int statusCode()const;
private:
int statusCode_;
HttpRequest request_;
};
HttpRequest request()const;
void setStatusCode(int code);
int statusCode()const;
private:
int statusCode_;
HttpRequest request_;
};
}
#endif // !ALIBABACLOUD_CORE_HTTPRESPONSE_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,14 +21,14 @@
namespace AlibabaCloud
{
class InstanceProfileCredentials : public BasicSessionCredentials
{
public:
InstanceProfileCredentials();
~InstanceProfileCredentials();
class InstanceProfileCredentials : public BasicSessionCredentials
{
public:
InstanceProfileCredentials();
~InstanceProfileCredentials();
private:
private:
};
};
}
#endif // !ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,25 +27,25 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT InstanceProfileCredentialsProvider : public CredentialsProvider, public EcsMetadataFetcher
{
public:
InstanceProfileCredentialsProvider(const std::string &roleName, int durationSeconds = 3600);
~InstanceProfileCredentialsProvider();
class ALIBABACLOUD_CORE_EXPORT InstanceProfileCredentialsProvider : public CredentialsProvider, public EcsMetadataFetcher
{
public:
InstanceProfileCredentialsProvider(const std::string &roleName, int durationSeconds = 3600);
~InstanceProfileCredentialsProvider();
std::string roleName()const;
virtual Credentials getCredentials() override;
using EcsMetadataFetcher::roleName;
using EcsMetadataFetcher::setRoleName;
using EcsMetadataFetcher::getMetadata;
private:
void loadCredentials();
bool checkExpiry()const;
std::string roleName()const;
virtual Credentials getCredentials() override;
using EcsMetadataFetcher::roleName;
using EcsMetadataFetcher::setRoleName;
using EcsMetadataFetcher::getMetadata;
private:
void loadCredentials();
bool checkExpiry()const;
std::mutex cachedMutex_;
Credentials cachedCredentials_;
int durationSeconds_;
std::chrono::system_clock::time_point expiry_;
};
std::mutex cachedMutex_;
Credentials cachedCredentials_;
int durationSeconds_;
std::chrono::system_clock::time_point expiry_;
};
}
#endif
#endif

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,38 +22,38 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT NetworkProxy
{
public:
enum Type
{
None = 0,
Http,
Socks5
};
NetworkProxy(Type type = None,
const std::string &hostName = "",
uint16_t port = 0,
const std::string &user = "",
const std::string &password = "");
~NetworkProxy();
class ALIBABACLOUD_CORE_EXPORT NetworkProxy
{
public:
enum Type
{
None = 0,
Http,
Socks5
};
NetworkProxy(Type type = None,
const std::string &hostName = "",
uint16_t port = 0,
const std::string &user = "",
const std::string &password = "");
~NetworkProxy();
std::string hostName() const;
std::string password() const;
uint16_t port() const;
void setHostName(const std::string &hostName);
void setPassword(const std::string &password);
void setPort(uint16_t port);
void setType(Type type);
void setUser(const std::string &user);
Type type() const;
std::string user() const;
private:
std::string hostName_;
std::string password_;
uint16_t port_;
Type type_;
std::string user_;
};
std::string hostName() const;
std::string password() const;
uint16_t port() const;
void setHostName(const std::string &hostName);
void setPassword(const std::string &password);
void setPort(uint16_t port);
void setType(Type type);
void setUser(const std::string &user);
Type type() const;
std::string user() const;
private:
std::string hostName_;
std::string password_;
uint16_t port_;
Type type_;
std::string user_;
};
}
#endif // !ALIBABACLOUD_CORE_NETWORKPROXY_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,52 +21,52 @@
namespace AlibabaCloud
{
template<typename E, typename R>
class Outcome
{
public:
Outcome() :
success_(true), e_(), r_() { }
explicit Outcome(const E &e) :
e_(e), success_(false), r_() { }
explicit Outcome(const R &r) :
r_(r), success_(true), e_() { }
Outcome(const Outcome &other) :
success_(other.success_),
e_(other.e_),
r_(other.r_)
{ }
Outcome(Outcome &&other)
{
*this = std::move(other);
}
Outcome & operator=(const Outcome &other)
{
if (this != &other) {
success_ = other.success_;
e_ = other.e_;
r_ = other.r_;
}
return *this;
}
Outcome & operator=(Outcome &&other)
{
if (this != &other)
{
success_ = other.success_;
r_ = other.r_;
e_ = other.e_;
}
return *this;
}
template<typename E, typename R>
class Outcome
{
public:
Outcome() :
success_(true), e_(), r_() { }
explicit Outcome(const E &e) :
e_(e), success_(false), r_() { }
explicit Outcome(const R &r) :
r_(r), success_(true), e_() { }
Outcome(const Outcome &other) :
success_(other.success_),
e_(other.e_),
r_(other.r_)
{ }
Outcome(Outcome &&other)
{
*this = std::move(other);
}
Outcome & operator=(const Outcome &other)
{
if (this != &other) {
success_ = other.success_;
e_ = other.e_;
r_ = other.r_;
}
return *this;
}
Outcome & operator=(Outcome &&other)
{
if (this != &other)
{
success_ = other.success_;
r_ = other.r_;
e_ = other.e_;
}
return *this;
}
bool isSuccess()const { return success_; }
E error()const { return e_; }
R result()const { return r_; }
private:
bool success_;
E e_;
R r_;
};
bool isSuccess()const { return success_; }
E error()const { return e_; }
R result()const { return r_; }
private:
bool success_;
E e_;
R r_;
};
}
#endif // !ALIBABACLOUD_CORE_OUTCOME_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,27 +28,27 @@
namespace AlibabaCloud
{
class RoaErrorMarshaller;
class ALIBABACLOUD_CORE_EXPORT RoaServiceClient : public CoreClient
{
public:
typedef Outcome<Error, std::string> JsonOutcome;
class RoaErrorMarshaller;
class ALIBABACLOUD_CORE_EXPORT RoaServiceClient : public CoreClient
{
public:
typedef Outcome<Error, std::string> JsonOutcome;
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();
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();
protected:
JsonOutcome makeRequest(const std::string &endpoint, const RoaServiceRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const override;
HttpRequest buildHttpRequest(const std::string & endpoint, const RoaServiceRequest &msg, HttpRequest::Method method)const;
private:
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const;
std::string canonicalizedResource(const std::string &path, std::map <std::string, std::string> &params)const;
std::shared_ptr<CredentialsProvider> credentialsProvider_;
std::shared_ptr<Signer> signer_;
};
protected:
JsonOutcome makeRequest(const std::string &endpoint, const RoaServiceRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const override;
HttpRequest buildHttpRequest(const std::string & endpoint, const RoaServiceRequest &msg, HttpRequest::Method method)const;
private:
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const;
std::string canonicalizedResource(const std::string &path, std::map <std::string, std::string> &params)const;
std::shared_ptr<CredentialsProvider> credentialsProvider_;
std::shared_ptr<Signer> signer_;
};
}
#endif // !ALIBABACLOUD_CORE_ROASERVICECLIENT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,15 +21,15 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT RoaServiceRequest : public ServiceRequest
{
public:
RoaServiceRequest(const std::string &product, const std::string &version);
virtual ~RoaServiceRequest();
using ServiceRequest::setParameter;
using ServiceRequest::setContent;
using ServiceRequest::parameter;
using ServiceRequest::setScheme;
};
class ALIBABACLOUD_CORE_EXPORT RoaServiceRequest : public ServiceRequest
{
public:
RoaServiceRequest(const std::string &product, const std::string &version);
virtual ~RoaServiceRequest();
using ServiceRequest::setParameter;
using ServiceRequest::setContent;
using ServiceRequest::parameter;
using ServiceRequest::setScheme;
};
}
#endif // !ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,34 +29,34 @@
namespace AlibabaCloud
{
class RpcErrorMarshaller;
class RpcServiceRequest;
class ALIBABACLOUD_CORE_EXPORT RpcServiceClient : public CoreClient
{
public:
typedef Outcome<Error, std::string> JsonOutcome;
class RpcErrorMarshaller;
class RpcServiceRequest;
class ALIBABACLOUD_CORE_EXPORT RpcServiceClient : public CoreClient
{
public:
typedef Outcome<Error, std::string> JsonOutcome;
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();
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();
std::shared_ptr<CredentialsProvider> credentialsProvider() {
return credentialsProvider_;
}
using CoreClient::configuration;
std::shared_ptr<CredentialsProvider> credentialsProvider() {
return credentialsProvider_;
}
using CoreClient::configuration;
using CoreClient::AttemptRequest;
using CoreClient::AttemptRequest;
protected:
virtual JsonOutcome makeRequest(const std::string &endpoint, const RpcServiceRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const override;
HttpRequest buildHttpRequest(const std::string & endpoint, const RpcServiceRequest &msg, HttpRequest::Method method)const;
private:
std::string canonicalizedQuery(const std::map <std::string, std::string> &params)const;
protected:
virtual JsonOutcome makeRequest(const std::string &endpoint, const RpcServiceRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const override;
HttpRequest buildHttpRequest(const std::string & endpoint, const RpcServiceRequest &msg, HttpRequest::Method method)const;
private:
std::string canonicalizedQuery(const std::map <std::string, std::string> &params)const;
std::shared_ptr<CredentialsProvider> credentialsProvider_;
std::shared_ptr<Signer> signer_;
};
std::shared_ptr<CredentialsProvider> credentialsProvider_;
std::shared_ptr<Signer> signer_;
};
}
#endif // !ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,17 +21,17 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT RpcServiceRequest : public ServiceRequest
{
public:
RpcServiceRequest(const std::string &product, const std::string &version, const std::string & action);
virtual ~RpcServiceRequest();
class ALIBABACLOUD_CORE_EXPORT RpcServiceRequest : public ServiceRequest
{
public:
RpcServiceRequest(const std::string &product, const std::string &version, const std::string & action);
virtual ~RpcServiceRequest();
std::string actionName()const;
std::string actionName()const;
using ServiceRequest::setScheme;
protected:
void setActionName(const std::string &name);
protected:
void setActionName(const std::string &name);
};
};
}
#endif // !ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
#endif // !ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +22,14 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT Runnable
{
public:
explicit Runnable(const std::function<void()> f);
void run()const;
class ALIBABACLOUD_CORE_EXPORT Runnable
{
public:
explicit Runnable(const std::function<void()> f);
void run()const;
private:
std::function<void()> f_;
};
private:
std::function<void()> f_;
};
}
#endif // !ALIBABACLOUD_CORE_RUNNABLE_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,49 +23,49 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT ServiceRequest
{
public:
typedef std::string ParameterNameType;
typedef std::string ParameterValueType;
typedef std::map<ParameterNameType, ParameterValueType> ParameterCollection;
class ALIBABACLOUD_CORE_EXPORT ServiceRequest
{
public:
typedef std::string ParameterNameType;
typedef std::string ParameterValueType;
typedef std::map<ParameterNameType, ParameterValueType> ParameterCollection;
virtual ~ServiceRequest();
virtual ~ServiceRequest();
const char* content()const;
size_t contentSize()const;
bool hasContent()const;
ParameterCollection parameters()const;
std::string product()const;
std::string resourcePath()const;
std::string version()const;
std::string scheme()const;
protected:
ServiceRequest(const std::string &product, const std::string &version);
ServiceRequest(const ServiceRequest &other);
ServiceRequest(ServiceRequest &&other);
ServiceRequest& operator=(const ServiceRequest &other);
ServiceRequest& operator=(ServiceRequest &&other);
const char* content()const;
size_t contentSize()const;
bool hasContent()const;
ParameterCollection parameters()const;
std::string product()const;
std::string resourcePath()const;
std::string version()const;
std::string scheme()const;
protected:
ServiceRequest(const std::string &product, const std::string &version);
ServiceRequest(const ServiceRequest &other);
ServiceRequest(ServiceRequest &&other);
ServiceRequest& operator=(const ServiceRequest &other);
ServiceRequest& operator=(ServiceRequest &&other);
void addParameter(const ParameterNameType &name, const ParameterValueType &value);
ParameterValueType parameter(const ParameterNameType &name)const;
void removeParameter(const ParameterNameType &name);
void setContent(const char *data, size_t size);
void setParameter(const ParameterNameType &name, const ParameterValueType &value);
void setParameters(const ParameterCollection &params);
void setResourcePath(const std::string &path);
void setProduct(const std::string &product);
void setVersion(const std::string &version);
void setScheme(const std::string scheme);
private:
char *content_;
size_t contentSize_;
ParameterCollection params_;
std::string product_;
std::string resourcePath_;
std::string version_;
std::string scheme_;
};
void addParameter(const ParameterNameType &name, const ParameterValueType &value);
ParameterValueType parameter(const ParameterNameType &name)const;
void removeParameter(const ParameterNameType &name);
void setContent(const char *data, size_t size);
void setParameter(const ParameterNameType &name, const ParameterValueType &value);
void setParameters(const ParameterCollection &params);
void setResourcePath(const std::string &path);
void setProduct(const std::string &product);
void setVersion(const std::string &version);
void setScheme(const std::string scheme);
private:
char *content_;
size_t contentSize_;
ParameterCollection params_;
std::string product_;
std::string resourcePath_;
std::string version_;
std::string scheme_;
};
}
#endif // !ALIBABACLOUD_CORE_SERVICEREQUEST_H_
#endif // !ALIBABACLOUD_CORE_SERVICEREQUEST_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,19 +22,19 @@
namespace AlibabaCloud
{
class PayloadReader;
class ALIBABACLOUD_CORE_EXPORT ServiceResult
{
public:
ServiceResult();
virtual ~ServiceResult();
class PayloadReader;
class ALIBABACLOUD_CORE_EXPORT ServiceResult
{
public:
ServiceResult();
virtual ~ServiceResult();
std::string requestId()const;
protected:
void setRequestId(const std::string &requestId);
private:
std::string requestId_;
};
std::string requestId()const;
protected:
void setRequestId(const std::string &requestId);
private:
std::string requestId_;
};
}
#endif // !ALIBABACLOUD_CORE_SERVICERESULT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,25 +22,25 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT Signer
{
public:
enum Type
{
HmacSha1,
};
virtual ~Signer();
class ALIBABACLOUD_CORE_EXPORT Signer
{
public:
enum Type
{
HmacSha1,
};
virtual ~Signer();
virtual std::string generate(const std::string &src, const std::string &secret)const = 0;
std::string name()const;
Type type() const;
std::string version()const;
protected:
Signer(Type type, const std::string &name, const std::string &version = "1.0");
private:
std::string name_;
std::string version_;
Type type_;
};
virtual std::string generate(const std::string &src, const std::string &secret)const = 0;
std::string name()const;
Type type() const;
std::string version()const;
protected:
Signer(Type type, const std::string &name, const std::string &version = "1.0");
private:
std::string name_;
std::string version_;
Type type_;
};
}
#endif // !ALIBABACLOUD_CORE_SIGNER_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,17 +21,17 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT SimpleCredentialsProvider : public CredentialsProvider
{
public:
SimpleCredentialsProvider(const Credentials &credentials);
SimpleCredentialsProvider(const std::string &accessKeyId,
const std::string &accessKeySecret);
~SimpleCredentialsProvider();
class ALIBABACLOUD_CORE_EXPORT SimpleCredentialsProvider : public CredentialsProvider
{
public:
SimpleCredentialsProvider(const Credentials &credentials);
SimpleCredentialsProvider(const std::string &accessKeyId,
const std::string &accessKeySecret);
~SimpleCredentialsProvider();
virtual Credentials getCredentials() override;
private:
Credentials credentials_;
};
virtual Credentials getCredentials() override;
private:
Credentials credentials_;
};
}
#endif // !ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,31 +24,31 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT StsAssumeRoleCredentialsProvider : public CredentialsProvider, public Sts::StsClient
{
public:
StsAssumeRoleCredentialsProvider(
const Credentials &credentials,
const ClientConfiguration &configuration,
const std::string &roleArn,
const std::string &roleSessionName,
const std::string &policy = "",
int durationSeconds = 3600);
~StsAssumeRoleCredentialsProvider();
class ALIBABACLOUD_CORE_EXPORT StsAssumeRoleCredentialsProvider : public CredentialsProvider, public Sts::StsClient
{
public:
StsAssumeRoleCredentialsProvider(
const Credentials &credentials,
const ClientConfiguration &configuration,
const std::string &roleArn,
const std::string &roleSessionName,
const std::string &policy = "",
int durationSeconds = 3600);
~StsAssumeRoleCredentialsProvider();
virtual Credentials getCredentials() override;
using StsClient::assumeRole;
private:
void loadCredentials();
bool checkExpiry()const;
virtual Credentials getCredentials() override;
using StsClient::assumeRole;
private:
void loadCredentials();
bool checkExpiry()const;
std::mutex cachedMutex_;
Credentials cachedCredentials_;
int durationSeconds_;
std::chrono::system_clock::time_point expiry_;
std::string policy_;
std::string roleArn_;
std::string roleSessionName_;
};
std::mutex cachedMutex_;
Credentials cachedCredentials_;
int durationSeconds_;
std::chrono::system_clock::time_point expiry_;
std::string policy_;
std::string roleArn_;
std::string roleSessionName_;
};
}
#endif // !ALIBABACLOUD_CORE_STSASSUMEROLECREDENTIALSPROVIDER_H_
#endif // !ALIBABACLOUD_CORE_STSASSUMEROLECREDENTIALSPROVIDER_H_

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,54 +22,54 @@
namespace AlibabaCloud
{
class ALIBABACLOUD_CORE_EXPORT Url
{
public:
explicit Url(const std::string &url = "");
Url(const Url &other) = default;
Url(Url &&other) = default;
~Url();
Url & operator=(const Url &url) = default;
Url & operator=(Url &&other) = default;
bool operator==(const Url &url) const;
bool operator!=(const Url &url) const;
class ALIBABACLOUD_CORE_EXPORT Url
{
public:
explicit Url(const std::string &url = "");
Url(const Url &other) = default;
Url(Url &&other) = default;
~Url();
Url & operator=(const Url &url) = default;
Url & operator=(Url &&other) = default;
bool operator==(const Url &url) const;
bool operator!=(const Url &url) const;
std::string authority() const;
void clear();
std::string fragment() const;
void fromString(const std::string &url);
bool hasFragment() const;
bool hasQuery() const;
std::string host()const;
bool isEmpty() const;
bool isValid() const;
int port()const;
std::string password() const;
std::string path() const;
std::string query() const;
std::string scheme() const;
void setAuthority(const std::string &authority);
void setFragment(const std::string &fragment);
void setHost(const std::string &host);
void setPassword(const std::string &password);
void setPath(const std::string &path);
void setPort(int port);
void setQuery(const std::string &query);
void setScheme(const std::string &scheme);
void setUserInfo(const std::string &userInfo);
void setUserName(const std::string &userName);
std::string toString()const;
std::string userInfo() const;
std::string userName() const;
private:
std::string scheme_;
std::string userName_;
std::string password_;
std::string host_;
std::string path_;
int port_;
std::string query_;
std::string fragment_;
};
std::string authority() const;
void clear();
std::string fragment() const;
void fromString(const std::string &url);
bool hasFragment() const;
bool hasQuery() const;
std::string host()const;
bool isEmpty() const;
bool isValid() const;
int port()const;
std::string password() const;
std::string path() const;
std::string query() const;
std::string scheme() const;
void setAuthority(const std::string &authority);
void setFragment(const std::string &fragment);
void setHost(const std::string &host);
void setPassword(const std::string &password);
void setPath(const std::string &path);
void setPort(int port);
void setQuery(const std::string &query);
void setScheme(const std::string &scheme);
void setUserInfo(const std::string &userInfo);
void setUserName(const std::string &userName);
std::string toString()const;
std::string userInfo() const;
std::string userName() const;
private:
std::string scheme_;
std::string userName_;
std::string password_;
std::string host_;
std::string path_;
int port_;
std::string query_;
std::string fragment_;
};
}
#endif // !ALIBABACLOUD_CORE_URL_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,27 +25,27 @@
namespace AlibabaCloud
{
namespace Location
{
class ALIBABACLOUD_CORE_EXPORT LocationClient : public RpcServiceClient
{
public:
typedef Outcome<Error, Model::DescribeEndpointsResult> DescribeEndpointsOutcome;
typedef std::future<DescribeEndpointsOutcome> DescribeEndpointsOutcomeCallable;
typedef std::function<void(const LocationClient*, const Model::DescribeEndpointsRequest&, const DescribeEndpointsOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> DescribeEndpointsAsyncHandler;
namespace Location
{
class ALIBABACLOUD_CORE_EXPORT LocationClient : public RpcServiceClient
{
public:
typedef Outcome<Error, Model::DescribeEndpointsResult> DescribeEndpointsOutcome;
typedef std::future<DescribeEndpointsOutcome> DescribeEndpointsOutcomeCallable;
typedef std::function<void(const LocationClient*, const Model::DescribeEndpointsRequest&, const DescribeEndpointsOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> DescribeEndpointsAsyncHandler;
LocationClient(const Credentials &credentials, const ClientConfiguration &configuration);
LocationClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
LocationClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
LocationClient(const std::shared_ptr<Location::LocationClient>& locationClient);
~LocationClient();
virtual 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;
using RpcServiceClient::makeRequest;
using RpcServiceClient::configuration;
};
}
LocationClient(const Credentials &credentials, const ClientConfiguration &configuration);
LocationClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
LocationClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
LocationClient(const std::shared_ptr<Location::LocationClient>& locationClient);
~LocationClient();
virtual 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;
using RpcServiceClient::makeRequest;
using RpcServiceClient::configuration;
};
}
}
#endif // !ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
/*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,18 +21,18 @@
namespace AlibabaCloud
{
namespace Location
{
class ALIBABACLOUD_CORE_EXPORT LocationRequest : public RpcServiceRequest
{
public:
explicit LocationRequest(const std::string & action);
virtual ~LocationRequest();
namespace Location
{
class ALIBABACLOUD_CORE_EXPORT LocationRequest : public RpcServiceRequest
{
public:
explicit LocationRequest(const std::string & action);
virtual ~LocationRequest();
private:
private:
};
}
};
}
}
#endif // !ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
#endif // !ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,25 +22,25 @@
namespace AlibabaCloud
{
namespace Location
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT DescribeEndpointsRequest : public LocationRequest
{
public:
DescribeEndpointsRequest();
~DescribeEndpointsRequest();
namespace Location
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT DescribeEndpointsRequest : public LocationRequest
{
public:
DescribeEndpointsRequest();
~DescribeEndpointsRequest();
std::string serviceCode()const;
void setServiceCode(const std::string& serviceCode);
std::string id()const;
void setId(const std::string& id);
std::string type()const;
void setType(const std::string& type);
std::string serviceCode()const;
void setServiceCode(const std::string& serviceCode);
std::string id()const;
void setId(const std::string& id);
std::string type()const;
void setType(const std::string& type);
};
}
}
};
}
}
}
#endif // !ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,41 +24,41 @@
namespace AlibabaCloud
{
namespace Location
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT DescribeEndpointsResult : public ServiceResult
{
public:
struct Endpoint
{
std::string endpoint;
std::string id;
std::string namespace_;
std::string serivceCode;
std::string type;
std::vector<std::string> protocols;
};
namespace Location
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT DescribeEndpointsResult : public ServiceResult
{
public:
struct Endpoint
{
std::string endpoint;
std::string id;
std::string namespace_;
std::string serivceCode;
std::string type;
std::vector<std::string> protocols;
};
DescribeEndpointsResult();
explicit DescribeEndpointsResult(const std::string &payload);
~DescribeEndpointsResult();
DescribeEndpointsResult();
explicit DescribeEndpointsResult(const std::string &payload);
~DescribeEndpointsResult();
std::vector<Endpoint> endpoints()const;
void setEndpoints(const std::vector<Endpoint> &endpoints);
std::vector<Endpoint> endpoints()const;
void setEndpoints(const std::vector<Endpoint> &endpoints);
bool success()const;
void setSuccess(const bool &success);
bool success()const;
void setSuccess(const bool &success);
protected:
void parse(const std::string &payload);
private:
std::vector<Endpoint> endpoints_;
bool success_;
protected:
void parse(const std::string &payload);
private:
std::vector<Endpoint> endpoints_;
bool success_;
};
}
}
};
}
}
}
#endif // !ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
#endif // !ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,33 +27,33 @@
namespace AlibabaCloud
{
namespace Sts
{
class ALIBABACLOUD_CORE_EXPORT StsClient : public RpcServiceClient
{
public:
typedef Outcome<Error, Model::AssumeRoleResult> AssumeRoleOutcome;
typedef std::future<AssumeRoleOutcome> AssumeRoleOutcomeCallable;
typedef std::function<void(const StsClient*, const Model::AssumeRoleRequest&, const AssumeRoleOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> AssumeRoleAsyncHandler;
namespace Sts
{
class ALIBABACLOUD_CORE_EXPORT StsClient : public RpcServiceClient
{
public:
typedef Outcome<Error, Model::AssumeRoleResult> AssumeRoleOutcome;
typedef std::future<AssumeRoleOutcome> AssumeRoleOutcomeCallable;
typedef std::function<void(const StsClient*, const Model::AssumeRoleRequest&, const AssumeRoleOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> AssumeRoleAsyncHandler;
typedef Outcome<Error, Model::GetCallerIdentityResult> GetCallerIdentityOutcome;
typedef std::future<GetCallerIdentityOutcome> GetCallerIdentityOutcomeCallable;
typedef std::function<void(const StsClient*, const Model::GetCallerIdentityRequest&, const GetCallerIdentityOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> GetCallerIdentityAsyncHandler;
typedef Outcome<Error, Model::GetCallerIdentityResult> GetCallerIdentityOutcome;
typedef std::future<GetCallerIdentityOutcome> GetCallerIdentityOutcomeCallable;
typedef std::function<void(const StsClient*, const Model::GetCallerIdentityRequest&, const GetCallerIdentityOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> GetCallerIdentityAsyncHandler;
StsClient(const Credentials &credentials, const ClientConfiguration &configuration);
StsClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
StsClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
~StsClient();
StsClient(const Credentials &credentials, const ClientConfiguration &configuration);
StsClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
StsClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
~StsClient();
virtual AssumeRoleOutcome assumeRole(const Model::AssumeRoleRequest &request)const;
void assumeRoleAsync(const Model::AssumeRoleRequest& request, const AssumeRoleAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
AssumeRoleOutcomeCallable assumeRoleCallable(const Model::AssumeRoleRequest& request) const;
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;
using RpcServiceClient::makeRequest;
};
}
virtual AssumeRoleOutcome assumeRole(const Model::AssumeRoleRequest &request)const;
void assumeRoleAsync(const Model::AssumeRoleRequest& request, const AssumeRoleAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
AssumeRoleOutcomeCallable assumeRoleCallable(const Model::AssumeRoleRequest& request) const;
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;
using RpcServiceClient::makeRequest;
};
}
}
#endif // !ALIBABACLOUD_CORE_STS_STSCLIENT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,18 +21,18 @@
namespace AlibabaCloud
{
namespace Sts
{
class ALIBABACLOUD_CORE_EXPORT StsRequest : public RpcServiceRequest
{
public:
explicit StsRequest(const std::string & action);
virtual ~StsRequest();
namespace Sts
{
class ALIBABACLOUD_CORE_EXPORT StsRequest : public RpcServiceRequest
{
public:
explicit StsRequest(const std::string & action);
virtual ~StsRequest();
private:
private:
};
}
};
}
}
#endif // !ALIBABACLOUD_CORE_STS_STSSERVICEREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,26 +22,26 @@
namespace AlibabaCloud
{
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT AssumeRoleRequest : public StsRequest
{
public:
AssumeRoleRequest();
~AssumeRoleRequest();
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT AssumeRoleRequest : public StsRequest
{
public:
AssumeRoleRequest();
~AssumeRoleRequest();
int durationSeconds()const;
std::string policy()const;
std::string roleArn()const;
std::string roleSessionName()const;
void setDurationSeconds(int durationSeconds);
void setPolicy(const std::string &policy);
void setRoleArn(const std::string & roleArn);
void setRoleSessionName(const std::string & roleSessionName);
};
}
}
int durationSeconds()const;
std::string policy()const;
std::string roleArn()const;
std::string roleSessionName()const;
void setDurationSeconds(int durationSeconds);
void setPolicy(const std::string &policy);
void setRoleArn(const std::string & roleArn);
void setRoleSessionName(const std::string & roleSessionName);
};
}
}
}
#endif // !ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLEREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,39 +21,39 @@
namespace AlibabaCloud
{
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT AssumeRoleResult : public ServiceResult
{
public:
struct AssumedRoleUser
{
std::string arn;
std::string assumedRoleId;
};
struct Credentials
{
std::string accessKeyId;
std::string accessKeySecret;
std::string expiration;
std::string securityToken;
};
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT AssumeRoleResult : public ServiceResult
{
public:
struct AssumedRoleUser
{
std::string arn;
std::string assumedRoleId;
};
struct Credentials
{
std::string accessKeyId;
std::string accessKeySecret;
std::string expiration;
std::string securityToken;
};
AssumeRoleResult();
explicit AssumeRoleResult(const std::string &payload);
~AssumeRoleResult();
AssumeRoleResult();
explicit AssumeRoleResult(const std::string &payload);
~AssumeRoleResult();
AssumedRoleUser assumedRoleUser()const;
Credentials credentials()const;
private:
void parse(const std::string &payload);
AssumedRoleUser assumedRoleUser()const;
Credentials credentials()const;
private:
void parse(const std::string &payload);
AssumedRoleUser assumedRoleUser_;
Credentials credentials_;
};
}
}
AssumedRoleUser assumedRoleUser_;
Credentials credentials_;
};
}
}
}
#endif // !ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLERESULT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,20 +22,20 @@
namespace AlibabaCloud
{
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityRequest : public StsRequest
{
public:
GetCallerIdentityRequest();
~GetCallerIdentityRequest();
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityRequest : public StsRequest
{
public:
GetCallerIdentityRequest();
~GetCallerIdentityRequest();
private:
private:
};
}
}
};
}
}
}
#endif // !ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYREQUEST_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,29 +21,29 @@
namespace AlibabaCloud
{
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityResult : public ServiceResult
{
public:
GetCallerIdentityResult();
explicit GetCallerIdentityResult(const std::string &payload);
~GetCallerIdentityResult();
namespace Sts
{
namespace Model
{
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityResult : public ServiceResult
{
public:
GetCallerIdentityResult();
explicit GetCallerIdentityResult(const std::string &payload);
~GetCallerIdentityResult();
std::string accountId();
std::string arn()const;
std::string userId()const;
private:
void parse(const std::string &payload);
std::string accountId();
std::string arn()const;
std::string userId()const;
private:
void parse(const std::string &payload);
std::string accountId_;
std::string arn_;
std::string userId_;
};
}
}
std::string accountId_;
std::string arn_;
std::string userId_;
};
}
}
}
#endif // !ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYRESULT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,24 +21,24 @@ static AlibabaCloud::Executor * executor = nullptr;
void AlibabaCloud::InitializeSdk()
{
if (IsSdkInitialized())
return;
if (IsSdkInitialized())
return;
executor = new Executor;
executor->start();
executor = new Executor;
executor->start();
}
bool AlibabaCloud::IsSdkInitialized()
{
return executor != nullptr;
return executor != nullptr;
}
void AlibabaCloud::ShutdownSdk()
{
if (!IsSdkInitialized())
return;
if (!IsSdkInitialized())
return;
executor->shutdown();
delete executor;
executor = nullptr;
executor->shutdown();
delete executor;
executor = nullptr;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,12 +20,12 @@
using namespace AlibabaCloud;
AsyncCallerContext::AsyncCallerContext() :
uuid_(GenerateUuid())
uuid_(GenerateUuid())
{
}
AsyncCallerContext::AsyncCallerContext(const std::string &uuid) :
uuid_(uuid)
uuid_(uuid)
{
}
@@ -35,10 +35,10 @@ AsyncCallerContext::~AsyncCallerContext()
std::string AsyncCallerContext::uuid()const
{
return uuid_;
return uuid_;
}
void AsyncCallerContext::setUuid(const std::string &uuid)
{
uuid_ = uuid;
uuid_ = uuid;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,10 +19,10 @@
using namespace AlibabaCloud;
ClientConfiguration::ClientConfiguration(const std::string &regionId,
const NetworkProxy &proxy):
regionId_(regionId),
proxy_(proxy),
endpoint_()
const NetworkProxy &proxy):
regionId_(regionId),
proxy_(proxy),
endpoint_()
{
}
@@ -32,30 +32,30 @@ ClientConfiguration::~ClientConfiguration()
std::string ClientConfiguration::endpoint() const
{
return endpoint_;
return endpoint_;
}
NetworkProxy ClientConfiguration::proxy()const
{
return proxy_;
return proxy_;
}
std::string ClientConfiguration::regionId()const
{
return regionId_;
return regionId_;
}
void ClientConfiguration::setEndpoint(const std::string & endpoint)
{
endpoint_ = endpoint;
endpoint_ = endpoint;
}
void ClientConfiguration::setProxy(const NetworkProxy &proxy)
{
proxy_ = proxy;
proxy_ = proxy;
}
void ClientConfiguration::setRegionId(const std::string &regionId)
{
regionId_ = regionId;
}
regionId_ = regionId;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,27 +28,27 @@ using namespace Location;
namespace
{
const std::string SERVICE_NAME = "Common";
const std::string SERVICE_NAME = "Common";
}
CommonClient::CommonClient(const Credentials &credentials, const ClientConfiguration &configuration) :
CoreClient(SERVICE_NAME, configuration),
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(credentials)),
signer_(std::make_shared<HmacSha1Signer>())
CoreClient(SERVICE_NAME, configuration),
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(credentials)),
signer_(std::make_shared<HmacSha1Signer>())
{
}
CommonClient::CommonClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
CoreClient(SERVICE_NAME, configuration),
credentialsProvider_(credentialsProvider),
signer_(std::make_shared<HmacSha1Signer>())
CoreClient(SERVICE_NAME, configuration),
credentialsProvider_(credentialsProvider),
signer_(std::make_shared<HmacSha1Signer>())
{
}
CommonClient::CommonClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
CoreClient(SERVICE_NAME, configuration),
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret)),
signer_(std::make_shared<HmacSha1Signer>())
CoreClient(SERVICE_NAME, configuration),
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret)),
signer_(std::make_shared<HmacSha1Signer>())
{
}
@@ -58,259 +58,259 @@ CommonClient::~CommonClient()
CommonClient::JsonOutcome CommonClient::makeRequest(const std::string &endpoint, const CommonRequest &msg, HttpRequest::Method method)const
{
auto outcome = AttemptRequest(endpoint, msg, method);
if (outcome.isSuccess())
return JsonOutcome(std::string(outcome.result().body(),
outcome.result().bodySize()));
else
return JsonOutcome(outcome.error());
auto outcome = AttemptRequest(endpoint, msg, method);
if (outcome.isSuccess())
return JsonOutcome(std::string(outcome.result().body(),
outcome.result().bodySize()));
else
return JsonOutcome(outcome.error());
}
CommonClient::CommonResponseOutcome CommonClient::commonResponse(const CommonRequest & request) const
{
auto outcome = makeRequest(request.domain(), request, request.httpMethod());
auto outcome = makeRequest(request.domain(), request, request.httpMethod());
if (outcome.isSuccess())
return CommonResponseOutcome(CommonResponse(outcome.result()));
else
return CommonResponseOutcome(Error(outcome.error()));
if (outcome.isSuccess())
return CommonResponseOutcome(CommonResponse(outcome.result()));
else
return CommonResponseOutcome(Error(outcome.error()));
}
void CommonClient::commonResponseAsync(const CommonRequest & request, const CommonResponseAsyncHandler & handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, commonResponse(request), context);
};
auto fn = [this, request, handler, context]()
{
handler(this, request, commonResponse(request), context);
};
asyncExecute(new Runnable(fn));
asyncExecute(new Runnable(fn));
}
CommonClient::CommonResponseOutcomeCallable CommonClient::commonResponseCallable(const CommonRequest & request) const
{
auto task = std::make_shared<std::packaged_task<CommonResponseOutcome()>>(
[this, request]()
{
return this->commonResponse(request);
});
auto task = std::make_shared<std::packaged_task<CommonResponseOutcome()>>(
[this, request]()
{
return this->commonResponse(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}
HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint, const ServiceRequest & msg, HttpRequest::Method method) const
{
return buildHttpRequest(endpoint, dynamic_cast<const CommonRequest& >(msg), method);
return buildHttpRequest(endpoint, dynamic_cast<const CommonRequest& >(msg), method);
}
HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
{
if (msg.requestPattern() == CommonRequest::RpcPattern)
return buildRpcHttpRequest(endpoint, msg, method);
else
return buildRoaHttpRequest(endpoint, msg, method);
if (msg.requestPattern() == CommonRequest::RpcPattern)
return buildRpcHttpRequest(endpoint, msg, method);
else
return buildRoaHttpRequest(endpoint, msg, method);
}
std::string CommonClient::canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const
{
std::map <std::string, std::string> materials;
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)
continue;
std::map <std::string, std::string> materials;
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)
continue;
std::string value = p.second;
StringReplace(value, "\t", " ");
StringReplace(value, "\n", " ");
StringReplace(value, "\r", " ");
StringReplace(value, "\f", " ");
materials[key] = value;
}
std::string value = p.second;
StringReplace(value, "\t", " ");
StringReplace(value, "\n", " ");
StringReplace(value, "\r", " ");
StringReplace(value, "\f", " ");
materials[key] = value;
}
if (materials.empty())
return std::string();
std::stringstream ss;
for (const auto &p : materials)
ss << p.first << ":" << p.second << "\n";
if (materials.empty())
return std::string();
std::stringstream ss;
for (const auto &p : materials)
ss << p.first << ":" << p.second << "\n";
return ss.str();
return ss.str();
}
HttpRequest CommonClient::buildRoaHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
{
const Credentials credentials = credentialsProvider_->getCredentials();
const Credentials credentials = credentialsProvider_->getCredentials();
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
url.setHost(endpoint);
url.setPath(msg.resourcePath());
url.setHost(endpoint);
url.setPath(msg.resourcePath());
auto params = msg.headerParameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params) {
if (!p.second.empty())
queryParams[p.first] = p.second;
}
auto params = msg.headerParameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params) {
if (!p.second.empty())
queryParams[p.first] = p.second;
}
if (!queryParams.empty()) {
std::stringstream queryString;
for (const auto &p : queryParams)
{
if (p.second.empty())
queryString << "&" << p.first;
else
queryString << "&" << p.first << "=" << p.second;
}
url.setQuery(queryString.str().substr(1));
}
if (!queryParams.empty()) {
std::stringstream queryString;
for (const auto &p : queryParams)
{
if (p.second.empty())
queryString << "&" << p.first;
else
queryString << "&" << p.first << "=" << p.second;
}
url.setQuery(queryString.str().substr(1));
}
HttpRequest request(url);
request.setMethod(method);
if (msg.headerParameter("Accept").empty()) {
request.setHeader("Accept", "application/json");
} else {
request.setHeader("Accept", msg.headerParameter("Accept"));
}
HttpRequest request(url);
request.setMethod(method);
if (msg.headerParameter("Accept").empty()) {
request.setHeader("Accept", "application/json");
} else {
request.setHeader("Accept", msg.headerParameter("Accept"));
}
if (msg.hasContent()) {
std::stringstream ss;
ss << msg.contentSize();
request.setHeader("Content-Length", ss.str());
if(msg.headerParameter("Content-Type").empty()) {
request.setHeader("Content-Type", "application/octet-stream");
} else {
request.setHeader("Content-Type", msg.headerParameter("Content-Type"));
}
request.setHeader("Content-MD5", ComputeContentMD5(msg.content(), msg.contentSize()));
request.setBody(msg.content(), msg.contentSize());
}
if (msg.hasContent()) {
std::stringstream ss;
ss << msg.contentSize();
request.setHeader("Content-Length", ss.str());
if(msg.headerParameter("Content-Type").empty()) {
request.setHeader("Content-Type", "application/octet-stream");
} else {
request.setHeader("Content-Type", msg.headerParameter("Content-Type"));
}
request.setHeader("Content-MD5", ComputeContentMD5(msg.content(), msg.contentSize()));
request.setBody(msg.content(), msg.contentSize());
}
std::time_t t = std::time(nullptr);
std::stringstream date;
std::time_t t = std::time(nullptr);
std::stringstream date;
#if defined(__GNUG__) && __GNUC__ < 5
char tmbuff[26];
strftime(tmbuff, 26, "%a, %d %b %Y %T", std::gmtime(&t));
date << tmbuff << " GMT";
char tmbuff[26];
strftime(tmbuff, 26, "%a, %d %b %Y %T", std::gmtime(&t));
date << tmbuff << " GMT";
#else
date << std::put_time(std::gmtime(&t), "%a, %d %b %Y %T GMT");
date << std::put_time(std::gmtime(&t), "%a, %d %b %Y %T GMT");
#endif
request.setHeader("Date", date.str());
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
request.setHeader("x-acs-region-id", configuration().regionId());
if (!credentials.sessionToken().empty())
request.setHeader("x-acs-security-token", credentials.sessionToken());
request.setHeader("x-acs-signature-method", signer_->name());
request.setHeader("x-acs-signature-nonce", GenerateUuid());
request.setHeader("x-acs-signature-version", signer_->version());
request.setHeader("x-acs-version", msg.version());
request.setHeader("Date", date.str());
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
request.setHeader("x-acs-region-id", configuration().regionId());
if (!credentials.sessionToken().empty())
request.setHeader("x-acs-security-token", credentials.sessionToken());
request.setHeader("x-acs-signature-method", signer_->name());
request.setHeader("x-acs-signature-nonce", GenerateUuid());
request.setHeader("x-acs-signature-version", signer_->version());
request.setHeader("x-acs-version", msg.version());
std::stringstream plaintext;
plaintext << HttpMethodToString(method) << "\n"
<< request.header("Accept") << "\n"
<< request.header("Content-MD5") << "\n"
<< request.header("Content-Type") << "\n"
<< request.header("Date") << "\n"
<< canonicalizedHeaders(request.headers());
if (!url.hasQuery())
plaintext << url.path();
else
plaintext << url.path() << "?" << url.query();
std::stringstream plaintext;
plaintext << HttpMethodToString(method) << "\n"
<< request.header("Accept") << "\n"
<< request.header("Content-MD5") << "\n"
<< request.header("Content-Type") << "\n"
<< request.header("Date") << "\n"
<< canonicalizedHeaders(request.headers());
if (!url.hasQuery())
plaintext << url.path();
else
plaintext << url.path() << "?" << url.query();
std::stringstream sign;
sign << "acs "
<< credentials.accessKeyId()
<< ":"
<< signer_->generate(plaintext.str(), credentials.accessKeySecret());
request.setHeader("Authorization", sign.str());
return request;
std::stringstream sign;
sign << "acs "
<< credentials.accessKeyId()
<< ":"
<< signer_->generate(plaintext.str(), credentials.accessKeySecret());
request.setHeader("Authorization", sign.str());
return request;
}
std::string CommonClient::canonicalizedQuery(const std::map<std::string, std::string>& params) const
{
if (params.empty())
return std::string();
if (params.empty())
return std::string();
std::stringstream ss;
for (const auto &p : params)
{
std::string key = UrlEncode(p.first);
StringReplace(key, "+", "%20");
StringReplace(key, "*", "%2A");
StringReplace(key, "%7E", "~");
std::string value = UrlEncode(p.second);
StringReplace(value, "+", "%20");
StringReplace(value, "*", "%2A");
StringReplace(value, "%7E", "~");
ss << "&" << key << "=" << value;
}
return ss.str().substr(1);
std::stringstream ss;
for (const auto &p : params)
{
std::string key = UrlEncode(p.first);
StringReplace(key, "+", "%20");
StringReplace(key, "*", "%2A");
StringReplace(key, "%7E", "~");
std::string value = UrlEncode(p.second);
StringReplace(value, "+", "%20");
StringReplace(value, "*", "%2A");
StringReplace(value, "%7E", "~");
ss << "&" << key << "=" << value;
}
return ss.str().substr(1);
}
HttpRequest CommonClient::buildRpcHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
{
const Credentials credentials = credentialsProvider_->getCredentials();
const Credentials credentials = credentialsProvider_->getCredentials();
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
url.setHost(endpoint);
url.setPath(msg.resourcePath());
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
url.setHost(endpoint);
url.setPath(msg.resourcePath());
auto params = msg.queryParameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params) {
if (!p.second.empty())
queryParams[p.first] = p.second;
}
auto params = msg.queryParameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params) {
if (!p.second.empty())
queryParams[p.first] = p.second;
}
queryParams["AccessKeyId"] = credentials.accessKeyId();
queryParams["Format"] = "JSON";
queryParams["RegionId"] = configuration().regionId();
queryParams["SecurityToken"] = credentials.sessionToken();
queryParams["SignatureMethod"] = signer_->name();
queryParams["SignatureNonce"] = GenerateUuid();
queryParams["SignatureVersion"] = signer_->version();
std::time_t t = std::time(nullptr);
std::stringstream ss;
queryParams["AccessKeyId"] = credentials.accessKeyId();
queryParams["Format"] = "JSON";
queryParams["RegionId"] = configuration().regionId();
queryParams["SecurityToken"] = credentials.sessionToken();
queryParams["SignatureMethod"] = signer_->name();
queryParams["SignatureNonce"] = GenerateUuid();
queryParams["SignatureVersion"] = signer_->version();
std::time_t t = std::time(nullptr);
std::stringstream ss;
#if defined(__GNUG__) && __GNUC__ < 5
char tmbuff[26];
strftime(tmbuff, 26, "%FT%TZ", std::gmtime(&t));
ss << tmbuff;
char tmbuff[26];
strftime(tmbuff, 26, "%FT%TZ", std::gmtime(&t));
ss << tmbuff;
#else
ss << std::put_time(std::gmtime(&t), "%FT%TZ");
ss << std::put_time(std::gmtime(&t), "%FT%TZ");
#endif
queryParams["Timestamp"] = ss.str();
queryParams["Version"] = msg.version();
queryParams["Timestamp"] = ss.str();
queryParams["Version"] = msg.version();
std::stringstream plaintext;
plaintext << HttpMethodToString(method)
<< "&"
<< UrlEncode(url.path())
<< "&"
<< UrlEncode(canonicalizedQuery(queryParams));
std::stringstream plaintext;
plaintext << HttpMethodToString(method)
<< "&"
<< UrlEncode(url.path())
<< "&"
<< UrlEncode(canonicalizedQuery(queryParams));
queryParams["Signature"] = signer_->generate(plaintext.str(), credentials.accessKeySecret() + "&");
queryParams["Signature"] = signer_->generate(plaintext.str(), credentials.accessKeySecret() + "&");
std::stringstream queryString;
for (const auto &p : queryParams)
queryString << "&" << p.first << "=" << UrlEncode(p.second);
url.setQuery(queryString.str().substr(1));
std::stringstream queryString;
for (const auto &p : queryParams)
queryString << "&" << p.first << "=" << UrlEncode(p.second);
url.setQuery(queryString.str().substr(1));
HttpRequest request(url);
request.setMethod(method);
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
return request;
}
HttpRequest request(url);
request.setMethod(method);
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
return request;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,82 +19,84 @@
using namespace AlibabaCloud;
CommonRequest::CommonRequest(RequestPattern pattern):
ServiceRequest("",""),
domain_(),
queryParams_(),
httpMethod_(HttpRequest::Get),
requestPattern_(pattern)
ServiceRequest("",""),
domain_(),
queryParams_(),
httpMethod_(HttpRequest::Get),
requestPattern_(pattern)
{
}
CommonRequest::~CommonRequest()
{}
{
}
std::string CommonRequest::domain()const
{
return domain_;
return domain_;
}
void CommonRequest::setDomain(const std::string &domain)
{
domain_ = domain;
domain_ = domain;
}
CommonRequest::RequestPattern CommonRequest::requestPattern() const
{
return requestPattern_;
return requestPattern_;
}
void CommonRequest::setRequestPattern(RequestPattern pattern)
{
requestPattern_ = pattern;
requestPattern_ = pattern;
}
void CommonRequest::setHttpMethod(HttpRequest::Method method)
{
httpMethod_ = method;
httpMethod_ = method;
}
HttpRequest::Method CommonRequest::httpMethod() const
{
return httpMethod_;
return httpMethod_;
}
CommonRequest::ParameterValueType CommonRequest::queryParameter(const ParameterNameType &name)const
{
ParameterCollection::const_iterator it = queryParams_.find(name);
if (it == queryParams_.end()) {
return ParameterValueType("");
}
return it->second;
ParameterCollection::const_iterator it = queryParams_.find(name);
if (it == queryParams_.end()) {
return ParameterValueType("");
}
return it->second;
}
CommonRequest::ParameterCollection CommonRequest::queryParameters() const
{
return queryParams_;
return queryParams_;
}
void CommonRequest::setQueryParameter(const ParameterNameType &name, const ParameterValueType &value)
{
queryParams_[name] = value;
queryParams_[name] = value;
}
CommonRequest::ParameterValueType CommonRequest::headerParameter(const ParameterNameType &name)const
{
const ParameterCollection::const_iterator it = headerParams_.find(name);
if (it == headerParams_.end()) {
return ParameterValueType("");
}
return it->second;
const ParameterCollection::const_iterator it = headerParams_.find(name);
if (it == headerParams_.end()) {
return ParameterValueType("");
}
return it->second;
}
CommonRequest::ParameterCollection CommonRequest::headerParameters() const
{
return headerParams_;
return headerParams_;
}
void CommonRequest::setHeaderParameter(const ParameterNameType &name, const ParameterValueType &value)
{
headerParams_[name] = value;
headerParams_[name] = value;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,12 +19,12 @@
using namespace AlibabaCloud;
CommonResponse::CommonResponse() :
payload_()
payload_()
{
}
CommonResponse::CommonResponse(const std::string &payload) :
payload_(payload)
payload_(payload)
{
}
@@ -34,5 +34,5 @@ CommonResponse::~CommonResponse()
std::string CommonResponse::payload() const
{
return payload_;
return payload_;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,61 +28,61 @@
using namespace AlibabaCloud;
CoreClient::CoreClient(const std::string & servicename, const ClientConfiguration &configuration) :
serviceName_(servicename),
configuration_(configuration),
httpClient_(new CurlHttpClient)
serviceName_(servicename),
configuration_(configuration),
httpClient_(new CurlHttpClient)
{
httpClient_->setProxy(configuration.proxy());
httpClient_->setProxy(configuration.proxy());
}
CoreClient::~CoreClient()
{
delete httpClient_;
delete httpClient_;
}
ClientConfiguration CoreClient::configuration()const
{
return configuration_;
return configuration_;
}
std::string CoreClient::serviceName()const
{
return serviceName_;
return serviceName_;
}
void CoreClient::asyncExecute(Runnable * r)const
{
Executor::instance()->execute(r);
Executor::instance()->execute(r);
}
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())
return outcome;
if(hasResponseError(outcome.result()))
return HttpClient::HttpResponseOutcome(buildCoreError(outcome.result()));
else
return outcome;
auto r = buildHttpRequest(endpoint, request, method);
auto outcome = httpClient_->makeRequest(r);
if (!outcome.isSuccess())
return outcome;
if(hasResponseError(outcome.result()))
return HttpClient::HttpResponseOutcome(buildCoreError(outcome.result()));
else
return outcome;
}
Error CoreClient::buildCoreError(const HttpResponse &response)const
{
Json::Reader reader;
Json::Value value;
if (!reader.parse(std::string(response.body(), response.bodySize()), value))
return Error("InvalidResponse", "");
Json::Reader reader;
Json::Value value;
if (!reader.parse(std::string(response.body(), response.bodySize()), value))
return Error("InvalidResponse", "");
Error error;
error.setErrorCode(value["Code"].asString());
error.setErrorMessage(value["Message"].asString());
error.setHost(value["HostId"].asString());
error.setRequestId(value["RequestId"].asString());
return error;
Error error;
error.setErrorCode(value["Code"].asString());
error.setErrorMessage(value["Message"].asString());
error.setHost(value["HostId"].asString());
error.setRequestId(value["RequestId"].asString());
return error;
}
bool CoreClient::hasResponseError(const HttpResponse &response)const
{
return response.statusCode() < 200 || response.statusCode() > 299;
}
return response.statusCode() < 200 || response.statusCode() > 299;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,11 +19,11 @@
using namespace AlibabaCloud;
Credentials::Credentials(const std::string &accessKeyId,
const std::string &accessKeySecret,
const std::string &sessionToken) :
accessKeyId_(accessKeyId),
accessKeySecret_(accessKeySecret),
sessionToken_(sessionToken)
const std::string &accessKeySecret,
const std::string &sessionToken) :
accessKeyId_(accessKeyId),
accessKeySecret_(accessKeySecret),
sessionToken_(sessionToken)
{
}
@@ -33,30 +33,30 @@ Credentials::~Credentials()
std::string Credentials::accessKeyId () const
{
return accessKeyId_;
return accessKeyId_;
}
std::string Credentials::accessKeySecret () const
{
return accessKeySecret_;
return accessKeySecret_;
}
void Credentials::setAccessKeyId(const std::string &accessKeyId)
{
accessKeyId_ = accessKeyId;
accessKeyId_ = accessKeyId;
}
void Credentials::setAccessKeySecret(const std::string &accessKeySecret)
{
accessKeySecret_ = accessKeySecret;
accessKeySecret_ = accessKeySecret;
}
void Credentials::setSessionToken (const std::string &sessionToken)
{
sessionToken_ = sessionToken;
sessionToken_ = sessionToken;
}
std::string Credentials::sessionToken () const
{
return sessionToken_;
return sessionToken_;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,124 +23,124 @@ using namespace AlibabaCloud;
namespace
{
size_t recvBody(char *ptr, size_t size, size_t nmemb, void *userdata)
{
std::ostringstream &out = *static_cast<std::ostringstream*>(userdata);
out << std::string(ptr, nmemb*size);
return nmemb * size;
}
size_t recvBody(char *ptr, size_t size, size_t nmemb, void *userdata)
{
std::ostringstream &out = *static_cast<std::ostringstream*>(userdata);
out << std::string(ptr, nmemb*size);
return nmemb * size;
}
size_t recvHeaders(char *buffer, size_t size, size_t nitems, void *userdata)
{
HttpResponse *response = static_cast<HttpResponse*>(userdata);
std::string line(buffer);
auto pos = line.find(':');
if (pos != line.npos)
{
std::string name = line.substr(0, pos);
std::string value = line.substr(pos + 2);
size_t p = 0;
if ((p = value.rfind('\r')) != value.npos)
value[p] = '\0';
response->setHeader(name, value);
}
return nitems * size;
}
size_t recvHeaders(char *buffer, size_t size, size_t nitems, void *userdata)
{
HttpResponse *response = static_cast<HttpResponse*>(userdata);
std::string line(buffer);
auto pos = line.find(':');
if (pos != line.npos)
{
std::string name = line.substr(0, pos);
std::string value = line.substr(pos + 2);
size_t p = 0;
if ((p = value.rfind('\r')) != value.npos)
value[p] = '\0';
response->setHeader(name, value);
}
return nitems * size;
}
void setCUrlProxy(CURL *curlHandle, const NetworkProxy &proxy)
{
if (proxy.type() == NetworkProxy::Type::None)
return;
void setCUrlProxy(CURL *curlHandle, const NetworkProxy &proxy)
{
if (proxy.type() == NetworkProxy::Type::None)
return;
long type;
switch (proxy.type())
{
case NetworkProxy::Type::Socks5:
type = CURLPROXY_SOCKS5;
break;
case NetworkProxy::Type::Http:
default:
type = CURLPROXY_HTTP;
break;
}
curl_easy_setopt(curlHandle, CURLOPT_PROXYTYPE, type);
long type;
switch (proxy.type())
{
case NetworkProxy::Type::Socks5:
type = CURLPROXY_SOCKS5;
break;
case NetworkProxy::Type::Http:
default:
type = CURLPROXY_HTTP;
break;
}
curl_easy_setopt(curlHandle, CURLOPT_PROXYTYPE, type);
std::ostringstream out;
out << proxy.hostName() << ":" << proxy.port();
curl_easy_setopt(curlHandle, CURLOPT_PROXY, out.str().c_str());
std::ostringstream out;
out << proxy.hostName() << ":" << proxy.port();
curl_easy_setopt(curlHandle, CURLOPT_PROXY, out.str().c_str());
if (!proxy.user().empty()) {
out.clear();
out << proxy.user() << ":" << proxy.password();
curl_easy_setopt(curlHandle, CURLOPT_PROXYUSERPWD, out.str().c_str());
}
}
if (!proxy.user().empty()) {
out.clear();
out << proxy.user() << ":" << proxy.password();
curl_easy_setopt(curlHandle, CURLOPT_PROXYUSERPWD, out.str().c_str());
}
}
}
CurlHttpClient::CurlHttpClient() :
HttpClient(),
curlHandle_(curl_easy_init())
HttpClient(),
curlHandle_(curl_easy_init())
{
}
CurlHttpClient::~CurlHttpClient()
{
curl_easy_cleanup(curlHandle_);
curl_easy_cleanup(curlHandle_);
}
HttpClient::HttpResponseOutcome CurlHttpClient::makeRequest(const HttpRequest &request)
{
curl_easy_reset(curlHandle_);
HttpResponse response(request);
curl_easy_reset(curlHandle_);
HttpResponse response(request);
std::string url = request.url().toString();
switch (request.method())
{
case HttpRequest::Method::Get:
break;
case HttpRequest::Method::Post:
curl_easy_setopt(curlHandle_, CURLOPT_POSTFIELDS, request.body());
break;
case HttpRequest::Method::Put:
curl_easy_setopt(curlHandle_, CURLOPT_UPLOAD, 1L);
break;
default:
break;
}
std::string url = request.url().toString();
switch (request.method())
{
case HttpRequest::Method::Get:
break;
case HttpRequest::Method::Post:
curl_easy_setopt(curlHandle_, CURLOPT_POSTFIELDS, request.body());
break;
case HttpRequest::Method::Put:
curl_easy_setopt(curlHandle_, CURLOPT_UPLOAD, 1L);
break;
default:
break;
}
curl_easy_setopt(curlHandle_, CURLOPT_URL, url.c_str());
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_setopt(curlHandle_, CURLOPT_HEADERDATA, &response);
curl_easy_setopt(curlHandle_, CURLOPT_HEADERFUNCTION, recvHeaders);
curl_easy_setopt(curlHandle_, CURLOPT_URL, url.c_str());
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_setopt(curlHandle_, CURLOPT_HEADERDATA, &response);
curl_easy_setopt(curlHandle_, CURLOPT_HEADERFUNCTION, recvHeaders);
curl_slist *list = nullptr;
auto headers = request.headers();
for (const auto &p : headers)
{
std::string str = p.first;
str.append(": ").append(p.second);
list = curl_slist_append(list, str.c_str());
}
curl_easy_setopt(curlHandle_, CURLOPT_HTTPHEADER, list);
std::ostringstream out;
curl_easy_setopt(curlHandle_, CURLOPT_WRITEDATA, &out);
curl_easy_setopt(curlHandle_, CURLOPT_WRITEFUNCTION, recvBody);
setCUrlProxy(curlHandle_, proxy());
curl_slist *list = nullptr;
auto headers = request.headers();
for (const auto &p : headers)
{
std::string str = p.first;
str.append(": ").append(p.second);
list = curl_slist_append(list, str.c_str());
}
curl_easy_setopt(curlHandle_, CURLOPT_HTTPHEADER, list);
std::ostringstream out;
curl_easy_setopt(curlHandle_, CURLOPT_WRITEDATA, &out);
curl_easy_setopt(curlHandle_, CURLOPT_WRITEFUNCTION, recvBody);
setCUrlProxy(curlHandle_, proxy());
CURLcode res = curl_easy_perform(curlHandle_);
switch (res)
{
case CURLE_OK: {
long response_code;
curl_easy_getinfo(curlHandle_, CURLINFO_RESPONSE_CODE, &response_code);
response.setStatusCode(response_code);
response.setBody(out.str().c_str(), out.str().length());
return HttpResponseOutcome(response);
}
case CURLE_SSL_CONNECT_ERROR:
return HttpResponseOutcome(Error("SSLConnectError", "A problem occurred somewhere in the SSL/TLS handshake."));
default:
return HttpResponseOutcome(Error("NetworkError", "Failed to connect to host or proxy."));
}
CURLcode res = curl_easy_perform(curlHandle_);
switch (res)
{
case CURLE_OK: {
long response_code;
curl_easy_getinfo(curlHandle_, CURLINFO_RESPONSE_CODE, &response_code);
response.setStatusCode(response_code);
response.setBody(out.str().c_str(), out.str().length());
return HttpResponseOutcome(response);
}
case CURLE_SSL_CONNECT_ERROR:
return HttpResponseOutcome(Error("SSLConnectError", "A problem occurred somewhere in the SSL/TLS handshake."));
default:
return HttpResponseOutcome(Error("NetworkError", "Failed to connect to host or proxy."));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,16 +22,16 @@
namespace AlibabaCloud
{
class CurlHttpClient : public HttpClient
{
public:
CurlHttpClient();
~CurlHttpClient();
class CurlHttpClient : public HttpClient
{
public:
CurlHttpClient();
~CurlHttpClient();
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) override;
private:
CURL *curlHandle_;
};
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) override;
private:
CURL *curlHandle_;
};
}
#endif // !ALIBABACLOUD_CORE_CURLHTTPCLIENT_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,35 +32,35 @@ EcsMetadataFetcher::~EcsMetadataFetcher()
std::string EcsMetadataFetcher::roleName()const
{
return roleName_;
return roleName_;
}
void EcsMetadataFetcher::setRoleName(const std::string & roleName)
{
roleName_ = roleName;
roleName_ = roleName;
}
std::string EcsMetadataFetcher::getMetadata() {
return getMetadata(METADATA_SERVICE_HOST, URL_IN_ECS_METADATA);
return getMetadata(METADATA_SERVICE_HOST, URL_IN_ECS_METADATA);
}
std::string EcsMetadataFetcher::getMetadata(const std::string host, const std::string in_path)
{
std::stringstream path;
path << in_path << roleName_;
std::stringstream path;
path << in_path << roleName_;
Url credentialUrl;
credentialUrl.setHost(host);
credentialUrl.setPath(path.str());
Url credentialUrl;
credentialUrl.setHost(host);
credentialUrl.setPath(path.str());
auto client = std::make_shared<CurlHttpClient>();
auto client = std::make_shared<CurlHttpClient>();
HttpRequest request;
request.setUrl(credentialUrl);
auto outcome = client->makeRequest(request);
HttpRequest request;
request.setUrl(credentialUrl);
auto outcome = client->makeRequest(request);
if (outcome.isSuccess())
return std::string(outcome.result().body(), outcome.result().bodySize());
else
return outcome.error().errorCode();
}
if (outcome.isSuccess())
return std::string(outcome.result().body(), outcome.result().bodySize());
else
return outcome.error().errorCode();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,26 +20,26 @@
#include <string>
namespace {
const int DEFAULT_TIMEOUT_IN_MILLISECONDS = 5000;
const char* const METADATA_SERVICE_HOST = "100.100.100.200";
const char* const URL_IN_ECS_METADATA = "/latest/meta-data/ram/security-credentials/";
const int DEFAULT_TIMEOUT_IN_MILLISECONDS = 5000;
const char* const METADATA_SERVICE_HOST = "100.100.100.200";
const char* const URL_IN_ECS_METADATA = "/latest/meta-data/ram/security-credentials/";
}
namespace AlibabaCloud
{
class EcsMetadataFetcher
{
public:
EcsMetadataFetcher();
~EcsMetadataFetcher();
class EcsMetadataFetcher
{
public:
EcsMetadataFetcher();
~EcsMetadataFetcher();
std::string roleName()const;
void setRoleName(const std::string & roleName);
std::string getMetadata(const std::string host, const std::string path);
virtual std::string getMetadata();
private:
std::string roleName_;
};
std::string roleName()const;
void setRoleName(const std::string & roleName);
std::string getMetadata(const std::string host, const std::string path);
virtual std::string getMetadata();
private:
std::string roleName_;
};
}
#endif // !ALIBABACLOUD_CORE_ECSMETADATASERVICECREDENTIALSFETCHER_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,96 +25,96 @@ using namespace AlibabaCloud::Location;
namespace
{
#if defined(WIN32) && defined(_MSC_VER)
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
#else
# include <strings.h>
# include <strings.h>
#endif
const std::string INTERNAL_ENDPOINTS_DATA = "{\"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\":\"\"}"
"]}";
const std::string INTERNAL_ENDPOINTS_DATA = "{\"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_(),
internalProductsInfo_()
LocationClient(locationClient),
regionId_(regionId),
product_(product),
serviceCode_(serviceCode),
durationSeconds_(durationSeconds),
cachedMutex_(),
cachedEndpoint_(),
expiry_(),
internalProductsInfo_()
{
loadInternalProductsInfo();
loadInternalProductsInfo();
}
EndpointProvider::EndpointProvider(
const Credentials& credentials,
const ClientConfiguration &configuration,
const std::string &regionId,
const std::string &product,
const std::string &serviceCode,
int durationSeconds) :
LocationClient(credentials, configuration),
regionId_(regionId),
product_(product),
serviceCode_(serviceCode),
durationSeconds_(durationSeconds),
cachedMutex_(),
cachedEndpoint_(),
expiry_(),
internalProductsInfo_()
const Credentials& credentials,
const ClientConfiguration &configuration,
const std::string &regionId,
const std::string &product,
const std::string &serviceCode,
int durationSeconds) :
LocationClient(credentials, configuration),
regionId_(regionId),
product_(product),
serviceCode_(serviceCode),
durationSeconds_(durationSeconds),
cachedMutex_(),
cachedEndpoint_(),
expiry_(),
internalProductsInfo_()
{
loadInternalProductsInfo();
loadInternalProductsInfo();
}
EndpointProvider::~EndpointProvider()
@@ -123,104 +123,104 @@ EndpointProvider::~EndpointProvider()
bool EndpointProvider::loadInternalProductsInfo()
{
Json::Reader reader;
Json::Value value;
if (!reader.parse(INTERNAL_ENDPOINTS_DATA, value))
return false;
Json::Reader reader;
Json::Value value;
if (!reader.parse(INTERNAL_ENDPOINTS_DATA, 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 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;
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();
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
auto now = std::chrono::system_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
return (diff > 0 - 60);
return (diff > 0 - 60);
}
std::string EndpointProvider::internalEndpoint(const std::string regionId, const std::string product)
{
for (Product p : internalProductsInfo_)
{
if (strcasecmp(p.code.c_str(), product.c_str()) != 0)
continue;
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;
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();
return e.second;
}
return p.globalEndpoint;
}
return std::string();
}
EndpointProvider::EndpointOutcome EndpointProvider::getEndpoint()
{
if (!configuration().endpoint().empty())
return EndpointOutcome(configuration().endpoint());
if (!configuration().endpoint().empty())
return EndpointOutcome(configuration().endpoint());
if (!serviceCode_.empty())
{
EndpointOutcome outcome = loadRemoteEndpoint();
if (outcome.isSuccess())
return outcome;
if (outcome.error().errorCode() != "InvalidRegionId"
&& outcome.error().errorCode() != "Illegal Parameter")
return outcome;
}
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);
std::string endpoint = internalEndpoint(regionId_, product_);
if (!endpoint.empty())
return EndpointOutcome(endpoint);
return EndpointOutcome(Error("InvalidRegionId", "The specified region does not exist."));
return EndpointOutcome(Error("InvalidRegionId", "The specified region does not exist."));
}
EndpointProvider::EndpointOutcome EndpointProvider::loadRemoteEndpoint()
{
if (checkExpiry())
{
std::lock_guard<std::mutex> locker(cachedMutex_);
if (checkExpiry())
{
Model::DescribeEndpointsRequest request;
request.setId(regionId_);
request.setServiceCode(serviceCode_);
request.setType("openAPI");
auto outcome = describeEndpoints(request);
if (!outcome.isSuccess())
return EndpointOutcome(outcome.error());
if (checkExpiry())
{
std::lock_guard<std::mutex> locker(cachedMutex_);
if (checkExpiry())
{
Model::DescribeEndpointsRequest request;
request.setId(regionId_);
request.setServiceCode(serviceCode_);
request.setType("openAPI");
auto outcome = describeEndpoints(request);
if (!outcome.isSuccess())
return EndpointOutcome(outcome.error());
auto all = outcome.result().endpoints();
if (all.size() > 0)
cachedEndpoint_ = all.front().endpoint;
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);
}
}
std::time_t t = std::time(nullptr) + durationSeconds_;
expiry_ = std::chrono::system_clock::from_time_t(t);
}
}
return EndpointOutcome(cachedEndpoint_);
}
return EndpointOutcome(cachedEndpoint_);
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,10 +19,10 @@
using namespace AlibabaCloud;
Error::Error(std::string code, const std::string message) :
errorCode_(code),
message_(message),
host_(),
requestId_()
errorCode_(code),
message_(message),
host_(),
requestId_()
{
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,103 +22,103 @@ using namespace AlibabaCloud;
Executor *Executor::self_ = nullptr;
Executor::Executor() :
cvMutex_(),
shutdown_(true),
tasksQueue_(),
tasksQueueMutex_(),
thread_()
cvMutex_(),
shutdown_(true),
tasksQueue_(),
tasksQueueMutex_(),
thread_()
{
self_ = this;
self_ = this;
}
Executor::~Executor()
{
self_ = nullptr;
shutdown();
self_ = nullptr;
shutdown();
}
Executor * Executor::instance()
{
return self_;
return self_;
}
bool Executor::start()
{
if (!isShutdown())
return true;
if (!isShutdown())
return true;
auto threadMain = [this]()
{
while (!shutdown_)
{
while (!tasksQueue_.empty())
{
Runnable *task = nullptr;
{
std::lock_guard<std::mutex> lock(tasksQueueMutex_);
if (!tasksQueue_.empty())
{
task = tasksQueue_.front();
tasksQueue_.pop();
}
}
auto threadMain = [this]()
{
while (!shutdown_)
{
while (!tasksQueue_.empty())
{
Runnable *task = nullptr;
{
std::lock_guard<std::mutex> lock(tasksQueueMutex_);
if (!tasksQueue_.empty())
{
task = tasksQueue_.front();
tasksQueue_.pop();
}
}
if (task) {
task->run();
delete task;
}
}
if (task) {
task->run();
delete task;
}
}
if (!shutdown_) {
std::unique_lock<std::mutex> lk(cvMutex_);
cv_.wait(lk);
}
}
};
if (!shutdown_) {
std::unique_lock<std::mutex> lk(cvMutex_);
cv_.wait(lk);
}
}
};
shutdown_ = false;
thread_ = std::thread(threadMain);
return true;
shutdown_ = false;
thread_ = std::thread(threadMain);
return true;
}
bool Executor::isShutdown()const
{
return shutdown_;
return shutdown_;
}
void Executor::execute(Runnable* task)
{
if (isShutdown())
return;
if (isShutdown())
return;
std::lock_guard<std::mutex> locker(tasksQueueMutex_);
tasksQueue_.push(task);
wakeUp();
std::lock_guard<std::mutex> locker(tasksQueueMutex_);
tasksQueue_.push(task);
wakeUp();
}
void Executor::wakeUp()
{
std::unique_lock<std::mutex> lk(cvMutex_);
cv_.notify_one();
std::unique_lock<std::mutex> lk(cvMutex_);
cv_.notify_one();
}
void Executor::shutdown()
{
if (isShutdown())
return;
if (isShutdown())
return;
{
std::lock_guard<std::mutex> locker(tasksQueueMutex_);
while (tasksQueue_.size() > 0) {
auto task = tasksQueue_.front();
delete task;
tasksQueue_.pop();
}
}
{
std::lock_guard<std::mutex> locker(tasksQueueMutex_);
while (tasksQueue_.size() > 0) {
auto task = tasksQueue_.front();
delete task;
tasksQueue_.pop();
}
}
shutdown_ = true;
wakeUp();
shutdown_ = true;
wakeUp();
if (thread_.joinable())
thread_.join();
}
if (thread_.joinable())
thread_.join();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,28 +26,28 @@
namespace AlibabaCloud
{
class Runnable;
class Executor
{
public:
Executor();
~Executor();
static Executor * instance();
void execute(Runnable* task);
bool isShutdown()const;
bool start();
void shutdown();
void wakeUp();
private:
static Executor *self_;
std::atomic<bool> shutdown_;
std::queue<Runnable*> tasksQueue_;
std::mutex tasksQueueMutex_;
std::thread thread_;
std::condition_variable cv_;
std::mutex cvMutex_;
};
class Runnable;
class Executor
{
public:
Executor();
~Executor();
static Executor * instance();
void execute(Runnable* task);
bool isShutdown()const;
bool start();
void shutdown();
void wakeUp();
private:
static Executor *self_;
std::atomic<bool> shutdown_;
std::queue<Runnable*> tasksQueue_;
std::mutex tasksQueueMutex_;
std::thread thread_;
std::condition_variable cv_;
std::mutex cvMutex_;
};
}
#endif // !ALIBABACLOUD_CORE_EXECUTOR_H_

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
using namespace AlibabaCloud;
HmacSha1Signer::HmacSha1Signer() :
Signer(HmacSha1, "HMAC-SHA1", "1.0")
Signer(HmacSha1, "HMAC-SHA1", "1.0")
{
}
@@ -35,65 +35,65 @@ HmacSha1Signer::~HmacSha1Signer()
std::string HmacSha1Signer::generate(const std::string & src, const std::string & secret) const
{
if (src.empty())
return std::string();
if (src.empty())
return std::string();
#ifdef _WIN32
typedef struct _my_blob {
BLOBHEADER hdr;
DWORD dwKeySize;
BYTE rgbKeyData[];
}my_blob;
typedef struct _my_blob {
BLOBHEADER hdr;
DWORD dwKeySize;
BYTE rgbKeyData[];
}my_blob;
DWORD kbLen = sizeof(my_blob) + secret.size();
my_blob * kb = (my_blob *)LocalAlloc(LPTR, kbLen);
kb->hdr.bType = PLAINTEXTKEYBLOB;
kb->hdr.bVersion = CUR_BLOB_VERSION;
kb->hdr.reserved = 0;
kb->hdr.aiKeyAlg = CALG_RC2;
kb->dwKeySize = secret.size();
memcpy(&kb->rgbKeyData, secret.c_str(), secret.size());
DWORD kbLen = sizeof(my_blob) + secret.size();
my_blob * kb = (my_blob *)LocalAlloc(LPTR, kbLen);
kb->hdr.bType = PLAINTEXTKEYBLOB;
kb->hdr.bVersion = CUR_BLOB_VERSION;
kb->hdr.reserved = 0;
kb->hdr.aiKeyAlg = CALG_RC2;
kb->dwKeySize = secret.size();
memcpy(&kb->rgbKeyData, secret.c_str(), secret.size());
HCRYPTPROV hProv = 0;
HCRYPTKEY hKey = 0;
HCRYPTHASH hHmacHash = 0;
BYTE pbHash[32];
DWORD dwDataLen = 32;
HMAC_INFO HmacInfo;
ZeroMemory(&HmacInfo, sizeof(HmacInfo));
HmacInfo.HashAlgid = CALG_SHA1;
HCRYPTPROV hProv = 0;
HCRYPTKEY hKey = 0;
HCRYPTHASH hHmacHash = 0;
BYTE pbHash[32];
DWORD dwDataLen = 32;
HMAC_INFO HmacInfo;
ZeroMemory(&HmacInfo, sizeof(HmacInfo));
HmacInfo.HashAlgid = CALG_SHA1;
CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET);
CryptImportKey(hProv, (BYTE*)kb, kbLen, 0, CRYPT_IPSEC_HMAC_KEY, &hKey);
CryptCreateHash(hProv, CALG_HMAC, hKey, 0, &hHmacHash);
CryptSetHashParam(hHmacHash, HP_HMAC_INFO, (BYTE*)&HmacInfo, 0);
CryptHashData(hHmacHash, (BYTE*)(src.c_str()), src.size(), 0);
CryptGetHashParam(hHmacHash, HP_HASHVAL, pbHash, &dwDataLen, 0);
CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET);
CryptImportKey(hProv, (BYTE*)kb, kbLen, 0, CRYPT_IPSEC_HMAC_KEY, &hKey);
CryptCreateHash(hProv, CALG_HMAC, hKey, 0, &hHmacHash);
CryptSetHashParam(hHmacHash, HP_HMAC_INFO, (BYTE*)&HmacInfo, 0);
CryptHashData(hHmacHash, (BYTE*)(src.c_str()), src.size(), 0);
CryptGetHashParam(hHmacHash, HP_HASHVAL, pbHash, &dwDataLen, 0);
LocalFree(kb);
CryptDestroyHash(hHmacHash);
CryptDestroyKey(hKey);
CryptReleaseContext(hProv, 0);
LocalFree(kb);
CryptDestroyHash(hHmacHash);
CryptDestroyKey(hKey);
CryptReleaseContext(hProv, 0);
DWORD dlen = 0;
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);
DWORD dlen = 0;
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);
std::string ret = std::string(dest, dlen);
delete dest;
return ret;
std::string ret = std::string(dest, dlen);
delete dest;
return ret;
#else
unsigned char md[EVP_MAX_BLOCK_LENGTH];
unsigned int mdLen = EVP_MAX_BLOCK_LENGTH;
unsigned char md[EVP_MAX_BLOCK_LENGTH];
unsigned int mdLen = EVP_MAX_BLOCK_LENGTH;
if (HMAC(EVP_sha1(), secret.c_str(), secret.size(),
reinterpret_cast<const unsigned char*>(src.c_str()), src.size(),
md, &mdLen) == nullptr)
return std::string();
if (HMAC(EVP_sha1(), secret.c_str(), secret.size(),
reinterpret_cast<const unsigned char*>(src.c_str()), src.size(),
md, &mdLen) == nullptr)
return std::string();
char encodedData[100];
EVP_EncodeBlock(reinterpret_cast<unsigned char*>(encodedData), md, mdLen);
return encodedData;
char encodedData[100];
EVP_EncodeBlock(reinterpret_cast<unsigned char*>(encodedData), md, mdLen);
return encodedData;
#endif
}
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,7 +22,7 @@
using namespace AlibabaCloud;
HttpClient::HttpClient() :
proxy_()
proxy_()
{
}
@@ -32,10 +32,10 @@ HttpClient::~HttpClient()
NetworkProxy HttpClient::proxy()const
{
return proxy_;
return proxy_;
}
void HttpClient::setProxy(const NetworkProxy &proxy)
{
proxy_ = proxy;
}
proxy_ = proxy;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,153 +22,153 @@ using namespace AlibabaCloud;
namespace
{
#if defined(WIN32) && defined(_MSC_VER)
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
#else
# include <strings.h>
# include <strings.h>
#endif
std::string KnownHeaderMapper[]
{
"Accept",
"Accept-Charset",
"Accept-Encoding",
"Accept-Language",
"Authorization",
"Connection",
"Content-Length",
"Content-MD5",
"Content-Type",
"Date",
"Host",
"Server",
"User-Agent"
};
std::string KnownHeaderMapper[]
{
"Accept",
"Accept-Charset",
"Accept-Encoding",
"Accept-Language",
"Authorization",
"Connection",
"Content-Length",
"Content-MD5",
"Content-Type",
"Date",
"Host",
"Server",
"User-Agent"
};
}
HttpMessage::HttpMessage() :
body_(nullptr),
bodySize_(0),
headers_()
body_(nullptr),
bodySize_(0),
headers_()
{
}
HttpMessage::HttpMessage(const HttpMessage &other) :
body_(nullptr),
bodySize_(other.bodySize_),
headers_(other.headers_)
body_(nullptr),
bodySize_(other.bodySize_),
headers_(other.headers_)
{
setBody(other.body_, other.bodySize_);
setBody(other.body_, other.bodySize_);
}
HttpMessage::HttpMessage(HttpMessage &&other)
{
*this = std::move(other);
*this = std::move(other);
}
HttpMessage& HttpMessage::operator=(const HttpMessage &other)
{
if (this != &other) {
body_ = nullptr;
bodySize_ = 0;
headers_ = other.headers_;
setBody(other.body_, other.bodySize_);
}
return *this;
if (this != &other) {
body_ = nullptr;
bodySize_ = 0;
headers_ = other.headers_;
setBody(other.body_, other.bodySize_);
}
return *this;
}
HttpMessage& HttpMessage::operator=(HttpMessage &&other)
{
if (this != &other)
*this = std::move(other);
return *this;
if (this != &other)
*this = std::move(other);
return *this;
}
void HttpMessage::addHeader(const HeaderNameType & name, const HeaderValueType & value)
{
setHeader(name, value);
setHeader(name, value);
}
void HttpMessage::addHeader(KnownHeader header, const HeaderValueType & value)
{
setHeader(header, value);
setHeader(header, value);
}
HttpMessage::HeaderValueType HttpMessage::header(const HeaderNameType & name) const
{
auto it = headers_.find(name);
if (it != headers_.end())
return it->second;
else
return std::string();
auto it = headers_.find(name);
if (it != headers_.end())
return it->second;
else
return std::string();
}
HttpMessage::HeaderCollection HttpMessage::headers() const
{
return headers_;
return headers_;
}
void HttpMessage::removeHeader(const HeaderNameType & name)
{
headers_.erase(name);
headers_.erase(name);
}
void HttpMessage::removeHeader(KnownHeader header)
{
removeHeader(KnownHeaderMapper[header]);
removeHeader(KnownHeaderMapper[header]);
}
void HttpMessage::setHeader(const HeaderNameType & name, const HeaderValueType & value)
{
headers_[name] = value;
headers_[name] = value;
}
void HttpMessage::setHeader(KnownHeader header, const std::string & value)
{
setHeader(KnownHeaderMapper[header], value);
setHeader(KnownHeaderMapper[header], value);
}
HttpMessage::~HttpMessage()
{
setBody(nullptr, 0);
setBody(nullptr, 0);
}
const char* HttpMessage::body()const
{
return body_;
return body_;
}
size_t HttpMessage::bodySize()const
{
return bodySize_;
return bodySize_;
}
bool HttpMessage::hasBody() const
{
return (bodySize_ != 0);
return (bodySize_ != 0);
}
HttpMessage::HeaderValueType HttpMessage::header(KnownHeader header)const
{
return this->header(KnownHeaderMapper[header]);
return this->header(KnownHeaderMapper[header]);
}
void HttpMessage::setBody(const char *data, size_t size)
{
if (body_)
delete body_;
body_ = nullptr;
bodySize_ = 0;
if (size) {
bodySize_ = size;
body_ = new char[size + 1];
std::copy(data, data + size, body_);
body_[size] = '\0';
}
if (body_)
delete body_;
body_ = nullptr;
bodySize_ = 0;
if (size) {
bodySize_ = size;
body_ = new char[size + 1];
std::copy(data, data + size, body_);
body_[size] = '\0';
}
}
bool HttpMessage::nocaseLess::operator()(const std::string & s1,
const std::string & s2) const
const std::string & s2) const
{
return strcasecmp(s1.c_str(), s2.c_str()) < 0;
return strcasecmp(s1.c_str(), s2.c_str()) < 0;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,9 @@
using namespace AlibabaCloud;
HttpRequest::HttpRequest(const Url &url, Method method) :
HttpMessage(),
url_(url),
method_(method)
HttpMessage(),
url_(url),
method_(method)
{
}
@@ -31,21 +31,21 @@ HttpRequest::~HttpRequest()
HttpRequest::Method HttpRequest::method() const
{
return method_;
return method_;
}
void HttpRequest::setMethod(Method method)
{
method_ = method;
method_ = method;
}
void HttpRequest::setUrl(const Url &url)
{
url_ = url;
url_ = url;
}
Url HttpRequest::url()const
{
return url_;
return url_;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,22 +18,22 @@
namespace
{
#define INVALID_STATUS_CODE -1
#define INVALID_STATUS_CODE -1
}
using namespace AlibabaCloud;
HttpResponse::HttpResponse() :
HttpMessage(),
request_(),
statusCode_(INVALID_STATUS_CODE)
HttpMessage(),
request_(),
statusCode_(INVALID_STATUS_CODE)
{
}
HttpResponse::HttpResponse(const HttpRequest & request) :
HttpMessage(),
request_(request),
statusCode_(INVALID_STATUS_CODE)
HttpMessage(),
request_(request),
statusCode_(INVALID_STATUS_CODE)
{
}
@@ -43,15 +43,15 @@ HttpResponse::~HttpResponse()
HttpRequest HttpResponse::request() const
{
return request_;
return request_;
}
void HttpResponse::setStatusCode(int code)
{
statusCode_ = code;
statusCode_ = code;
}
int HttpResponse::statusCode() const
{
return statusCode_;
return statusCode_;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,10 +19,10 @@
using namespace AlibabaCloud;
InstanceProfileCredentials::InstanceProfileCredentials() :
BasicSessionCredentials(Credentials::InstanceProfile)
BasicSessionCredentials(Credentials::InstanceProfile)
{
}
InstanceProfileCredentials::~InstanceProfileCredentials()
{
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,14 +26,14 @@
using namespace AlibabaCloud;
InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(const std::string & roleName, int durationSeconds):
CredentialsProvider(),
EcsMetadataFetcher(),
durationSeconds_(durationSeconds),
cachedMutex_(),
cachedCredentials_("", ""),
expiry_()
CredentialsProvider(),
EcsMetadataFetcher(),
durationSeconds_(durationSeconds),
cachedMutex_(),
cachedCredentials_("", ""),
expiry_()
{
setRoleName(roleName);
setRoleName(roleName);
}
InstanceProfileCredentialsProvider::~InstanceProfileCredentialsProvider()
@@ -42,60 +42,60 @@ InstanceProfileCredentialsProvider::~InstanceProfileCredentialsProvider()
Credentials InstanceProfileCredentialsProvider::getCredentials()
{
loadCredentials();
std::lock_guard<std::mutex> locker(cachedMutex_);
return cachedCredentials_;
loadCredentials();
std::lock_guard<std::mutex> locker(cachedMutex_);
return cachedCredentials_;
}
bool InstanceProfileCredentialsProvider::checkExpiry()const
{
auto now = std::chrono::system_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
auto now = std::chrono::system_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
return (diff > 0 - 60);
return (diff > 0 - 60);
}
void InstanceProfileCredentialsProvider::loadCredentials()
{
if (checkExpiry())
{
std::lock_guard<std::mutex> locker(cachedMutex_);
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())
{
cachedCredentials_ = Credentials("","");
return;
}
if (checkExpiry())
{
std::lock_guard<std::mutex> locker(cachedMutex_);
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())
{
cachedCredentials_ = Credentials("","");
return;
}
auto code = value["Code"].asString();
auto accessKeyId = value["AccessKeyId"].asString();
auto accessKeySecret = value["AccessKeySecret"].asString();
auto securityToken = value["SecurityToken"].asString();
auto expiration = value["Expiration"].asString();
auto code = value["Code"].asString();
auto accessKeyId = value["AccessKeyId"].asString();
auto accessKeySecret = value["AccessKeySecret"].asString();
auto securityToken = value["SecurityToken"].asString();
auto expiration = value["Expiration"].asString();
cachedCredentials_ = Credentials(accessKeyId,
accessKeySecret,
securityToken);
cachedCredentials_ = Credentials(accessKeyId,
accessKeySecret,
securityToken);
std::tm tm = {};
std::tm tm = {};
#if defined(__GNUG__) && __GNUC__ < 5
strptime(expiration.c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm);
strptime(expiration.c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm);
#else
std::stringstream ss(expiration);
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
std::stringstream ss(expiration);
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
#endif
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
}
}
}
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
}
}
}
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,15 +19,15 @@
using namespace AlibabaCloud;
NetworkProxy::NetworkProxy(Type type,
const std::string &hostName,
uint16_t port,
const std::string &user,
const std::string &password)
const std::string &hostName,
uint16_t port,
const std::string &user,
const std::string &password)
: hostName_(hostName),
password_(password),
port_(port),
type_(type),
user_(user)
password_(password),
port_(port),
type_(type),
user_(user)
{
}
@@ -37,50 +37,50 @@ NetworkProxy::~NetworkProxy()
std::string NetworkProxy::hostName() const
{
return hostName_;
return hostName_;
}
std::string NetworkProxy::password() const
{
return password_;
return password_;
}
uint16_t NetworkProxy::port() const
{
return port_;
return port_;
}
void NetworkProxy::setHostName(const std::string &hostName)
{
hostName_ = hostName;
hostName_ = hostName;
}
void NetworkProxy::setPassword(const std::string &password)
{
password_ = password;
password_ = password;
}
void NetworkProxy::setPort(uint16_t port)
{
port_ = port;
port_ = port;
}
void NetworkProxy::setType(NetworkProxy::Type type)
{
type_ = type;
type_ = type;
}
void NetworkProxy::setUser(const std::string &user)
{
user_ = user;
user_ = user;
}
NetworkProxy::Type NetworkProxy::type() const
{
return type_;
return type_;
}
std::string NetworkProxy::user() const
{
return user_;
return user_;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -14,4 +14,4 @@
* limitations under the License.
*/
#include <alibabacloud/core/Outcome.h>
#include <alibabacloud/core/Outcome.h>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,11 +25,11 @@
using namespace AlibabaCloud;
RoaServiceClient::RoaServiceClient(const std::string & servicename, const std::shared_ptr<CredentialsProvider> &credentialsProvider,
const ClientConfiguration &configuration,
const std::shared_ptr<Signer> &signer) :
CoreClient(servicename, configuration),
credentialsProvider_(credentialsProvider),
signer_(signer)
const ClientConfiguration &configuration,
const std::shared_ptr<Signer> &signer) :
CoreClient(servicename, configuration),
credentialsProvider_(credentialsProvider),
signer_(signer)
{
}
@@ -39,156 +39,156 @@ RoaServiceClient::~RoaServiceClient()
std::string RoaServiceClient::canonicalizedResource(const std::string &path, std::map <std::string, std::string> &params)const
{
if (params.empty())
return path;
if (params.empty())
return path;
std::stringstream ss;
for (const auto &p : params)
{
if (p.second.empty())
ss << "&" << p.first;
else
ss << "&" << p.first << "=" << p.second;
}
std::stringstream ss;
for (const auto &p : params)
{
if (p.second.empty())
ss << "&" << p.first;
else
ss << "&" << p.first << "=" << p.second;
}
std::string str = path;
str.append("?").append(ss.str().substr(1));
return str;
std::string str = path;
str.append("?").append(ss.str().substr(1));
return str;
}
std::string RoaServiceClient::canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const
{
std::map <std::string, std::string> materials;
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)
continue;
std::map <std::string, std::string> materials;
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)
continue;
std::string value = p.second;
StringReplace(value, "\t", " ");
StringReplace(value, "\n", " ");
StringReplace(value, "\r", " ");
StringReplace(value, "\f", " ");
materials[key] = value;
}
std::string value = p.second;
StringReplace(value, "\t", " ");
StringReplace(value, "\n", " ");
StringReplace(value, "\r", " ");
StringReplace(value, "\f", " ");
materials[key] = value;
}
if (materials.empty())
return std::string();
std::stringstream ss;
for (const auto &p : materials)
ss << p.first << ":" << p.second << "\n";
if (materials.empty())
return std::string();
std::stringstream ss;
for (const auto &p : materials)
ss << p.first << ":" << p.second << "\n";
return ss.str();
return ss.str();
}
RoaServiceClient::JsonOutcome RoaServiceClient::makeRequest(const std::string &endpoint, const RoaServiceRequest &msg, HttpRequest::Method method)const
{
auto outcome = AttemptRequest(endpoint, msg, method);
if (outcome.isSuccess())
return JsonOutcome(std::string(outcome.result().body(),
outcome.result().bodySize()));
else
return JsonOutcome(outcome.error());
auto outcome = AttemptRequest(endpoint, msg, method);
if (outcome.isSuccess())
return JsonOutcome(std::string(outcome.result().body(),
outcome.result().bodySize()));
else
return JsonOutcome(outcome.error());
}
HttpRequest RoaServiceClient::buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const
{
return buildHttpRequest(endpoint, dynamic_cast<const RoaServiceRequest& >(msg), method);
return buildHttpRequest(endpoint, dynamic_cast<const RoaServiceRequest& >(msg), method);
}
HttpRequest RoaServiceClient::buildHttpRequest(const std::string & endpoint, const RoaServiceRequest &msg, HttpRequest::Method method) const
{
const Credentials credentials = credentialsProvider_->getCredentials();
const Credentials credentials = credentialsProvider_->getCredentials();
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
url.setHost(endpoint);
url.setPath(msg.resourcePath());
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
url.setHost(endpoint);
url.setPath(msg.resourcePath());
auto params = msg.parameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params){
if (!p.second.empty())
queryParams[p.first] = p.second;
}
auto params = msg.parameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params){
if (!p.second.empty())
queryParams[p.first] = p.second;
}
if (!queryParams.empty()) {
std::stringstream queryString;
for (const auto &p : queryParams)
{
if (p.second.empty())
queryString << "&" << p.first;
else
queryString << "&" << p.first << "=" << p.second;
}
url.setQuery(queryString.str().substr(1));
}
if (!queryParams.empty()) {
std::stringstream queryString;
for (const auto &p : queryParams)
{
if (p.second.empty())
queryString << "&" << p.first;
else
queryString << "&" << p.first << "=" << p.second;
}
url.setQuery(queryString.str().substr(1));
}
HttpRequest request(url);
request.setMethod(method);
if (msg.parameter("Accept").empty()) {
request.setHeader("Accept", "application/json");
} else {
request.setHeader("Accept", msg.parameter("Accept"));
}
HttpRequest request(url);
request.setMethod(method);
if (msg.parameter("Accept").empty()) {
request.setHeader("Accept", "application/json");
} else {
request.setHeader("Accept", msg.parameter("Accept"));
}
if (msg.hasContent()) {
std::stringstream ss;
ss << msg.contentSize();
request.setHeader("Content-Length", ss.str());
if(msg.parameter("Content-Type").empty()) {
request.setHeader("Content-Type", "application/octet-stream");
} else {
request.setHeader("Content-Type", msg.parameter("Content-Type"));
}
request.setHeader("Content-MD5", ComputeContentMD5(msg.content(),msg.contentSize()));
request.setBody(msg.content(), msg.contentSize());
}
if (msg.hasContent()) {
std::stringstream ss;
ss << msg.contentSize();
request.setHeader("Content-Length", ss.str());
if(msg.parameter("Content-Type").empty()) {
request.setHeader("Content-Type", "application/octet-stream");
} else {
request.setHeader("Content-Type", msg.parameter("Content-Type"));
}
request.setHeader("Content-MD5", ComputeContentMD5(msg.content(),msg.contentSize()));
request.setBody(msg.content(), msg.contentSize());
}
std::time_t t = std::time(nullptr);
std::stringstream date;
std::time_t t = std::time(nullptr);
std::stringstream date;
#if defined(__GNUG__) && __GNUC__ < 5
char tmbuff[26];
strftime(tmbuff, 26, "%a, %d %b %Y %T", std::gmtime(&t));
date << tmbuff << " GMT";
char tmbuff[26];
strftime(tmbuff, 26, "%a, %d %b %Y %T", std::gmtime(&t));
date << tmbuff << " GMT";
#else
date << std::put_time(std::gmtime(&t), "%a, %d %b %Y %T GMT");
date << std::put_time(std::gmtime(&t), "%a, %d %b %Y %T GMT");
#endif
request.setHeader("Date", date.str());
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
request.setHeader("x-acs-region-id", configuration().regionId());
if(!credentials.sessionToken().empty())
request.setHeader("x-acs-security-token", credentials.sessionToken());
request.setHeader("x-acs-signature-method", signer_->name());
request.setHeader("x-acs-signature-nonce", GenerateUuid());
request.setHeader("x-acs-signature-version", signer_->version());
request.setHeader("x-acs-version", msg.version());
request.setHeader("Date", date.str());
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
request.setHeader("x-acs-region-id", configuration().regionId());
if(!credentials.sessionToken().empty())
request.setHeader("x-acs-security-token", credentials.sessionToken());
request.setHeader("x-acs-signature-method", signer_->name());
request.setHeader("x-acs-signature-nonce", GenerateUuid());
request.setHeader("x-acs-signature-version", signer_->version());
request.setHeader("x-acs-version", msg.version());
std::stringstream plaintext;
plaintext << HttpMethodToString(method) << "\n"
<< request.header("Accept") << "\n"
<< request.header("Content-MD5") << "\n"
<< request.header("Content-Type") << "\n"
<< request.header("Date") << "\n"
<< canonicalizedHeaders(request.headers());
if (!url.hasQuery())
plaintext << url.path();
else
plaintext << url.path() << "?" << url.query();
std::stringstream plaintext;
plaintext << HttpMethodToString(method) << "\n"
<< request.header("Accept") << "\n"
<< request.header("Content-MD5") << "\n"
<< request.header("Content-Type") << "\n"
<< request.header("Date") << "\n"
<< canonicalizedHeaders(request.headers());
if (!url.hasQuery())
plaintext << url.path();
else
plaintext << url.path() << "?" << url.query();
std::stringstream sign;
sign << "acs "
<< credentials.accessKeyId()
<< ":"
<< signer_->generate(plaintext.str(), credentials.accessKeySecret());
request.setHeader("Authorization", sign.str());
std::stringstream sign;
sign << "acs "
<< credentials.accessKeyId()
<< ":"
<< signer_->generate(plaintext.str(), credentials.accessKeySecret());
request.setHeader("Authorization", sign.str());
return request;
return request;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,7 +23,7 @@
using namespace AlibabaCloud;
RoaServiceRequest::RoaServiceRequest(const std::string & product, const std::string & version) :
ServiceRequest(product, version)
ServiceRequest(product, version)
{
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,11 +24,11 @@
using namespace AlibabaCloud;
RpcServiceClient::RpcServiceClient(const std::string & servicename, const std::shared_ptr<CredentialsProvider> &credentialsProvider,
const ClientConfiguration &configuration,
const std::shared_ptr<Signer> &signer) :
CoreClient(servicename, configuration),
credentialsProvider_(credentialsProvider),
signer_(signer)
const ClientConfiguration &configuration,
const std::shared_ptr<Signer> &signer) :
CoreClient(servicename, configuration),
credentialsProvider_(credentialsProvider),
signer_(signer)
{
}
@@ -38,97 +38,97 @@ RpcServiceClient::~RpcServiceClient()
std::string RpcServiceClient::canonicalizedQuery(const std::map<std::string, std::string>& params) const
{
if (params.empty())
return std::string();
if (params.empty())
return std::string();
std::stringstream ss;
for (const auto &p : params)
{
std::string key = UrlEncode(p.first);
StringReplace(key, "+", "%20");
StringReplace(key, "*", "%2A");
StringReplace(key, "%7E", "~");
std::string value = UrlEncode(p.second);
StringReplace(value, "+", "%20");
StringReplace(value, "*", "%2A");
StringReplace(value, "%7E", "~");
ss << "&" << key << "=" << value;
}
return ss.str().substr(1);
std::stringstream ss;
for (const auto &p : params)
{
std::string key = UrlEncode(p.first);
StringReplace(key, "+", "%20");
StringReplace(key, "*", "%2A");
StringReplace(key, "%7E", "~");
std::string value = UrlEncode(p.second);
StringReplace(value, "+", "%20");
StringReplace(value, "*", "%2A");
StringReplace(value, "%7E", "~");
ss << "&" << key << "=" << value;
}
return ss.str().substr(1);
}
RpcServiceClient::JsonOutcome RpcServiceClient::makeRequest(const std::string &endpoint, const RpcServiceRequest &msg, HttpRequest::Method method)const
{
auto outcome = AttemptRequest(endpoint, msg, method);
if (outcome.isSuccess())
return JsonOutcome(std::string(outcome.result().body(),
outcome.result().bodySize()));
else
return JsonOutcome(outcome.error());
auto outcome = AttemptRequest(endpoint, msg, method);
if (outcome.isSuccess())
return JsonOutcome(std::string(outcome.result().body(),
outcome.result().bodySize()));
else
return JsonOutcome(outcome.error());
}
HttpRequest RpcServiceClient::buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method )const
{
return buildHttpRequest(endpoint, dynamic_cast<const RpcServiceRequest& >(msg), method);
return buildHttpRequest(endpoint, dynamic_cast<const RpcServiceRequest& >(msg), method);
}
HttpRequest RpcServiceClient::buildHttpRequest(const std::string & endpoint, const RpcServiceRequest &msg, HttpRequest::Method method) const
{
const Credentials credentials = credentialsProvider_->getCredentials();
const Credentials credentials = credentialsProvider_->getCredentials();
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
Url url;
if (msg.scheme().empty()) {
url.setScheme("https");
} else {
url.setScheme(msg.scheme());
}
url.setHost(endpoint);
url.setPath(msg.resourcePath());
url.setHost(endpoint);
url.setPath(msg.resourcePath());
auto params = msg.parameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params) {
if (!p.second.empty())
queryParams[p.first] = p.second;
}
auto params = msg.parameters();
std::map <std::string, std::string> queryParams;
for (const auto &p : params) {
if (!p.second.empty())
queryParams[p.first] = p.second;
}
queryParams["AccessKeyId"] = credentials.accessKeyId();
queryParams["Format"] = "JSON";
queryParams["RegionId"] = configuration().regionId();
queryParams["SecurityToken"] = credentials.sessionToken();
queryParams["SignatureMethod"] = signer_->name();
queryParams["SignatureNonce"] = GenerateUuid();
queryParams["SignatureVersion"] = signer_->version();
std::time_t t = std::time(nullptr);
std::stringstream ss;
queryParams["AccessKeyId"] = credentials.accessKeyId();
queryParams["Format"] = "JSON";
queryParams["RegionId"] = configuration().regionId();
queryParams["SecurityToken"] = credentials.sessionToken();
queryParams["SignatureMethod"] = signer_->name();
queryParams["SignatureNonce"] = GenerateUuid();
queryParams["SignatureVersion"] = signer_->version();
std::time_t t = std::time(nullptr);
std::stringstream ss;
#if defined(__GNUG__) && __GNUC__ < 5
char tmbuff[26];
strftime(tmbuff, 26, "%FT%TZ" , std::gmtime(&t));
ss << tmbuff;
char tmbuff[26];
strftime(tmbuff, 26, "%FT%TZ" , std::gmtime(&t));
ss << tmbuff;
#else
ss << std::put_time(std::gmtime(&t), "%FT%TZ");
ss << std::put_time(std::gmtime(&t), "%FT%TZ");
#endif
queryParams["Timestamp"] = ss.str();
queryParams["Version"] = msg.version();
queryParams["Timestamp"] = ss.str();
queryParams["Version"] = msg.version();
std::stringstream plaintext;
plaintext << HttpMethodToString(method)
<< "&"
<< UrlEncode(url.path())
<< "&"
<< UrlEncode(canonicalizedQuery(queryParams));
std::stringstream plaintext;
plaintext << HttpMethodToString(method)
<< "&"
<< UrlEncode(url.path())
<< "&"
<< UrlEncode(canonicalizedQuery(queryParams));
queryParams["Signature"] = signer_->generate(plaintext.str(), credentials.accessKeySecret() + "&");
queryParams["Signature"] = signer_->generate(plaintext.str(), credentials.accessKeySecret() + "&");
std::stringstream queryString;
for (const auto &p : queryParams)
queryString << "&" << p.first << "=" << UrlEncode(p.second);
url.setQuery(queryString.str().substr(1));
std::stringstream queryString;
for (const auto &p : queryParams)
queryString << "&" << p.first << "=" << UrlEncode(p.second);
url.setQuery(queryString.str().substr(1));
HttpRequest request(url);
request.setMethod(method);
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
return request;
}
HttpRequest request(url);
request.setMethod(method);
request.setHeader("Host", url.host());
request.setHeader("x-sdk-client", std::string("CPP/").append(ALIBABACLOUD_VERSION_STR));
return request;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,9 +19,9 @@
using namespace AlibabaCloud;
RpcServiceRequest::RpcServiceRequest(const std::string & product, const std::string & version, const std::string & action) :
ServiceRequest(product, version)
ServiceRequest(product, version)
{
setActionName(action);
setActionName(action);
}
RpcServiceRequest::~RpcServiceRequest()
@@ -30,11 +30,11 @@ RpcServiceRequest::~RpcServiceRequest()
std::string RpcServiceRequest::actionName()const
{
return parameter("Action");
return parameter("Action");
}
void RpcServiceRequest::setActionName(const std::string & name)
{
setParameter("Action", name);
}
setParameter("Action", name);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,11 +19,11 @@
using namespace AlibabaCloud;
Runnable::Runnable(const std::function<void()> f) :
f_(f)
f_(f)
{
}
void Runnable::run() const
{
f_();
}
f_();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,153 +19,153 @@
using namespace AlibabaCloud;
ServiceRequest::ServiceRequest(const std::string &product, const std::string &version) :
content_(nullptr),
contentSize_(0),
params_(),
product_(product),
resourcePath_("/"),
version_(version),
scheme_("https")
content_(nullptr),
contentSize_(0),
params_(),
product_(product),
resourcePath_("/"),
version_(version),
scheme_("https")
{
}
ServiceRequest::ServiceRequest(const ServiceRequest &other) :
content_(nullptr),
contentSize_(other.contentSize_),
params_(other.params_),
product_(other.product_),
resourcePath_(other.resourcePath_),
version_(other.version_),
scheme_(other.scheme_)
content_(nullptr),
contentSize_(other.contentSize_),
params_(other.params_),
product_(other.product_),
resourcePath_(other.resourcePath_),
version_(other.version_),
scheme_(other.scheme_)
{
setContent(other.content_, other.contentSize_);
setContent(other.content_, other.contentSize_);
}
ServiceRequest::ServiceRequest(ServiceRequest &&other)
{
*this = std::move(other);
*this = std::move(other);
}
ServiceRequest& ServiceRequest::operator=(const ServiceRequest &other)
{
if (this != &other) {
content_ = nullptr;
contentSize_ = 0;
params_ = other.params_;
setContent(other.content_, other.contentSize_);
}
return *this;
if (this != &other) {
content_ = nullptr;
contentSize_ = 0;
params_ = other.params_;
setContent(other.content_, other.contentSize_);
}
return *this;
}
ServiceRequest& ServiceRequest::operator=(ServiceRequest &&other)
{
if (this != &other)
*this = std::move(other);
return *this;
if (this != &other)
*this = std::move(other);
return *this;
}
ServiceRequest::~ServiceRequest()
{
if (content_)
delete content_;
if (content_)
delete content_;
}
const char * ServiceRequest::content() const
{
return content_;
return content_;
}
size_t ServiceRequest::contentSize() const
{
return contentSize_;
return contentSize_;
}
bool ServiceRequest::hasContent() const
{
return (contentSize_ != 0);
return (contentSize_ != 0);
}
void ServiceRequest::setContent(const char * data, size_t size)
{
if (content_)
delete content_;
content_ = nullptr;
contentSize_ = 0;
if (size) {
contentSize_ = size;
content_ = new char[size];
std::copy(data, data + size, content_);
}
if (content_)
delete content_;
content_ = nullptr;
contentSize_ = 0;
if (size) {
contentSize_ = size;
content_ = new char[size];
std::copy(data, data + size, content_);
}
}
void ServiceRequest::addParameter(const ParameterNameType & name, const ParameterValueType & value)
{
setParameter(name, value);
setParameter(name, value);
}
ServiceRequest::ParameterValueType ServiceRequest::parameter(const ParameterNameType &name)const
{
ParameterCollection::const_iterator it = params_.find(name);
if (it == params_.end()) {
return ParameterValueType("");
}
return it->second;
ParameterCollection::const_iterator it = params_.find(name);
if (it == params_.end()) {
return ParameterValueType("");
}
return it->second;
}
ServiceRequest::ParameterCollection ServiceRequest::parameters() const
{
return params_;
return params_;
}
void ServiceRequest::removeParameter(const ParameterNameType & name)
{
params_.erase(name);
params_.erase(name);
}
void ServiceRequest::setParameter(const ParameterNameType &name, const ParameterValueType &value)
{
params_[name] = value;
params_[name] = value;
}
void ServiceRequest::setParameters(const ParameterCollection & params)
{
params_ = params;
params_ = params;
}
std::string ServiceRequest::version()const
{
return version_;
return version_;
}
void ServiceRequest::setVersion(const std::string &version)
{
version_ = version;
version_ = version;
}
std::string ServiceRequest::product() const
{
return product_;
return product_;
}
void ServiceRequest::setProduct(const std::string & product)
{
product_ = product;
product_ = product;
}
std::string ServiceRequest::resourcePath() const
{
return resourcePath_;
return resourcePath_;
}
void ServiceRequest::setResourcePath(const std::string & path)
{
resourcePath_ = path;
resourcePath_ = path;
}
void ServiceRequest::setScheme(const std::string scheme) {
scheme_ = scheme;
scheme_ = scheme;
}
std::string ServiceRequest::scheme() const {
return scheme_;
return scheme_;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,7 +19,7 @@
using namespace AlibabaCloud;
ServiceResult::ServiceResult() :
requestId_()
requestId_()
{
}
@@ -29,10 +29,10 @@ ServiceResult::~ServiceResult()
std::string ServiceResult::requestId() const
{
return requestId_;
return requestId_;
}
void ServiceResult::setRequestId(const std::string & requestId)
{
requestId_ = requestId;
requestId_ = requestId;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,9 +19,9 @@
using namespace AlibabaCloud;
Signer::Signer(Type type, const std::string & name, const std::string & version) :
type_(type),
name_(name),
version_(version)
type_(type),
name_(name),
version_(version)
{
}
@@ -31,15 +31,15 @@ Signer::~Signer()
std::string Signer::name() const
{
return name_;
return name_;
}
Signer::Type Signer::type() const
{
return type_;
return type_;
}
std::string Signer::version() const
{
return version_;
return version_;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,14 +19,14 @@
using namespace AlibabaCloud;
SimpleCredentialsProvider::SimpleCredentialsProvider(const Credentials &credentials):
CredentialsProvider(),
credentials_(credentials)
CredentialsProvider(),
credentials_(credentials)
{
}
SimpleCredentialsProvider::SimpleCredentialsProvider(const std::string & accessKeyId, const std::string & accessKeySecret) :
CredentialsProvider(),
credentials_(accessKeyId, accessKeySecret)
CredentialsProvider(),
credentials_(accessKeyId, accessKeySecret)
{
}
@@ -36,5 +36,5 @@ SimpleCredentialsProvider::~SimpleCredentialsProvider()
Credentials SimpleCredentialsProvider::getCredentials()
{
return credentials_;
return credentials_;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,21 +22,21 @@ using namespace AlibabaCloud;
using namespace AlibabaCloud::Sts;
StsAssumeRoleCredentialsProvider::StsAssumeRoleCredentialsProvider(
const Credentials &credentials,
const ClientConfiguration &configuration,
const std::string & roleArn,
const std::string & roleSessionName,
const std::string & policy,
int durationSeconds):
CredentialsProvider(),
StsClient(credentials, configuration),
roleArn_(roleArn),
roleSessionName_(roleSessionName),
policy_(policy),
durationSeconds_(durationSeconds),
cachedMutex_(),
cachedCredentials_("", ""),
expiry_()
const Credentials &credentials,
const ClientConfiguration &configuration,
const std::string & roleArn,
const std::string & roleSessionName,
const std::string & policy,
int durationSeconds):
CredentialsProvider(),
StsClient(credentials, configuration),
roleArn_(roleArn),
roleSessionName_(roleSessionName),
policy_(policy),
durationSeconds_(durationSeconds),
cachedMutex_(),
cachedCredentials_("", ""),
expiry_()
{
}
@@ -46,49 +46,49 @@ StsAssumeRoleCredentialsProvider::~StsAssumeRoleCredentialsProvider()
Credentials StsAssumeRoleCredentialsProvider::getCredentials()
{
loadCredentials();
std::lock_guard<std::mutex> locker(cachedMutex_);
return cachedCredentials_;
loadCredentials();
std::lock_guard<std::mutex> locker(cachedMutex_);
return cachedCredentials_;
}
bool StsAssumeRoleCredentialsProvider::checkExpiry()const
{
auto now = std::chrono::system_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
auto now = std::chrono::system_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
return (diff > 0 - 60);
return (diff > 0 - 60);
}
void StsAssumeRoleCredentialsProvider::loadCredentials()
{
if (checkExpiry())
{
std::lock_guard<std::mutex> locker(cachedMutex_);
if (checkExpiry())
{
Model::AssumeRoleRequest request;
request.setRoleArn(roleArn_);
request.setRoleSessionName(roleSessionName_);
request.setPolicy(policy_);
request.setDurationSeconds(durationSeconds_);
if (checkExpiry())
{
std::lock_guard<std::mutex> locker(cachedMutex_);
if (checkExpiry())
{
Model::AssumeRoleRequest request;
request.setRoleArn(roleArn_);
request.setRoleSessionName(roleSessionName_);
request.setPolicy(policy_);
request.setDurationSeconds(durationSeconds_);
auto assumeRoleOutcome = assumeRole(request);
if (assumeRoleOutcome.isSuccess())
{
const auto stsCredentials = assumeRoleOutcome.result().credentials();
cachedCredentials_ = Credentials(stsCredentials.accessKeyId,
stsCredentials.accessKeySecret,
stsCredentials.securityToken);
auto assumeRoleOutcome = assumeRole(request);
if (assumeRoleOutcome.isSuccess())
{
const auto stsCredentials = assumeRoleOutcome.result().credentials();
cachedCredentials_ = Credentials(stsCredentials.accessKeyId,
stsCredentials.accessKeySecret,
stsCredentials.securityToken);
std::tm tm = {};
std::tm tm = {};
#if defined(__GNUG__) && __GNUC__ < 5
strptime(stsCredentials.expiration.c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm);
strptime(stsCredentials.expiration.c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm);
#else
std::stringstream ss(stsCredentials.expiration);
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
std::stringstream ss(stsCredentials.expiration);
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
#endif
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
}
}
}
}
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
}
}
}
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,17 +26,17 @@ namespace
}
Url::Url(const std::string & url) :
scheme_(),
userName_(),
password_(),
host_(),
path_(),
port_(INVALID_PORT),
query_(),
fragment_()
scheme_(),
userName_(),
password_(),
host_(),
path_(),
port_(INVALID_PORT),
query_(),
fragment_()
{
if(!url.empty())
fromString(url);
if(!url.empty())
fromString(url);
}
Url::~Url()
@@ -45,300 +45,300 @@ Url::~Url()
bool Url::operator==(const Url &url) const
{
return scheme_ == url.scheme_
&& userName_ == url.userName_
&& password_ == url.password_
&& host_ == url.host_
&& path_ == url.path_
&& port_ == url.port_
&& query_ == url.query_
&& fragment_ == url.fragment_;
return scheme_ == url.scheme_
&& userName_ == url.userName_
&& password_ == url.password_
&& host_ == url.host_
&& path_ == url.path_
&& port_ == url.port_
&& query_ == url.query_
&& fragment_ == url.fragment_;
}
bool Url::operator!=(const Url &url) const
{
return !(*this == url);
return !(*this == url);
}
std::string Url::authority() const
{
if (!isValid())
return std::string();
if (!isValid())
return std::string();
std::ostringstream out;
std::string str = userInfo();
if (!str.empty())
out << str << "@";
out << host_;
if (port_ != INVALID_PORT)
out << ":" << port_;
return out.str();
std::ostringstream out;
std::string str = userInfo();
if (!str.empty())
out << str << "@";
out << host_;
if (port_ != INVALID_PORT)
out << ":" << port_;
return out.str();
}
void Url::clear()
{
scheme_.clear();
userName_.clear();
password_.clear();
host_.clear();
path_.clear();
port_ = INVALID_PORT;
query_.clear();
fragment_.clear();
scheme_.clear();
userName_.clear();
password_.clear();
host_.clear();
path_.clear();
port_ = INVALID_PORT;
query_.clear();
fragment_.clear();
}
std::string Url::fragment() const
{
return fragment_;
return fragment_;
}
void Url::fromString(const std::string & url)
{
clear();
if (url.empty())
return;
clear();
if (url.empty())
return;
std::string str = url;
std::string::size_type pos = 0;
std::string authority, fragment, path, query, scheme;
std::string str = url;
std::string::size_type pos = 0;
std::string authority, fragment, path, query, scheme;
pos = str.find("://");
if (pos != str.npos) {
scheme = str.substr(0, pos);
str.erase(0, pos + 3);
}
pos = str.find("://");
if (pos != str.npos) {
scheme = str.substr(0, pos);
str.erase(0, pos + 3);
}
pos = str.find('#');
if (pos != str.npos) {
fragment = str.substr(pos + 1);
str.erase(pos);
}
pos = str.find('#');
if (pos != str.npos) {
fragment = str.substr(pos + 1);
str.erase(pos);
}
pos = str.find('?');
if (pos != str.npos) {
query = str.substr(pos + 1);
str.erase(pos);
}
pos = str.find('?');
if (pos != str.npos) {
query = str.substr(pos + 1);
str.erase(pos);
}
pos = str.find('/');
if (pos != str.npos) {
path = str.substr(pos);
str.erase(pos);
}
else
path = "/";
pos = str.find('/');
if (pos != str.npos) {
path = str.substr(pos);
str.erase(pos);
}
else
path = "/";
authority = str;
authority = str;
setScheme(scheme);
setAuthority(authority);
setPath(path);
setQuery(query);
setFragment(fragment);
setScheme(scheme);
setAuthority(authority);
setPath(path);
setQuery(query);
setFragment(fragment);
}
bool Url::hasFragment() const
{
return !fragment_.empty();
return !fragment_.empty();
}
bool Url::hasQuery() const
{
return !query_.empty();
return !query_.empty();
}
std::string Url::host() const
{
return host_;
return host_;
}
bool Url::isEmpty() const
{
return scheme_.empty()
&& userName_.empty()
&& password_.empty()
&& host_.empty()
&& path_.empty()
&& (port_ == INVALID_PORT)
&& query_.empty()
&& fragment_.empty();
return scheme_.empty()
&& userName_.empty()
&& password_.empty()
&& host_.empty()
&& path_.empty()
&& (port_ == INVALID_PORT)
&& query_.empty()
&& fragment_.empty();
}
bool Url::isValid() const
{
if (isEmpty())
return false;
if (isEmpty())
return false;
if (host_.empty())
return false;
if (host_.empty())
return false;
bool valid = true;
if (userName_.empty())
valid = password_.empty();
return valid;
bool valid = true;
if (userName_.empty())
valid = password_.empty();
return valid;
}
int Url::port() const
{
return port_;
return port_;
}
std::string Url::password() const
{
return password_;
return password_;
}
std::string Url::path() const
{
return path_;
return path_;
}
std::string Url::query() const
{
return query_;
return query_;
}
std::string Url::scheme() const
{
return scheme_;
return scheme_;
}
void Url::setAuthority(const std::string & authority)
{
if (authority.empty()) {
setUserInfo("");
setHost("");
setPort(INVALID_PORT);
return;
}
if (authority.empty()) {
setUserInfo("");
setHost("");
setPort(INVALID_PORT);
return;
}
std::string userinfo, host, port;
std::string::size_type pos = 0, prevpos = 0;
std::string userinfo, host, port;
std::string::size_type pos = 0, prevpos = 0;
pos = authority.find('@');
if (pos != authority.npos) {
userinfo = authority.substr(0, pos);
prevpos = pos + 1;
}
else {
pos = 0;
}
pos = authority.find('@');
if (pos != authority.npos) {
userinfo = authority.substr(0, pos);
prevpos = pos + 1;
}
else {
pos = 0;
}
pos = authority.find(':', prevpos);
if (pos == authority.npos)
host = authority.substr(prevpos);
else {
host = authority.substr(prevpos, pos - prevpos);
port = authority.substr(pos + 1);
}
pos = authority.find(':', prevpos);
if (pos == authority.npos)
host = authority.substr(prevpos);
else {
host = authority.substr(prevpos, pos - prevpos);
port = authority.substr(pos + 1);
}
setUserInfo(userinfo);
setHost(host);
setPort(!port.empty() ? atoi(port.c_str()): INVALID_PORT);
setUserInfo(userinfo);
setHost(host);
setPort(!port.empty() ? atoi(port.c_str()): INVALID_PORT);
}
void Url::setFragment(const std::string & fragment)
{
fragment_ = fragment;
fragment_ = fragment;
}
void Url::setHost(const std::string & host)
{
if(host.empty()){
host_.clear();
return;
}
host_ = host;
std::transform(host_.begin(), host_.end(), host_.begin(), ::tolower);
if(host.empty()){
host_.clear();
return;
}
host_ = host;
std::transform(host_.begin(), host_.end(), host_.begin(), ::tolower);
}
void Url::setPassword(const std::string & password)
{
password_ = password;
password_ = password;
}
void Url::setPath(const std::string & path)
{
path_ = path;
path_ = path;
}
void Url::setPort(int port)
{
port_ = port;
port_ = port;
}
void Url::setQuery(const std::string & query)
{
query_ = query;
query_ = query;
}
void Url::setScheme(const std::string & scheme)
{
if(scheme.empty()){
scheme_.clear();
return;
}
scheme_ = scheme;
std::transform(scheme_.begin(), scheme_.end(), scheme_.begin(), ::tolower);
if(scheme.empty()){
scheme_.clear();
return;
}
scheme_ = scheme;
std::transform(scheme_.begin(), scheme_.end(), scheme_.begin(), ::tolower);
}
void Url::setUserInfo(const std::string & userInfo)
{
if (userInfo.empty()) {
userName_.clear();
password_.clear();
return;
}
if (userInfo.empty()) {
userName_.clear();
password_.clear();
return;
}
auto pos = userInfo.find(':');
if (pos == userInfo.npos)
userName_ = userInfo;
else {
userName_ = userInfo.substr(0, pos);
password_ = userInfo.substr(pos + 1);
}
auto pos = userInfo.find(':');
if (pos == userInfo.npos)
userName_ = userInfo;
else {
userName_ = userInfo.substr(0, pos);
password_ = userInfo.substr(pos + 1);
}
}
void Url::setUserName(const std::string & userName)
{
userName_ = userName;
userName_ = userName;
}
std::string Url::toString() const
{
if (!isValid())
return std::string();
if (!isValid())
return std::string();
std::ostringstream out;
if (!scheme_.empty())
out << scheme_ << "://";
std::string str = authority();
if (!str.empty())
out << authority();
if (path_.empty())
out << "/";
else
out << path_;
if (hasQuery())
out << "?" << query_;
if (hasFragment())
out << "#" << fragment_;
return out.str();
std::ostringstream out;
if (!scheme_.empty())
out << scheme_ << "://";
std::string str = authority();
if (!str.empty())
out << authority();
if (path_.empty())
out << "/";
else
out << path_;
if (hasQuery())
out << "?" << query_;
if (hasFragment())
out << "#" << fragment_;
return out.str();
}
std::string Url::userInfo() const
{
if (!isValid())
return std::string();
if (!isValid())
return std::string();
std::ostringstream out;
out << userName_;
if (!password_.empty())
out << ":" << password_;
return out.str();
std::ostringstream out;
out << userName_;
if (!password_.empty())
out << ":" << password_;
return out.str();
}
std::string Url::userName() const
{
return userName_;
return userName_;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,116 +27,116 @@
std::string AlibabaCloud::GenerateUuid()
{
#ifdef _WIN32
char *data;
UUID uuidhandle;
UuidCreate(&uuidhandle);
UuidToString(&uuidhandle, (RPC_CSTR*)&data);
std::string uuid(data);
RpcStringFree((RPC_CSTR*)&data);
return uuid;
char *data;
UUID uuidhandle;
UuidCreate(&uuidhandle);
UuidToString(&uuidhandle, (RPC_CSTR*)&data);
std::string uuid(data);
RpcStringFree((RPC_CSTR*)&data);
return uuid;
#else
uuid_t uu;
uuid_generate(uu);
char buf[36];
uuid_unparse(uu, buf);
return buf;
uuid_t uu;
uuid_generate(uu);
char buf[36];
uuid_unparse(uu, buf);
return buf;
#endif
}
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);
curl_free(output);
return result;
CURL *curl = curl_easy_init();
char *output = curl_easy_escape(curl, src.c_str(), src.size());
std::string result(output);
curl_free(output);
return result;
}
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);
std::string result(output, outlength);
curl_free(output);
return result;
CURL *curl = curl_easy_init();
int outlength = 0;
char *output = curl_easy_unescape(curl, src.c_str(), src.size(), &outlength);
std::string result(output, outlength);
curl_free(output);
return result;
}
std::string AlibabaCloud::ComputeContentMD5(const char * data, size_t size)
{
#ifdef _WIN32
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
BYTE pbHash[16];
DWORD dwDataLen = 16;
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
BYTE pbHash[16];
DWORD dwDataLen = 16;
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
CryptHashData(hHash, (BYTE*)(data), size, 0);
CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &dwDataLen, 0);
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
CryptHashData(hHash, (BYTE*)(data), size, 0);
CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &dwDataLen, 0);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
DWORD dlen = 0;
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);
DWORD dlen = 0;
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);
std::string ret = std::string(dest, dlen);
delete dest;
return ret;
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);
unsigned char md[MD5_DIGEST_LENGTH];
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);
return encodedData;
char encodedData[100];
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)
{
std::string::size_type pos =0;
while ((pos = src.find(s1, pos)) != std::string::npos)
{
src.replace(pos, s1.length(), s2);
pos += s2.length();
}
std::string::size_type pos =0;
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)
{
case HttpRequest::Method::Head:
return "HEAD";
break;
case HttpRequest::Method::Post:
return "POST";
break;
case HttpRequest::Method::Put:
return "PUT";
break;
case HttpRequest::Method::Delete:
return "DELETE";
break;
case HttpRequest::Method::Connect:
return "CONNECT";
break;
case HttpRequest::Method::Options:
return "OPTIONS";
break;
case HttpRequest::Method::Patch:
return "PATCH";
break;
case HttpRequest::Method::Trace:
return "TRACE";
break;
case HttpRequest::Method::Get:
default:
return "GET";
break;
}
switch (method)
{
case HttpRequest::Method::Head:
return "HEAD";
break;
case HttpRequest::Method::Post:
return "POST";
break;
case HttpRequest::Method::Put:
return "PUT";
break;
case HttpRequest::Method::Delete:
return "DELETE";
break;
case HttpRequest::Method::Connect:
return "CONNECT";
break;
case HttpRequest::Method::Options:
return "OPTIONS";
break;
case HttpRequest::Method::Patch:
return "PATCH";
break;
case HttpRequest::Method::Trace:
return "TRACE";
break;
case HttpRequest::Method::Get:
default:
return "GET";
break;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,11 @@
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);
std::string UrlEncode(const std::string &src);
std::string UrlDecode(const std::string &src);
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);
std::string UrlEncode(const std::string &src);
std::string UrlDecode(const std::string &src);
}
#endif
#endif

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,22 +22,22 @@ using namespace AlibabaCloud::Location;
namespace
{
const std::string SERVICE_NAME = "Location";
const std::string ENDPOINT = "location.aliyuncs.com";
const std::string SERVICE_NAME = "Location";
const std::string ENDPOINT = "location.aliyuncs.com";
}
LocationClient::LocationClient(const Credentials &credentials, const ClientConfiguration &configuration) :
RpcServiceClient(SERVICE_NAME, 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(SERVICE_NAME, credentialsProvider, configuration)
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
{
}
LocationClient::LocationClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
{
}
@@ -52,31 +52,31 @@ LocationClient::~LocationClient()
LocationClient::DescribeEndpointsOutcome LocationClient::describeEndpoints(const Model::DescribeEndpointsRequest &request) const
{
auto outcome = makeRequest(ENDPOINT, request);
auto outcome = makeRequest(ENDPOINT, request);
if (outcome.isSuccess())
return DescribeEndpointsOutcome(Model::DescribeEndpointsResult(outcome.result()));
else
return DescribeEndpointsOutcome(outcome.error());
if (outcome.isSuccess())
return DescribeEndpointsOutcome(Model::DescribeEndpointsResult(outcome.result()));
else
return DescribeEndpointsOutcome(outcome.error());
}
void LocationClient::describeEndpointsAsync(const Model::DescribeEndpointsRequest& request, const DescribeEndpointsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
std::async(std::launch::async,
[this, request, handler, context]()
{
handler(this, request, describeEndpoints(request), context);
});
std::async(std::launch::async,
[this, request, handler, context]()
{
handler(this, request, describeEndpoints(request), context);
});
}
LocationClient::DescribeEndpointsOutcomeCallable LocationClient::describeEndpointsCallable(const Model::DescribeEndpointsRequest &request) const
{
auto task = std::make_shared<std::packaged_task<DescribeEndpointsOutcome()>>(
[this, request]()
{
return this->describeEndpoints(request);
});
auto task = std::make_shared<std::packaged_task<DescribeEndpointsOutcome()>>(
[this, request]()
{
return this->describeEndpoints(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
/*
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +19,10 @@
using namespace AlibabaCloud::Location;
LocationRequest::LocationRequest(const std::string & action) :
RpcServiceRequest("location", "2015-06-12", action)
{ }
RpcServiceRequest("location", "2015-06-12", action)
{
}
LocationRequest::~LocationRequest()
{ }
{
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ using namespace AlibabaCloud::Location;
using namespace AlibabaCloud::Location::Model;
DescribeEndpointsRequest::DescribeEndpointsRequest() :
LocationRequest("DescribeEndpoints")
LocationRequest("DescribeEndpoints")
{}
DescribeEndpointsRequest::~DescribeEndpointsRequest()
@@ -28,31 +28,30 @@ DescribeEndpointsRequest::~DescribeEndpointsRequest()
std::string DescribeEndpointsRequest::serviceCode()const
{
return parameter("ServiceCode");
return parameter("ServiceCode");
}
void DescribeEndpointsRequest::setServiceCode(const std::string & serviceCode)
{
setParameter("ServiceCode", serviceCode);
setParameter("ServiceCode", serviceCode);
}
std::string DescribeEndpointsRequest::id()const
{
return parameter("Id");
return parameter("Id");
}
void DescribeEndpointsRequest::setId(const std::string & id)
{
setParameter("Id", id);
setParameter("Id", id);
}
std::string DescribeEndpointsRequest::type()const
{
return parameter("Type");
return parameter("Type");
}
void DescribeEndpointsRequest::setType(const std::string & type)
{
setParameter("Type", type);
setParameter("Type", type);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,14 +21,14 @@ using namespace AlibabaCloud::Location;
using namespace AlibabaCloud::Location::Model;
DescribeEndpointsResult::DescribeEndpointsResult() :
ServiceResult()
ServiceResult()
{
}
DescribeEndpointsResult::DescribeEndpointsResult(const std::string &payload) :
ServiceResult()
ServiceResult()
{
parse(payload);
parse(payload);
}
DescribeEndpointsResult::~DescribeEndpointsResult()
@@ -36,48 +36,47 @@ DescribeEndpointsResult::~DescribeEndpointsResult()
void DescribeEndpointsResult::parse(const std::string &payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
setRequestId(value["RequestId"].asString());
success_ = value["Success"].asBool();
auto allEndpoints = value["Endpoints"]["Endpoint"];
for (const auto &item : allEndpoints)
{
Endpoint region;
region.endpoint = item["Endpoint"].asString();
region.id = item["Id"].asString();
region.namespace_ = item["Namespace"].asString();
region.serivceCode = item["SerivceCode"].asString();
region.type = item["Type"].asString();
auto allProtocols = item["Protocols"]["Protocols"];
for (const auto &item : allProtocols)
{
region.protocols.push_back(item.asString());
}
endpoints_.push_back(region);
}
success_ = value["Success"].asBool();
auto allEndpoints = value["Endpoints"]["Endpoint"];
for (const auto &item : allEndpoints)
{
Endpoint region;
region.endpoint = item["Endpoint"].asString();
region.id = item["Id"].asString();
region.namespace_ = item["Namespace"].asString();
region.serivceCode = item["SerivceCode"].asString();
region.type = item["Type"].asString();
auto allProtocols = item["Protocols"]["Protocols"];
for (const auto &item : allProtocols)
{
region.protocols.push_back(item.asString());
}
endpoints_.push_back(region);
}
}
std::vector<DescribeEndpointsResult::Endpoint> DescribeEndpointsResult::endpoints()const
{
return endpoints_;
return endpoints_;
}
void DescribeEndpointsResult::setEndpoints(const std::vector<Endpoint> & endpoints)
{
endpoints_ = endpoints;
endpoints_ = endpoints;
}
bool DescribeEndpointsResult::success()const
{
return success_;
return success_;
}
void DescribeEndpointsResult::setSuccess(const bool & success)
{
success_ = success;
success_ = success;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,22 +24,22 @@ using namespace AlibabaCloud::Sts::Model;
namespace
{
const std::string SERVICE_NAME = "Sts";
const std::string ENDPOINT = "sts.aliyuncs.com";
const std::string SERVICE_NAME = "Sts";
const std::string ENDPOINT = "sts.aliyuncs.com";
}
StsClient::StsClient(const Credentials &credentials, const ClientConfiguration &configuration) :
RpcServiceClient(SERVICE_NAME, 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(SERVICE_NAME, credentialsProvider, configuration)
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
{
}
StsClient::StsClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
{
}
@@ -49,64 +49,64 @@ StsClient::~StsClient()
StsClient::AssumeRoleOutcome StsClient::assumeRole(const Model::AssumeRoleRequest &request)const
{
auto outcome = makeRequest(ENDPOINT, request);
auto outcome = makeRequest(ENDPOINT, request);
if (outcome.isSuccess())
return AssumeRoleOutcome(AssumeRoleResult(outcome.result()));
else
return AssumeRoleOutcome(Error(outcome.error()));
if (outcome.isSuccess())
return AssumeRoleOutcome(AssumeRoleResult(outcome.result()));
else
return AssumeRoleOutcome(Error(outcome.error()));
}
void StsClient::assumeRoleAsync(const Model::AssumeRoleRequest & request, const AssumeRoleAsyncHandler & handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, assumeRole(request), context);
};
auto fn = [this, request, handler, context]()
{
handler(this, request, assumeRole(request), context);
};
asyncExecute(new Runnable(fn));
asyncExecute(new Runnable(fn));
}
StsClient::AssumeRoleOutcomeCallable StsClient::assumeRoleCallable(const Model::AssumeRoleRequest & request) const
{
auto task = std::make_shared<std::packaged_task<AssumeRoleOutcome()>>(
[this, request]()
{
return this->assumeRole(request);
});
auto task = std::make_shared<std::packaged_task<AssumeRoleOutcome()>>(
[this, request]()
{
return this->assumeRole(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}
StsClient::GetCallerIdentityOutcome StsClient::getCallerIdentity(const GetCallerIdentityRequest &request) const
{
auto outcome = makeRequest(ENDPOINT, request);
auto outcome = makeRequest(ENDPOINT, request);
if (outcome.isSuccess())
return GetCallerIdentityOutcome(GetCallerIdentityResult(outcome.result()));
else
return GetCallerIdentityOutcome(Error(outcome.error()));
if (outcome.isSuccess())
return GetCallerIdentityOutcome(GetCallerIdentityResult(outcome.result()));
else
return GetCallerIdentityOutcome(Error(outcome.error()));
}
void StsClient::getCallerIdentityAsync(const GetCallerIdentityRequest& request, const GetCallerIdentityAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, getCallerIdentity(request), context);
};
auto fn = [this, request, handler, context]()
{
handler(this, request, getCallerIdentity(request), context);
};
asyncExecute(new Runnable(fn));
asyncExecute(new Runnable(fn));
}
StsClient::GetCallerIdentityOutcomeCallable StsClient::getCallerIdentityCallable(const GetCallerIdentityRequest &request) const
{
auto task = std::make_shared<std::packaged_task<GetCallerIdentityOutcome()>>(
[this, request]()
{
return this->getCallerIdentity(request);
});
auto task = std::make_shared<std::packaged_task<GetCallerIdentityOutcome()>>(
[this, request]()
{
return this->getCallerIdentity(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,10 @@ using namespace AlibabaCloud;
using namespace AlibabaCloud::Sts;
StsRequest::StsRequest(const std::string & action) :
RpcServiceRequest("sts", "2015-04-01", action)
RpcServiceRequest("sts", "2015-04-01", action)
{
}
StsRequest::~StsRequest()
{
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,11 +21,11 @@ using namespace AlibabaCloud::Sts;
using namespace AlibabaCloud::Sts::Model;
AssumeRoleRequest::AssumeRoleRequest() :
StsRequest("AssumeRole")
StsRequest("AssumeRole")
{
setRoleArn("");
setRoleSessionName("");
setDurationSeconds(3600);
setRoleArn("");
setRoleSessionName("");
setDurationSeconds(3600);
}
AssumeRoleRequest::~AssumeRoleRequest()
@@ -34,40 +34,40 @@ AssumeRoleRequest::~AssumeRoleRequest()
int AssumeRoleRequest::durationSeconds() const
{
return std::stoi(parameter("DurationSeconds"));
return std::stoi(parameter("DurationSeconds"));
}
std::string AssumeRoleRequest::policy() const
{
return parameter("Policy");
return parameter("Policy");
}
std::string AssumeRoleRequest::roleArn() const
{
return parameter("RoleArn");
return parameter("RoleArn");
}
std::string AssumeRoleRequest::roleSessionName() const
{
return parameter("RoleSessionName");
return parameter("RoleSessionName");
}
void AssumeRoleRequest::setDurationSeconds(int durationSeconds)
{
setParameter("DurationSeconds", std::to_string(durationSeconds));
setParameter("DurationSeconds", std::to_string(durationSeconds));
}
void AssumeRoleRequest::setPolicy(const std::string & policy)
{
setParameter("Policy", policy);
setParameter("Policy", policy);
}
void AssumeRoleRequest::setRoleArn(const std::string & roleArn)
{
setParameter("RoleArn", roleArn);
setParameter("RoleArn", roleArn);
}
void AssumeRoleRequest::setRoleSessionName(const std::string & roleSessionName)
{
setParameter("RoleSessionName", roleSessionName);
setParameter("RoleSessionName", roleSessionName);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,18 +21,18 @@ using namespace AlibabaCloud::Sts;
using namespace AlibabaCloud::Sts::Model;
AssumeRoleResult::AssumeRoleResult() :
ServiceResult(),
assumedRoleUser_(),
credentials_()
ServiceResult(),
assumedRoleUser_(),
credentials_()
{
}
AssumeRoleResult::AssumeRoleResult(const std::string & payload) :
ServiceResult(),
assumedRoleUser_(),
credentials_()
ServiceResult(),
assumedRoleUser_(),
credentials_()
{
parse(payload);
parse(payload);
}
AssumeRoleResult::~AssumeRoleResult()
@@ -41,29 +41,29 @@ AssumeRoleResult::~AssumeRoleResult()
AssumeRoleResult::AssumedRoleUser AssumeRoleResult::assumedRoleUser() const
{
return assumedRoleUser_;
return assumedRoleUser_;
}
AssumeRoleResult::Credentials AssumeRoleResult::credentials() const
{
return credentials_;
return credentials_;
}
void AssumeRoleResult::parse(const std::string & payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
setRequestId(value["RequestId"].asString());
auto assumedRoleUserNode = value["AssumedRoleUser"];
assumedRoleUser_.assumedRoleId = assumedRoleUserNode["AssumedRoleId"].asString();
assumedRoleUser_.arn = assumedRoleUserNode["Arn"].asString();
auto assumedRoleUserNode = value["AssumedRoleUser"];
assumedRoleUser_.assumedRoleId = assumedRoleUserNode["AssumedRoleId"].asString();
assumedRoleUser_.arn = assumedRoleUserNode["Arn"].asString();
auto credentialsNode = value["Credentials"];
credentials_.accessKeyId = credentialsNode["AccessKeyId"].asString();
credentials_.accessKeySecret = credentialsNode["AccessKeySecret"].asString();
credentials_.expiration = credentialsNode["Expiration"].asString();
credentials_.securityToken = credentialsNode["SecurityToken"].asString();
auto credentialsNode = value["Credentials"];
credentials_.accessKeyId = credentialsNode["AccessKeyId"].asString();
credentials_.accessKeySecret = credentialsNode["AccessKeySecret"].asString();
credentials_.expiration = credentialsNode["Expiration"].asString();
credentials_.securityToken = credentialsNode["SecurityToken"].asString();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,10 +21,10 @@ using namespace AlibabaCloud::Sts;
using namespace AlibabaCloud::Sts::Model;
GetCallerIdentityRequest::GetCallerIdentityRequest() :
StsRequest("GetCallerIdentity")
StsRequest("GetCallerIdentity")
{
}
GetCallerIdentityRequest::~GetCallerIdentityRequest()
{
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
* Copyright 1999-2019 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,20 +22,20 @@ using namespace AlibabaCloud::Sts;
using namespace AlibabaCloud::Sts::Model;
GetCallerIdentityResult::GetCallerIdentityResult() :
ServiceResult(),
accountId_(),
arn_(),
userId_()
ServiceResult(),
accountId_(),
arn_(),
userId_()
{
}
GetCallerIdentityResult::GetCallerIdentityResult(const std::string & payload) :
ServiceResult(),
accountId_(),
arn_(),
userId_()
ServiceResult(),
accountId_(),
arn_(),
userId_()
{
parse(payload);
parse(payload);
}
GetCallerIdentityResult::~GetCallerIdentityResult()
@@ -44,28 +44,28 @@ GetCallerIdentityResult::~GetCallerIdentityResult()
std::string GetCallerIdentityResult::accountId()
{
return accountId_;
return accountId_;
}
std::string GetCallerIdentityResult::arn() const
{
return arn_;
return arn_;
}
std::string GetCallerIdentityResult::userId() const
{
return userId_;
return userId_;
}
void GetCallerIdentityResult::parse(const std::string & payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
setRequestId(value["RequestId"].asString());
accountId_ = value["AccountId"].asString();
arn_ = value["Arn"].asString();
userId_ = value["UserId"].asString();
}
accountId_ = value["AccountId"].asString();
arn_ = value["Arn"].asString();
userId_ = value["UserId"].asString();
}