Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85e2f3ebe4 | ||
|
|
a6d33574bd | ||
|
|
c17dc7c79a | ||
|
|
563e907601 | ||
|
|
33a44c856d | ||
|
|
f877a9ef39 | ||
|
|
eb7ab33440 | ||
|
|
6a5f788210 | ||
|
|
fdc3251134 | ||
|
|
043df1b674 | ||
|
|
5f3caa1943 | ||
|
|
01dcff0b7c | ||
|
|
ae7e11733f | ||
|
|
da28515bd8 | ||
|
|
138dbdc61e | ||
|
|
b429dcc915 | ||
|
|
57daafe4cc | ||
|
|
ecd09578e8 | ||
|
|
78df52c437 | ||
|
|
e477d06dea | ||
|
|
e00a04b071 | ||
|
|
48fc5dfe8c | ||
|
|
6cfcc11657 | ||
|
|
7b7c45cb26 | ||
|
|
cf825c63a5 | ||
|
|
fc29617d7d | ||
|
|
352be1dd14 | ||
|
|
66910b1961 | ||
|
|
790577e792 | ||
|
|
1ee62b8677 | ||
|
|
21edc7f283 | ||
|
|
919f98cbdd | ||
|
|
ad045aa702 | ||
|
|
6e65f364a1 | ||
|
|
bc0df2dcec | ||
|
|
9664fb1b00 |
26
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: "Bug Report"
|
||||
about: Create a report to help us improve
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
Thank you for reporting a possible bug in Alibaba Cloud C++ SDK
|
||||
|
||||
Please fill in as much of the template below as you can.
|
||||
|
||||
Product and API: the product and API you are working on when bug occurs
|
||||
Platform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)
|
||||
How to Reproduce: If possible, please provide code that demonstrates the problem,
|
||||
keeping it as simple and free of external dependencies as you can.
|
||||
|
||||
If crash, please provide the stack trace.
|
||||
|
||||
If build error, please provide compiler information: compiler and version, etc
|
||||
-->
|
||||
|
||||
* **Product and API**:
|
||||
* **Platform**:
|
||||
* **How to Reproduce**
|
||||
|
||||
<!-- Please provide more details below this comment. -->
|
||||
28
.github/ISSUE_TEMPLATE/bug_report_cn.md
vendored
Normal file
28
.github/ISSUE_TEMPLATE/bug_report_cn.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
name: "缺陷问题反馈"
|
||||
about: 提交缺陷问题反馈
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
感谢提交问题反馈。
|
||||
|
||||
请提供尽量全面的信息协助问题定位修复。
|
||||
|
||||
产品和接口:问题发生时工作所在的产品和调用的API
|
||||
平台:操作系统信息,类型,版本
|
||||
|
||||
如果可能,请提供一份最小问题复现代码。
|
||||
|
||||
如果崩溃,请提供错误栈。
|
||||
|
||||
如果编译出错,请提供 cmake 版本,编译器版本,编译命令等信息。
|
||||
|
||||
-->
|
||||
|
||||
* **产品和接口**:
|
||||
* **平台**:
|
||||
* **最小代码**:
|
||||
|
||||
<!-- 请提供其他可能协助问题定位的信息 -->
|
||||
|
||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
tools/endpoints.json
|
||||
initCoverage.info
|
||||
testCoverage.info
|
||||
coverageReport/
|
||||
Testing/
|
||||
.vscode/
|
||||
ft_build/
|
||||
ut_build/
|
||||
sdk_build/
|
||||
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
dist: xenial
|
||||
sudo: require
|
||||
language: cpp
|
||||
compiler: gcc
|
||||
|
||||
install:
|
||||
- sudo apt-get install lcov libcurl4-openssl-dev libssl-dev uuid-dev libjsoncpp-dev
|
||||
|
||||
script:
|
||||
- ./unit_test.sh
|
||||
- ./generate_code_cov.sh
|
||||
- ./function_test.sh
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
7
3rdparty/CMakeLists.txt
vendored
7
3rdparty/CMakeLists.txt
vendored
@@ -44,9 +44,10 @@ endif()
|
||||
ExternalProject_Add(catch
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/catch-2.0.1.hpp
|
||||
URL_HASH MD5=9b3d2cb5c0f9532cddfbbfd0a622f0af
|
||||
DOWNLOAD_NO_EXTRACT 1
|
||||
CONFIGURE_COMMAND ""
|
||||
DOWNLOAD_COMMAND ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND
|
||||
${CMAKE_COMMAND} -E copy_if_different <DOWNLOADED_FILE> <INSTALL_DIR>/catch.hpp
|
||||
${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/catch-2.0.1.hpp <INSTALL_DIR>/catch.hpp
|
||||
)
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
2019-03-12 Version: 1.34.9
|
||||
1, add agency infomation
|
||||
2, update sdk core resources
|
||||
|
||||
2018-12-20 Version: 1.34.8
|
||||
1, Sync CDN API.
|
||||
|
||||
2018-12-11 Version: 1.34.7
|
||||
1, Sync CDN API.
|
||||
|
||||
|
||||
188
CMakeLists.txt
188
CMakeLists.txt
@@ -1,95 +1,95 @@
|
||||
#
|
||||
# Copyright 2009-2017 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.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
|
||||
file(STRINGS "VERSION" version)
|
||||
|
||||
project(alibabacloud-sdk VERSION ${version})
|
||||
|
||||
message(STATUS "Project version: ${PROJECT_VERSION}")
|
||||
|
||||
set(TARGET_OUTPUT_NAME_PREFIX "alibabacloud-sdk-" CACHE STRING "The target's output name prefix")
|
||||
option(BUILD_SHARED_LIBS "Enable shared library" ON)
|
||||
option(BUILD_UNIT_TESTS "Enable unit tests" OFF)
|
||||
option(BUILD_FUNCTION_TESTS "Enable function test" OFF)
|
||||
|
||||
set(LIB_TYPE STATIC)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(LIB_TYPE SHARED)
|
||||
add_definitions(-DALIBABACLOUD_SHARED)
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL
|
||||
PROPERTY
|
||||
USE_FOLDERS ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include(ExternalProject)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
add_subdirectory(3rdparty)
|
||||
add_subdirectory(core)
|
||||
|
||||
if(BUILD_UNIT_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test/core)
|
||||
add_subdirectory(test/httpserver)
|
||||
endif()
|
||||
|
||||
if(BUILD_FUNCTION_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test/function_test/cdn)
|
||||
add_subdirectory(test/function_test/core)
|
||||
add_subdirectory(test/function_test/ecs)
|
||||
add_subdirectory(test/function_test/nlp)
|
||||
add_subdirectory(test/function_test/rds)
|
||||
add_subdirectory(test/function_test/slb)
|
||||
add_subdirectory(test/function_test/vpc)
|
||||
endif()
|
||||
|
||||
add_subdirectory(ecs)
|
||||
add_subdirectory(slb)
|
||||
add_subdirectory(vpc)
|
||||
add_subdirectory(cdn)
|
||||
add_subdirectory(rds)
|
||||
add_subdirectory(cloudphoto)
|
||||
add_subdirectory(ess)
|
||||
add_subdirectory(tesladam)
|
||||
add_subdirectory(cms)
|
||||
add_subdirectory(afs)
|
||||
add_subdirectory(aegis)
|
||||
add_subdirectory(ehpc)
|
||||
add_subdirectory(cs)
|
||||
add_subdirectory(ccc)
|
||||
add_subdirectory(teslamaxcompute)
|
||||
add_subdirectory(push)
|
||||
add_subdirectory(csb)
|
||||
add_subdirectory(domain)
|
||||
add_subdirectory(green)
|
||||
add_subdirectory(hsm)
|
||||
add_subdirectory(dcdn)
|
||||
add_subdirectory(pvtz)
|
||||
add_subdirectory(cloudauth)
|
||||
add_subdirectory(dyvmsapi)
|
||||
add_subdirectory(drds)
|
||||
add_subdirectory(jarvis)
|
||||
add_subdirectory(scdn)
|
||||
add_subdirectory(live)
|
||||
add_subdirectory(rtc)
|
||||
add_subdirectory(chatbot)
|
||||
add_subdirectory(teslastream)
|
||||
add_subdirectory(mopen)
|
||||
add_subdirectory(mts)
|
||||
add_subdirectory(iot)
|
||||
add_subdirectory(linkface)
|
||||
add_subdirectory(ots)
|
||||
add_subdirectory(smartag)
|
||||
add_subdirectory(vod)
|
||||
add_subdirectory(ccs)
|
||||
add_subdirectory(saf)
|
||||
add_subdirectory(arms)
|
||||
add_subdirectory(lubancloud)
|
||||
add_subdirectory(alimt)
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
|
||||
file(STRINGS "VERSION" version)
|
||||
|
||||
project(alibabacloud-sdk VERSION ${version})
|
||||
|
||||
message(STATUS "Project version: ${PROJECT_VERSION}")
|
||||
|
||||
set(TARGET_OUTPUT_NAME_PREFIX "alibabacloud-sdk-" CACHE STRING "The target's output name prefix")
|
||||
option(BUILD_SHARED_LIBS "Enable shared library" ON)
|
||||
option(BUILD_TESTS "Enable tests" ON)
|
||||
|
||||
set(LIB_TYPE STATIC)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(LIB_TYPE SHARED)
|
||||
add_definitions(-DALIBABACLOUD_SHARED)
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL
|
||||
PROPERTY
|
||||
USE_FOLDERS ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include(ExternalProject)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
add_subdirectory(3rdparty)
|
||||
add_subdirectory(core)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(core-tests)
|
||||
endif()
|
||||
add_subdirectory(ecs)
|
||||
add_subdirectory(slb)
|
||||
add_subdirectory(vpc)
|
||||
add_subdirectory(cdn)
|
||||
add_subdirectory(rds)
|
||||
add_subdirectory(cloudphoto)
|
||||
add_subdirectory(ess)
|
||||
add_subdirectory(tesladam)
|
||||
add_subdirectory(cms)
|
||||
add_subdirectory(afs)
|
||||
add_subdirectory(aegis)
|
||||
add_subdirectory(ehpc)
|
||||
add_subdirectory(cs)
|
||||
add_subdirectory(ccc)
|
||||
add_subdirectory(teslamaxcompute)
|
||||
add_subdirectory(push)
|
||||
add_subdirectory(csb)
|
||||
add_subdirectory(domain)
|
||||
add_subdirectory(green)
|
||||
add_subdirectory(hsm)
|
||||
add_subdirectory(dcdn)
|
||||
add_subdirectory(pvtz)
|
||||
add_subdirectory(cloudauth)
|
||||
add_subdirectory(dyvmsapi)
|
||||
add_subdirectory(drds)
|
||||
add_subdirectory(jarvis)
|
||||
add_subdirectory(scdn)
|
||||
add_subdirectory(live)
|
||||
add_subdirectory(rtc)
|
||||
add_subdirectory(chatbot)
|
||||
add_subdirectory(teslastream)
|
||||
add_subdirectory(mopen)
|
||||
add_subdirectory(mts)
|
||||
add_subdirectory(iot)
|
||||
add_subdirectory(linkface)
|
||||
add_subdirectory(ots)
|
||||
add_subdirectory(smartag)
|
||||
add_subdirectory(vod)
|
||||
add_subdirectory(ccs)
|
||||
add_subdirectory(saf)
|
||||
add_subdirectory(arms)
|
||||
add_subdirectory(lubancloud)
|
||||
add_subdirectory(alimt)
|
||||
add_subdirectory(xspace)
|
||||
4
LICENSE
4
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
Copyright 2009-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.
|
||||
@@ -10,4 +10,4 @@ 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.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
limitations under the License.
|
||||
|
||||
244
README.md
244
README.md
@@ -1,81 +1,163 @@
|
||||
# Alibaba Cloud C++ Software Development Kit
|
||||
[中文文档](./README_zh.md)
|
||||
|
||||
The Alibaba Cloud C++ Software Development Kit (SDK) allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), and CloudMonitor. You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.
|
||||
|
||||
This document introduces how to obtain and call Alibaba Cloud C++ SDK.
|
||||
|
||||
If you have any problem while using C++ SDK, please join the **DingTalk group: 11771185 (the official SDK customer service group of Alibaba Cloud)** for consultation.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- To use Alibaba Cloud C++ SDK, you must have an Alibaba Cloud account and an AccessKey.
|
||||
|
||||
The AccessKey is required when initializing the client. You can create an AccessKey in the Alibaba Cloud console. For more information, see [Create an AccessKey](https://usercenter.console.aliyun.com/?spm=5176.doc52740.2.3.QKZk8w#/manage/ak).
|
||||
|
||||
>**Note:** To increase the security of your account, we recommend that you use the AccessKey of the RAM user to access Alibaba Cloud services.
|
||||
|
||||
- To use Alibaba Cloud C++ SDK to access the APIs of a product, you must first activate the product on the [Alibaba Cloud console](https://home.console.aliyun.com/?spm=5176.doc52740.2.4.QKZk8w) if required.
|
||||
|
||||
|
||||
## Install C++ SDK
|
||||
|
||||
1. Install third-party libraries on the Linux platform, including `libcurl`, `libopenssl`, `libuuid`, and `libjsoncpp`.
|
||||
|
||||
- Run the following commands on the Redhat/Fedora system to install third-party libraries.
|
||||
```
|
||||
sudo dnf install libcurl-devel openssl-devel libuuid-devel libjsoncpp-devel
|
||||
```
|
||||
- Run the following commands on the Debian/Ubuntu system to install third-party libraries.
|
||||
```
|
||||
sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev libjsoncpp-dev
|
||||
```
|
||||
2. Run the following commands to clone source codes from GitHub.
|
||||
|
||||
```
|
||||
git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
|
||||
```
|
||||
|
||||
## Use the C++ SDK
|
||||
|
||||
Before using C++ SDK, you must first configure the preprocessor to define `ALIBABACLOUD_SHARED` to achieve dynamic linking with Alibaba Cloud C++ SDK shared libraries. Then you must create a client instance, specify the region of cloud services and provide authentication parameters before sending API requests.
|
||||
|
||||
The following code shows how to call the [DescribeInstances](~~25506~~) API of ECS to query detailed information of all ECS instances in a specific region.
|
||||
|
||||
```
|
||||
#include <iostream>
|
||||
#include <alibabacloud/core/AlibabaCloud.h>
|
||||
#include <alibabacloud/ecs/EcsClient.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Ecs;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Initialize the SDK
|
||||
AlibabaCloud::InitializeSdk();
|
||||
|
||||
// Configure the ECS instance
|
||||
ClientConfiguration configuration("<your-region-id>");
|
||||
EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
|
||||
|
||||
// Create an API request and set parameters
|
||||
Model::DescribeInstancesRequest request;
|
||||
request.setPageSize(10);
|
||||
|
||||
auto outcome = client.describeInstances(request);
|
||||
if (!outcome.isSuccess())
|
||||
{
|
||||
// Handle exceptions
|
||||
std::cout << outcome.error().errorCode() << std::endl;
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
|
||||
|
||||
// Close the SDK
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
# Alibaba Cloud C++ Software Development Kit
|
||||
[中文文档](./README_zh.md)
|
||||
|
||||
[](https://travis-ci.org/aliyun/aliyun-openapi-cpp-sdk)
|
||||
[](https://codecov.io/gh/aliyun/aliyun-openapi-cpp-sdk)
|
||||
|
||||
The Alibaba Cloud C++ Software Development Kit (SDK) allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), and CloudMonitor. You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.
|
||||
|
||||
This document introduces how to obtain and call Alibaba Cloud C++ SDK.
|
||||
|
||||
If you have any problem while using C++ SDK, please submit an [issue](https://github.com/aliyun/aliyun-openapi-cpp-sdk/issues/new).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- To use Alibaba Cloud C++ SDK, you must have an Alibaba Cloud account and an AccessKey.
|
||||
|
||||
The AccessKey is required when initializing the client. You can create an AccessKey in the Alibaba Cloud console. For more information, see [Create an AccessKey](https://usercenter.console.aliyun.com/?spm=5176.doc52740.2.3.QKZk8w#/manage/ak).
|
||||
|
||||
>**Note:** To increase the security of your account, we recommend that you use the AccessKey of the RAM user to access Alibaba Cloud services.
|
||||
|
||||
- To use Alibaba Cloud C++ SDK to access the APIs of a product, you must first activate the product on the [Alibaba Cloud console](https://home.console.aliyun.com/?spm=5176.doc52740.2.4.QKZk8w) if required.
|
||||
|
||||
- C++11 supported compiler installed
|
||||
- Windows: Visual Studio 2015 or newer
|
||||
- Linux: GCC 4.9 or newer
|
||||
- CMake 3.0 or newer
|
||||
- 4G memory or more
|
||||
|
||||
## Install C++ SDK from source code
|
||||
|
||||
|
||||
### Linux
|
||||
|
||||
1. Install third-party libraries on the Linux platform, including `libcurl`, `libopenssl`, `libuuid`, and `libjsoncpp`.
|
||||
|
||||
- Run the following commands on the `Redhat/Fedora` system
|
||||
```
|
||||
sudo dnf install libcurl-devel openssl-devel libuuid-devel libjsoncpp-devel
|
||||
```
|
||||
- Run the following commands on the `Debian/Ubuntu` system
|
||||
```
|
||||
sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev libjsoncpp-dev
|
||||
```
|
||||
2. Run the following commands to clone source codes from GitHub.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
|
||||
```
|
||||
|
||||
3. Build and install SDK
|
||||
|
||||
- Manually build and install
|
||||
|
||||
```bash
|
||||
cd aliyun-openapi-cpp-sdk
|
||||
mkdir sdk_build
|
||||
cd sdk_build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
- Or you may do this with `easyinstall.sh` in the source directory
|
||||
|
||||
```shell
|
||||
cd aliyun-openapi-cpp-sdk
|
||||
sudo sh easyinstall.sh
|
||||
```
|
||||
|
||||
**The C++ SDK will be installed to `/usr`.**
|
||||
|
||||
### windows
|
||||
|
||||
1. Install [perl](https://www.perl.org/get.html#win32).
|
||||
|
||||
2. Run the following command to clone code from Github via git-bash:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
|
||||
```
|
||||
|
||||
2. Build Visual Studio solution
|
||||
|
||||
- Change directory to source code and make directory sdk_build
|
||||
|
||||
- Open CMake UI and
|
||||
|
||||
- `Browse Source` to open source code directory.
|
||||
|
||||
- `Browse build` to open the created sdk_build directory
|
||||
|
||||
- `Configure`
|
||||
|
||||
- `Generate`
|
||||
|
||||
3. Build and Install C++ SDK
|
||||
|
||||
- Open `aliyun-openapi-cpp-sdk\\sdk_build\\alibabacloud-sdk.sln` with Visual Studio
|
||||
|
||||
- Select `Release`
|
||||
|
||||
- Check INSTALL option from Build -> Configuration Manager
|
||||
|
||||
- Build->Build Solutions to build.
|
||||
|
||||
**SDK will be installed to `C:\Program File (x86)\alibabacloud-sdk`**
|
||||
|
||||
|
||||
## Use the C++ SDK
|
||||
|
||||
Before using C++ SDK, you must first configure the preprocessor to define `ALIBABACLOUD_SHARED` to achieve dynamic linking with Alibaba Cloud C++ SDK shared libraries. Then you must create a client instance, specify the region of cloud services and provide authentication parameters before sending API requests.
|
||||
|
||||
The following code shows how to call the [DescribeInstances](~~25506~~) API of ECS to query detailed information of all ECS instances in a specific region.
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include <alibabacloud/core/AlibabaCloud.h>
|
||||
#include <alibabacloud/ecs/EcsClient.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Ecs;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// Initialize the SDK
|
||||
AlibabaCloud::InitializeSdk();
|
||||
|
||||
// Configure the ECS instance
|
||||
ClientConfiguration configuration("<your-region-id>");
|
||||
EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
|
||||
|
||||
// Create an API request and set parameters
|
||||
Model::DescribeInstancesRequest request;
|
||||
request.setPageSize(10);
|
||||
|
||||
auto outcome = client.describeInstances(request);
|
||||
if (!outcome.isSuccess()) {
|
||||
// Handle exceptions
|
||||
std::cout << outcome.error().errorCode() << std::endl;
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
|
||||
|
||||
// Close the SDK
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Copy the above to ecs_test.cc, then build with the following command.
|
||||
|
||||
```bash
|
||||
~$ g++ -o ecstest ecs_test.cc --std=c++11 -lalibabacloud-sdk-core -l alibabacloud-sdk-ecs
|
||||
~$ ./ecstest
|
||||
# Result or error message will be shown here.
|
||||
~$
|
||||
```
|
||||
|
||||
**More [examples](https://github.com/aliyun/aliyun-openapi-cpp-sdk/tree/master/examples)**
|
||||
|
||||
## LICENSE
|
||||
Please refer to [LICENSE](https://github.com/aliyun/aliyun-openapi-cpp-sdk/blob/master/LICENSE) (Apache 2.0 LICENSE).
|
||||
|
||||
135
README_zh.md
135
README_zh.md
@@ -1,10 +1,13 @@
|
||||
# 阿里云开发者C++工具套件
|
||||
|
||||
[](https://travis-ci.org/aliyun/aliyun-openapi-cpp-sdk)
|
||||
[](https://codecov.io/gh/aliyun/aliyun-openapi-cpp-sdk)
|
||||
|
||||
欢迎使用阿里云开发者工具套件(SDK)。
|
||||
|
||||
适用于阿里云的 C++ SDK 提供了一组现代化的 C++(C++ 11 或更高版本)接口,让您不用复杂编程即可访问云服务器、云监控等多个阿里云服务。
|
||||
|
||||
如果您在使用SDK的过程中遇到任何问题,欢迎前往[阿里云SDK问答社区](https://yq.aliyun.com/tags/type_ask-tagid_23350)提问,提问前请阅读[提问引导](https://help.aliyun.com/document_detail/93957.html)。亦可在当前GitHub提交Issues。
|
||||
如果您在使用SDK的过程中遇到任何问题,欢迎前往[阿里云SDK问答社区](https://yq.aliyun.com/tags/type_ask-tagid_23350)提问,提问前请阅读[提问引导](https://help.aliyun.com/document_detail/93957.html)。亦可在当前 GitHub [提交 Issues](https://github.com/aliyun/aliyun-openapi-cpp-sdk/issues/new)。
|
||||
|
||||
完成本文档中的操作开始使用 C++ SDK。
|
||||
|
||||
@@ -19,8 +22,11 @@
|
||||
* 开通了云产品服务。有些云产品如对象存储(OSS)需要先在[阿里云控制台](https://home.console.aliyun.com)开通服务。
|
||||
|
||||
* 安装支持 C++ 11 或更高版本的编译器:
|
||||
* Visual Studio 2015 或以上版本
|
||||
* 或 GCC 4.9 或以上版本
|
||||
* Windows: Visual Studio 2015 或以上版本
|
||||
* Linux: GCC 4.9 或以上版本
|
||||
|
||||
* 安装 CMake 3.0 或以上版本
|
||||
* 建议 4G 或以上内存
|
||||
|
||||
## 从源代码构建 SDK
|
||||
|
||||
@@ -33,43 +39,77 @@
|
||||
git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git
|
||||
```
|
||||
|
||||
2. 安装 cmake 3.0 或以上版本,进入 SDK 创建生成必要的构建文件
|
||||
2. 创建生成必要的构建文件
|
||||
|
||||
```
|
||||
```bash
|
||||
cd <path/to/aliyun-openapi-cpp-sdk>
|
||||
mkdir sdk_build
|
||||
cd sdk_build
|
||||
cmake ..
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
进入 sdk_build 目录使用 Visual Studio 打开 alibabacloud-sdk.sln 生成解决方案。
|
||||
|
||||
或者您也可以使用 VS 的开发人员命令提示符,执行以下命令编译并安装:
|
||||
|
||||
```
|
||||
msbuild ALL_BUILD.vcxproj
|
||||
msbuild INSTALL.vcxproj
|
||||
```
|
||||
|
||||
### Linux
|
||||
|
||||
要在 Linux 平台进行编译, 您必须安装依赖的外部库文件 libcurl、libopenssl、libuuid、libjsoncpp, 通常情况下,系统的包管理器中的会有提供。
|
||||
|
||||
例如:在基于 Redhat / Fedora 的系统上安装这些软件包
|
||||
|
||||
```
|
||||
```bash
|
||||
sudo dnf install libcurl-devel openssl-devel libuuid-devel libjsoncpp-devel
|
||||
```
|
||||
|
||||
在基于 Debian/Ubuntu 的系统
|
||||
```bash
|
||||
sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev libjsoncpp-dev
|
||||
```
|
||||
|
||||
在安装依赖库后执行以下命令编译并安装:
|
||||
|
||||
手动编译安装
|
||||
```bash
|
||||
cd aliyun-openapi-cpp-sdk
|
||||
mkdir sdk_build
|
||||
cd sdk_build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
make
|
||||
sudo make install
|
||||
|
||||
或者通过 `easyinstall.sh`一键式安装
|
||||
|
||||
```bash
|
||||
cd aliyun-openapi-cpp-sdk
|
||||
sudo sh easyinstall.sh
|
||||
```
|
||||
|
||||
**C++ SDK 将被安装在 `/usr`.**
|
||||
|
||||
|
||||
### Windows
|
||||
|
||||
通过 cmake 生成 Visual Studio 解决方案:
|
||||
|
||||
在 aliyun-openapi-cpp-sdk 下创建 sdk_build 目录
|
||||
|
||||
打开 cmake-ui 选择源代码目录和构建目录,点击 `配置(configure)` 和 `生成(generate)` 构建 VS 解决方案。
|
||||
|
||||
进入 sdk_build 目录使用 Visual Studio 打开 alibabacloud-sdk.sln 解决方案。
|
||||
|
||||
选择构建 `Release` 输出,并打开配置管理器勾选 `INSTALL`。
|
||||
|
||||
构建 -> 生成解决方案。
|
||||
|
||||
或者您也可以使用 VS 的开发人员命令提示符,执行以下命令编译并安装:
|
||||
|
||||
```
|
||||
msbuild ALL_BUILD.vcxproj
|
||||
msbuild INSTALL.vcxproj
|
||||
```
|
||||
|
||||
**C++ SDK 将安装在 `C:\Program File (x86)\alibabacloud-sdk` 目录**
|
||||
|
||||
**注意:请以管理员身份运行 Visual Studio,否则无法安装 SDK**
|
||||
|
||||
## 如何使用 C++ SDK
|
||||
|
||||
在调用 C++ SDK时,您首先需要配置预处理器定义 ALIBABACLOUD_SHARED 以引用阿里云 C++ SDK 的共享库,然后通过创建 Client 实例提供身份验证,并指定云服务的地域,然后发送API请求。
|
||||
@@ -86,35 +126,46 @@ sudo make install
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Ecs;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// 初始化 SDK
|
||||
AlibabaCloud::InitializeSdk();
|
||||
int main(int argc, char** argv) {
|
||||
// 初始化 SDK
|
||||
AlibabaCloud::InitializeSdk();
|
||||
|
||||
// 配置 ecs 实例
|
||||
ClientConfiguration configuration("<your-region-id>");
|
||||
EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
|
||||
// 配置 ecs 实例
|
||||
ClientConfiguration configuration("<your-region-id>");
|
||||
EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
|
||||
|
||||
// 创建API请求并设置参数
|
||||
Model::DescribeInstancesRequest request;
|
||||
request.setPageSize(10);
|
||||
// 创建API请求并设置参数
|
||||
Model::DescribeInstancesRequest request;
|
||||
request.setPageSize(10);
|
||||
|
||||
auto outcome = client.describeInstances(request);
|
||||
if (!outcome.isSuccess())
|
||||
{
|
||||
// 异常处理
|
||||
std::cout << outcome.error().errorCode() << std::endl;
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
|
||||
auto outcome = client.describeInstances(request);
|
||||
if (!outcome.isSuccess()) {
|
||||
// 异常处理
|
||||
std::cout << outcome.error().errorCode() << std::endl;
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 关闭 SDK
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return 0;
|
||||
std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
|
||||
|
||||
// 关闭 SDK
|
||||
AlibabaCloud::ShutdownSdk();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
复制上述文件到 ecs_test.cc。
|
||||
|
||||
Linux 下
|
||||
|
||||
```bash
|
||||
~$ g++ -o ecstest ecs_test.cc --std=c++11 -lalibabacloud-sdk-core -l alibabacloud-sdk-ecs
|
||||
~$ ./ecstest
|
||||
# 结果或错误返回将在此展示
|
||||
~$
|
||||
```
|
||||
|
||||
**更多 [例程](https://github.com/aliyun/aliyun-openapi-cpp-sdk/tree/master/examples) 请(参考)[https://github.com/aliyun/aliyun-openapi-cpp-sdk/blob/master/examples/README_zh.md]**
|
||||
|
||||
## 许可协议
|
||||
请参阅 LICENSE 文件(Apache 2.0 许可证)。
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
add_executable(core-tests
|
||||
main.cc
|
||||
httpmessage.cc
|
||||
signer.cc
|
||||
url.cc )
|
||||
|
||||
set_target_properties(core-tests
|
||||
PROPERTIES
|
||||
OUTPUT_NAME ${TARGET_OUTPUT_NAME_PREFIX}core-tests
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
target_link_libraries(core-tests
|
||||
core
|
||||
)
|
||||
|
||||
ExternalProject_Get_Property(catch INSTALL_DIR)
|
||||
set(catch_install_dir ${INSTALL_DIR})
|
||||
add_dependencies(core-tests catch)
|
||||
|
||||
target_include_directories(core-tests
|
||||
PRIVATE ${catch_install_dir}
|
||||
${CMAKE_SOURCE_DIR}/core/include
|
||||
)
|
||||
|
||||
add_test(NAME core-tests COMMAND core-tests)
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2017 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <catch.hpp>
|
||||
#include <alibabacloud/core/HttpRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
TEST_CASE("testHttpMessage")
|
||||
{
|
||||
const std::string data = "Thu, 19 Oct 2017 04:38:27 GMT";
|
||||
HttpRequest r;
|
||||
r.setHeader("accept", "application/xml");
|
||||
r.setHeader("Accept", "application/json");
|
||||
r.setHeader("Date", data);
|
||||
|
||||
REQUIRE(r.headers().size() == 2);
|
||||
REQUIRE(r.header("accept") == "application/json");
|
||||
REQUIRE(r.header(HttpMessage::KnownHeader::Date) == data);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2017 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2017 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <catch.hpp>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
TEST_CASE("testHmacSha1Signer")
|
||||
{
|
||||
HmacSha1Signer sig;
|
||||
std::string sign = sig.generate("GET&%2F&AccessKeyId%3Dtestid%26Action%3DDescribeRegions"
|
||||
"%26Format%3DXML%26RegionId%3Dregion1%26SignatureMethod%3DHMAC-SHA1"
|
||||
"%26SignatureNonce%3DNwDAxvLU6tFE0DVb%26SignatureVersion%3D1.0"
|
||||
"%26TimeStamp%3D2012-12-26T10%253A33%253A56Z%26Version%3D2013-01-10",
|
||||
"testsecret&");
|
||||
REQUIRE("axE3FUHgDyfm9/+Iep0HpZXrRwE=" == sign);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2017 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <catch.hpp>
|
||||
#include <alibabacloud/core/Url.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
TEST_CASE("testUrl")
|
||||
{
|
||||
const std::string src = "abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1";
|
||||
Url url;
|
||||
url.setScheme("abc");
|
||||
url.setUserName("username");
|
||||
url.setPassword("password");
|
||||
url.setHost("example.com");
|
||||
url.setPath("/path/data");
|
||||
url.setPort(123);
|
||||
url.setQuery("key=value&key2=value2");
|
||||
url.setFragment("fragid1");
|
||||
REQUIRE(url.toString() == src);
|
||||
|
||||
url.clear();
|
||||
url.fromString(src);
|
||||
REQUIRE(url.scheme() == "abc");
|
||||
REQUIRE(url.userName() == "username");
|
||||
REQUIRE(url.password() == "password");
|
||||
REQUIRE(url.host() == "example.com");
|
||||
REQUIRE(url.path() == "/path/data");
|
||||
REQUIRE(url.port() == 123);
|
||||
REQUIRE(url.query() == "key=value&key2=value2");
|
||||
REQUIRE(url.fragment() == "fragid1");
|
||||
|
||||
Url newurl = url;
|
||||
REQUIRE(newurl == url);
|
||||
}
|
||||
|
||||
TEST_CASE("testUrl2")
|
||||
{
|
||||
const std::string src = "http://oss.example.com";
|
||||
Url url(src);
|
||||
REQUIRE(url.scheme() == "http");
|
||||
REQUIRE(url.userName() == "");
|
||||
REQUIRE(url.password() == "");
|
||||
REQUIRE(url.host() == "oss.example.com");
|
||||
REQUIRE(url.path() == "/");
|
||||
REQUIRE(url.port() == -1);
|
||||
REQUIRE(url.query() == "");
|
||||
REQUIRE(url.fragment() == "");
|
||||
}
|
||||
@@ -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,6 +14,15 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# coverage option
|
||||
OPTION (ENABLE_COVERAGE "Use gcov" OFF)
|
||||
MESSAGE(STATUS ENABLE_COVERAGE=${ENABLE_COVERAGE})
|
||||
IF(ENABLE_COVERAGE)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
ENDIF()
|
||||
|
||||
configure_file(src/Config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/alibabacloud/core/Config.h @ONLY)
|
||||
|
||||
set(core_public_header
|
||||
@@ -120,7 +129,7 @@ set(core_src
|
||||
src/sts/StsClient.cc
|
||||
src/sts/StsRequest.cc
|
||||
src/sts/model/AssumeRoleRequest.cc
|
||||
src/sts/model/AssumeRoleResult.cc
|
||||
src/sts/model/AssumeRoleResult.cc
|
||||
src/sts/model/GetCallerIdentityRequest.cc
|
||||
src/sts/model/GetCallerIdentityResult.cc
|
||||
)
|
||||
|
||||
@@ -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,16 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ALIBABACLOUD_H_
|
||||
#define ALIBABACLOUD_CORE_ALIBABACLOUD_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_ALIBABACLOUD_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_ALIBABACLOUD_H_
|
||||
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
ALIBABACLOUD_CORE_EXPORT void InitializeSdk();
|
||||
ALIBABACLOUD_CORE_EXPORT bool IsSdkInitialized();
|
||||
ALIBABACLOUD_CORE_EXPORT void ShutdownSdk();
|
||||
}
|
||||
namespace AlibabaCloud {
|
||||
ALIBABACLOUD_CORE_EXPORT void InitializeSdk();
|
||||
ALIBABACLOUD_CORE_EXPORT bool IsSdkInitialized();
|
||||
ALIBABACLOUD_CORE_EXPORT void ShutdownSdk();
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_ALIBABACLOUD_H_
|
||||
|
||||
@@ -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,25 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ASYNCCALLERCONTEXT_H_
|
||||
#define ALIBABACLOUD_CORE_ASYNCCALLERCONTEXT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_ASYNCCALLERCONTEXT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_ASYNCCALLERCONTEXT_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
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_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_ASYNCCALLERCONTEXT_H_
|
||||
|
||||
@@ -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,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
#define ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -24,26 +24,25 @@
|
||||
#include "NetworkProxy.h"
|
||||
#include "Signer.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT ClientConfiguration
|
||||
{
|
||||
public:
|
||||
explicit ClientConfiguration(const std::string ®ionId = "cn-hangzhou",
|
||||
const NetworkProxy &proxy = NetworkProxy());
|
||||
~ClientConfiguration();
|
||||
namespace AlibabaCloud {
|
||||
class ALIBABACLOUD_CORE_EXPORT ClientConfiguration {
|
||||
public:
|
||||
explicit ClientConfiguration(const std::string ®ionId = "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 ®ionId);
|
||||
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 ®ionId);
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
private:
|
||||
std::string endpoint_;
|
||||
NetworkProxy proxy_;
|
||||
std::string regionId_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "AsyncCallerContext.h"
|
||||
#include "ClientConfiguration.h"
|
||||
#include "CoreExport.h"
|
||||
@@ -26,38 +28,50 @@
|
||||
#include "CommonResponse.h"
|
||||
#include "CredentialsProvider.h"
|
||||
|
||||
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;
|
||||
|
||||
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();
|
||||
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;
|
||||
|
||||
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;
|
||||
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();
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
private:
|
||||
std::string canonicalizedQuery(const std::map <std::string, std::string> ¶ms)const;
|
||||
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const;
|
||||
protected:
|
||||
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;
|
||||
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
private:
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,52 +14,53 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
#include "ServiceRequest.h"
|
||||
#include "HttpRequest.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT CommonRequest : public ServiceRequest
|
||||
{
|
||||
public:
|
||||
enum RequestPattern
|
||||
{
|
||||
RpcPattern,
|
||||
RoaPattern
|
||||
};
|
||||
namespace AlibabaCloud {
|
||||
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;
|
||||
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;
|
||||
|
||||
private:
|
||||
std::string domain_;
|
||||
RequestPattern requestPattern_;
|
||||
ParameterCollection queryParams_;
|
||||
ParameterCollection headerParams_;
|
||||
HttpRequest::Method httpMethod_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
protected:
|
||||
using ServiceRequest::product;
|
||||
|
||||
private:
|
||||
std::string domain_;
|
||||
RequestPattern requestPattern_;
|
||||
ParameterCollection queryParams_;
|
||||
ParameterCollection headerParams_;
|
||||
HttpRequest::Method httpMethod_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,25 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
#define ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT CommonResponse
|
||||
{
|
||||
public:
|
||||
CommonResponse();
|
||||
explicit CommonResponse(const std::string &payload);
|
||||
~CommonResponse();
|
||||
namespace AlibabaCloud {
|
||||
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;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
private:
|
||||
std::string payload_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
|
||||
@@ -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,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CORECLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_CORECLIENT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "ClientConfiguration.h"
|
||||
#include "CoreExport.h"
|
||||
#include "HttpClient.h"
|
||||
@@ -28,27 +29,31 @@
|
||||
#include "ServiceRequest.h"
|
||||
#include "Runnable.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT CoreClient
|
||||
{
|
||||
public:
|
||||
CoreClient(const std::string & servicename, const ClientConfiguration &configuration);
|
||||
virtual ~CoreClient();
|
||||
namespace AlibabaCloud {
|
||||
class ALIBABACLOUD_CORE_EXPORT CoreClient {
|
||||
public:
|
||||
CoreClient(const std::string & servicename,
|
||||
const ClientConfiguration &configuration);
|
||||
virtual ~CoreClient();
|
||||
|
||||
ClientConfiguration configuration()const;
|
||||
std::string serviceName()const;
|
||||
protected:
|
||||
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
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_
|
||||
|
||||
@@ -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,19 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COREEXPORT_H_
|
||||
#define ALIBABACLOUD_CORE_COREEXPORT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_COREEXPORT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_COREEXPORT_H_
|
||||
|
||||
#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_
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_COREEXPORT_H_
|
||||
|
||||
@@ -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,34 +14,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CREDENTIAL_H_
|
||||
#define ALIBABACLOUD_CORE_CREDENTIAL_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_CREDENTIALS_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_CREDENTIALS_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT Credentials
|
||||
{
|
||||
public:
|
||||
Credentials(const std::string &accessKeyId,
|
||||
const std::string &accessKeySecret,
|
||||
const std::string &sessionToken="");
|
||||
~Credentials();
|
||||
namespace AlibabaCloud {
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_CREDENTIAL_H_
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_CREDENTIALS_H_
|
||||
|
||||
@@ -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,23 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_CREDENTIALSPROVIDER_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_CREDENTIALSPROVIDER_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_CREDENTIALSPROVIDER_H_
|
||||
|
||||
#include "CoreExport.h"
|
||||
#include "Credentials.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT CredentialsProvider
|
||||
{
|
||||
public:
|
||||
CredentialsProvider() = default;
|
||||
virtual ~CredentialsProvider() = default;
|
||||
namespace AlibabaCloud {
|
||||
class ALIBABACLOUD_CORE_EXPORT CredentialsProvider {
|
||||
public:
|
||||
CredentialsProvider() = default;
|
||||
virtual ~CredentialsProvider() = default;
|
||||
virtual Credentials getCredentials() = 0;
|
||||
|
||||
virtual Credentials getCredentials() = 0;
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_CREDENTIALSPROVIDER_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,57 +14,58 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
|
||||
|
||||
#include <alibabacloud/core/location/LocationClient.h>
|
||||
#include <alibabacloud/core/CoreClient.h>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <alibabacloud/core/location/LocationClient.h>
|
||||
#include <alibabacloud/core/CoreClient.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT EndpointProvider
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, std::string> EndpointOutcome;
|
||||
namespace AlibabaCloud {
|
||||
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();
|
||||
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);
|
||||
|
||||
EndpointOutcome getEndpoint();
|
||||
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;
|
||||
};
|
||||
EndpointProvider(
|
||||
const Credentials &credentials,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::string ®ionId,
|
||||
const std::string &product,
|
||||
const std::string &serviceCode = std::string(),
|
||||
int durationSeconds = 3600);
|
||||
~EndpointProvider();
|
||||
|
||||
EndpointOutcome loadRemoteEndpoint();
|
||||
bool checkExpiry()const;
|
||||
bool loadInternalProductsInfo();
|
||||
std::string internalEndpoint(const std::string regionId, const std::string product);
|
||||
EndpointOutcome getEndpoint();
|
||||
using LocationClient::describeEndpoints;
|
||||
|
||||
std::mutex cachedMutex_;
|
||||
std::string cachedEndpoint_;
|
||||
std::shared_ptr<Location::LocationClient> locationClient_;
|
||||
int durationSeconds_;
|
||||
std::chrono::system_clock::time_point expiry_;
|
||||
std::string regionId_;
|
||||
std::string product_;
|
||||
std::string serviceCode_;
|
||||
std::list<Product> internalProductsInfo_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
EndpointOutcome loadRemoteEndpoint();
|
||||
bool checkExpiry()const;
|
||||
|
||||
bool loadLocalProductsInfo();
|
||||
std::string localEndpoint(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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
|
||||
|
||||
@@ -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,35 +14,37 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ERROR_H_
|
||||
#define ALIBABACLOUD_CORE_ERROR_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_ERROR_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_ERROR_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT Error
|
||||
{
|
||||
public:
|
||||
Error() = default;
|
||||
Error(std::string code, const std::string message);
|
||||
~Error() = default;
|
||||
namespace AlibabaCloud {
|
||||
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;
|
||||
std::string detail() 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);
|
||||
void setDetail(const std::string& detail);
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_ERROR_H_
|
||||
private:
|
||||
std::string errorCode_;
|
||||
std::string message_;
|
||||
std::string host_;
|
||||
std::string requestId_;
|
||||
std::string detail_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_ERROR_H_
|
||||
|
||||
@@ -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,28 +14,28 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_GLOBAL_H_
|
||||
#define ALIBABACLOUD_CORE_GLOBAL_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_GLOBAL_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_GLOBAL_H_
|
||||
|
||||
#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_
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_GLOBAL_H_
|
||||
|
||||
@@ -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,21 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
#define ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
|
||||
#include "Signer.h"
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT HmacSha1Signer : public Signer
|
||||
{
|
||||
public:
|
||||
HmacSha1Signer();
|
||||
~HmacSha1Signer();
|
||||
|
||||
virtual std::string generate(const std::string &src, const std::string &secret)const override;
|
||||
};
|
||||
}
|
||||
namespace AlibabaCloud {
|
||||
class ALIBABACLOUD_CORE_EXPORT HmacSha1Signer : public Signer {
|
||||
public:
|
||||
HmacSha1Signer();
|
||||
~HmacSha1Signer();
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
std::string generate(const std::string &src,
|
||||
const std::string &secret) const override;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
|
||||
@@ -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,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_HTTPCLIENT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPCLIENT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPCLIENT_H_
|
||||
|
||||
#include <alibabacloud/core/HttpRequest.h>
|
||||
#include <alibabacloud/core/HttpResponse.h>
|
||||
@@ -23,21 +23,20 @@
|
||||
#include <alibabacloud/core/Outcome.h>
|
||||
#include <alibabacloud/core/Error.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class HttpClient
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, HttpResponse> HttpResponseOutcome;
|
||||
namespace AlibabaCloud {
|
||||
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_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) = 0;
|
||||
NetworkProxy proxy()const;
|
||||
void setProxy(const NetworkProxy &proxy);
|
||||
|
||||
private:
|
||||
NetworkProxy proxy_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPCLIENT_H_
|
||||
|
||||
@@ -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,69 +14,69 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPMESSAGE_H_
|
||||
#define ALIBABACLOUD_CORE_HTTPMESSAGE_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPMESSAGE_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPMESSAGE_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
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
|
||||
};
|
||||
namespace AlibabaCloud {
|
||||
class ALIBABACLOUD_CORE_EXPORT HttpMessage {
|
||||
private:
|
||||
struct ALIBABACLOUD_CORE_EXPORT nocaseLess {
|
||||
bool operator() (const std::string & s1, const std::string & s2) const;
|
||||
};
|
||||
|
||||
typedef std::string HeaderNameType;
|
||||
typedef std::string HeaderValueType;
|
||||
typedef std::map<HeaderNameType, HeaderValueType, nocaseLess> HeaderCollection;
|
||||
public:
|
||||
enum KnownHeader {
|
||||
Accept,
|
||||
AcceptCharset,
|
||||
AcceptEncoding,
|
||||
AcceptLanguage,
|
||||
Authorization,
|
||||
Connection,
|
||||
ContentLength,
|
||||
ContentMD5,
|
||||
ContentType,
|
||||
Date,
|
||||
Host,
|
||||
Server,
|
||||
UserAgent
|
||||
};
|
||||
|
||||
HttpMessage(const HttpMessage &other);
|
||||
HttpMessage(HttpMessage &&other);
|
||||
HttpMessage& operator=(const HttpMessage &other);
|
||||
HttpMessage& operator=(HttpMessage &&other);
|
||||
virtual ~HttpMessage();
|
||||
typedef std::string HeaderNameType;
|
||||
typedef std::string HeaderValueType;
|
||||
typedef std::map<HeaderNameType, HeaderValueType, nocaseLess>
|
||||
HeaderCollection;
|
||||
|
||||
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_
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPMESSAGE_H_
|
||||
|
||||
@@ -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,40 +14,38 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_HTTPREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include "HttpMessage.h"
|
||||
#include "Url.h"
|
||||
|
||||
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();
|
||||
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();
|
||||
|
||||
Method method()const;
|
||||
void setMethod(Method method);
|
||||
void setUrl(const Url &url);
|
||||
Url url()const;
|
||||
private:
|
||||
Method method_;
|
||||
Url url_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Method method()const;
|
||||
void setMethod(Method method);
|
||||
void setUrl(const Url &url);
|
||||
Url url()const;
|
||||
|
||||
private:
|
||||
Method method_;
|
||||
Url url_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPREQUEST_H_
|
||||
|
||||
@@ -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,30 +14,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
#define ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
#include "HttpMessage.h"
|
||||
#include "HttpRequest.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT HttpResponse : public HttpMessage
|
||||
{
|
||||
public:
|
||||
HttpResponse();
|
||||
explicit HttpResponse(const HttpRequest & request);
|
||||
~HttpResponse();
|
||||
namespace AlibabaCloud {
|
||||
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;
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
private:
|
||||
int statusCode_;
|
||||
HttpRequest request_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
|
||||
@@ -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,21 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
#define ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
|
||||
#include "BasicSessionCredentials.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class InstanceProfileCredentials : public BasicSessionCredentials
|
||||
{
|
||||
public:
|
||||
InstanceProfileCredentials();
|
||||
~InstanceProfileCredentials();
|
||||
namespace AlibabaCloud {
|
||||
class InstanceProfileCredentials : public BasicSessionCredentials {
|
||||
public:
|
||||
InstanceProfileCredentials();
|
||||
~InstanceProfileCredentials();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
private:
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
|
||||
@@ -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,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALSPROVIDER_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALSPROVIDER_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALSPROVIDER_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
@@ -23,28 +23,30 @@
|
||||
#include <string>
|
||||
#include "CredentialsProvider.h"
|
||||
#include "Credentials.h"
|
||||
#include "../src/EcsMetadataFetcher.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class EcsMetadataFetcher;
|
||||
class ALIBABACLOUD_CORE_EXPORT InstanceProfileCredentialsProvider : public CredentialsProvider
|
||||
{
|
||||
public:
|
||||
InstanceProfileCredentialsProvider(const std::string &roleName, int durationSeconds = 3600);
|
||||
~InstanceProfileCredentialsProvider();
|
||||
namespace AlibabaCloud {
|
||||
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;
|
||||
std::string roleName()const;
|
||||
Credentials getCredentials() override;
|
||||
using EcsMetadataFetcher::roleName;
|
||||
using EcsMetadataFetcher::setRoleName;
|
||||
using EcsMetadataFetcher::getMetadata;
|
||||
|
||||
private:
|
||||
void loadCredentials();
|
||||
bool checkExpiry()const;
|
||||
private:
|
||||
void loadCredentials();
|
||||
bool checkExpiry()const;
|
||||
|
||||
std::mutex cachedMutex_;
|
||||
Credentials cachedCredentials_;
|
||||
int durationSeconds_;
|
||||
std::chrono::system_clock::time_point expiry_;
|
||||
EcsMetadataFetcher *fetcher_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
std::mutex cachedMutex_;
|
||||
Credentials cachedCredentials_;
|
||||
int durationSeconds_;
|
||||
std::chrono::system_clock::time_point expiry_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALSPROVIDER_H_
|
||||
|
||||
@@ -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,46 +14,44 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_NETWORKPROXY_H_
|
||||
#define ALIBABACLOUD_CORE_NETWORKPROXY_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_NETWORKPROXY_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_NETWORKPROXY_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
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();
|
||||
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();
|
||||
|
||||
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_
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_NETWORKPROXY_H_
|
||||
|
||||
@@ -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,59 +14,54 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_OUTCOME_H_
|
||||
#define ALIBABACLOUD_CORE_OUTCOME_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_OUTCOME_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_OUTCOME_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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_
|
||||
bool isSuccess()const { return success_; }
|
||||
E error()const { return e_; }
|
||||
R result()const { return r_; }
|
||||
|
||||
private:
|
||||
bool success_;
|
||||
E e_;
|
||||
R r_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_OUTCOME_H_
|
||||
|
||||
@@ -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,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -26,29 +26,31 @@
|
||||
#include "HttpRequest.h"
|
||||
#include "RoaServiceRequest.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class RoaErrorMarshaller;
|
||||
class ALIBABACLOUD_CORE_EXPORT RoaServiceClient : public CoreClient
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, std::string> JsonOutcome;
|
||||
namespace AlibabaCloud {
|
||||
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> ¶ms)const;
|
||||
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
protected:
|
||||
JsonOutcome makeRequest(const std::string &endpoint,
|
||||
const RoaServiceRequest &msg, HttpRequest::Method method =
|
||||
HttpRequest::Method::Get)const;
|
||||
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::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
|
||||
@@ -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,19 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
|
||||
#include "ServiceRequest.h"
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT RoaServiceRequest : public ServiceRequest
|
||||
{
|
||||
public:
|
||||
RoaServiceRequest(const std::string &product, const std::string &version);
|
||||
virtual ~RoaServiceRequest();
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
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;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
|
||||
@@ -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,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -27,29 +27,38 @@
|
||||
#include "RpcServiceRequest.h"
|
||||
#include "Outcome.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class RpcErrorMarshaller;
|
||||
class RpcServiceRequest;
|
||||
class ALIBABACLOUD_CORE_EXPORT RpcServiceClient : public CoreClient
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, std::string> JsonOutcome;
|
||||
namespace AlibabaCloud {
|
||||
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();
|
||||
|
||||
protected:
|
||||
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> ¶ms)const;
|
||||
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
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;
|
||||
using CoreClient::AttemptRequest;
|
||||
|
||||
protected:
|
||||
virtual JsonOutcome makeRequest(const std::string &endpoint,
|
||||
const RpcServiceRequest &msg, HttpRequest::Method method =
|
||||
HttpRequest::Method::Get) const;
|
||||
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::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
|
||||
@@ -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,23 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
|
||||
#include "ServiceRequest.h"
|
||||
#include <string>
|
||||
|
||||
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();
|
||||
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();
|
||||
|
||||
std::string actionName()const;
|
||||
protected:
|
||||
void setActionName(const std::string &name);
|
||||
std::string actionName()const;
|
||||
using ServiceRequest::setScheme;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
protected:
|
||||
void setActionName(const std::string &name);
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,22 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
#define ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
|
||||
#include <functional>
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT Runnable
|
||||
{
|
||||
public:
|
||||
explicit Runnable(const std::function<void()> f);
|
||||
void run()const;
|
||||
namespace AlibabaCloud {
|
||||
class ALIBABACLOUD_CORE_EXPORT Runnable {
|
||||
public:
|
||||
explicit Runnable(const std::function<void()> f);
|
||||
void run()const;
|
||||
|
||||
private:
|
||||
std::function<void()> f_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
private:
|
||||
std::function<void()> f_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
|
||||
@@ -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,55 +14,61 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
|
||||
#include <map>
|
||||
#include "CoreExport.h"
|
||||
#include "Url.h"
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT ServiceRequest
|
||||
{
|
||||
public:
|
||||
typedef std::string ParameterNameType;
|
||||
typedef std::string ParameterValueType;
|
||||
typedef std::map<ParameterNameType, ParameterValueType> ParameterCollection;
|
||||
namespace AlibabaCloud {
|
||||
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;
|
||||
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;
|
||||
|
||||
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 ¶ms);
|
||||
void setResourcePath(const std::string &path);
|
||||
void setProduct(const std::string &product);
|
||||
void setVersion(const std::string &version);
|
||||
private:
|
||||
char *content_;
|
||||
size_t contentSize_;
|
||||
ParameterCollection params_;
|
||||
std::string product_;
|
||||
std::string resourcePath_;
|
||||
std::string version_;
|
||||
};
|
||||
}
|
||||
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);
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
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 ¶ms);
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
|
||||
@@ -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,27 +14,27 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
#define ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class PayloadReader;
|
||||
class ALIBABACLOUD_CORE_EXPORT ServiceResult
|
||||
{
|
||||
public:
|
||||
ServiceResult();
|
||||
virtual ~ServiceResult();
|
||||
namespace AlibabaCloud {
|
||||
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;
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
protected:
|
||||
void setRequestId(const std::string &requestId);
|
||||
|
||||
private:
|
||||
std::string requestId_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
|
||||
@@ -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,33 +14,34 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SIGNER_H_
|
||||
#define ALIBABACLOUD_CORE_SIGNER_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_SIGNER_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_SIGNER_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT Signer
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
HmacSha1,
|
||||
};
|
||||
virtual ~Signer();
|
||||
namespace AlibabaCloud {
|
||||
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_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_SIGNER_H_
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_SIGNER_H_
|
||||
|
||||
@@ -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,24 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
|
||||
#include "CredentialsProvider.h"
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT SimpleCredentialsProvider : public CredentialsProvider
|
||||
{
|
||||
public:
|
||||
SimpleCredentialsProvider(const Credentials &credentials);
|
||||
SimpleCredentialsProvider(const std::string &accessKeyId,
|
||||
const std::string &accessKeySecret);
|
||||
~SimpleCredentialsProvider();
|
||||
namespace AlibabaCloud {
|
||||
class ALIBABACLOUD_CORE_EXPORT SimpleCredentialsProvider
|
||||
: public CredentialsProvider {
|
||||
public:
|
||||
explicit SimpleCredentialsProvider(const Credentials &credentials);
|
||||
SimpleCredentialsProvider(const std::string &accessKeyId,
|
||||
const std::string &accessKeySecret);
|
||||
~SimpleCredentialsProvider();
|
||||
|
||||
virtual Credentials getCredentials() override;
|
||||
private:
|
||||
Credentials credentials_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
Credentials getCredentials() override;
|
||||
|
||||
private:
|
||||
Credentials credentials_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,39 +14,42 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_STS_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_STS_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <alibabacloud/core/CredentialsProvider.h>
|
||||
#include <alibabacloud/core/sts/StsClient.h>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT StsAssumeRoleCredentialsProvider : public CredentialsProvider
|
||||
{
|
||||
public:
|
||||
StsAssumeRoleCredentialsProvider(const std::shared_ptr<Sts::StsClient>& stsClient,
|
||||
const std::string &roleArn,
|
||||
const std::string &roleSessionName,
|
||||
const std::string &policy = "",
|
||||
int durationSeconds = 3600);
|
||||
~StsAssumeRoleCredentialsProvider();
|
||||
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();
|
||||
|
||||
virtual Credentials getCredentials() override;
|
||||
private:
|
||||
void loadCredentials();
|
||||
bool checkExpiry()const;
|
||||
Credentials getCredentials() override;
|
||||
using StsClient::assumeRole;
|
||||
|
||||
std::mutex cachedMutex_;
|
||||
Credentials cachedCredentials_;
|
||||
std::shared_ptr<Sts::StsClient> stsClient_;
|
||||
int durationSeconds_;
|
||||
std::chrono::system_clock::time_point expiry_;
|
||||
std::string policy_;
|
||||
std::string roleArn_;
|
||||
std::string roleSessionName_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
|
||||
@@ -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,62 +14,61 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_URL_H_
|
||||
#define ALIBABACLOUD_CORE_URL_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_URL_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_URL_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
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_
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_URL_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,36 +14,53 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include <alibabacloud/core/RpcServiceClient.h>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "model/DescribeEndpointsRequest.h"
|
||||
#include "model/DescribeEndpointsResult.h"
|
||||
|
||||
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;
|
||||
|
||||
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();
|
||||
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;
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
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;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,25 +14,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
|
||||
#include <alibabacloud/core/RpcServiceRequest.h>
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Location
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT LocationRequest : public RpcServiceRequest
|
||||
{
|
||||
public:
|
||||
explicit LocationRequest(const std::string & action);
|
||||
virtual ~LocationRequest();
|
||||
namespace AlibabaCloud {
|
||||
namespace Location {
|
||||
class ALIBABACLOUD_CORE_EXPORT LocationRequest : public RpcServiceRequest {
|
||||
public:
|
||||
explicit LocationRequest(const std::string & action);
|
||||
virtual ~LocationRequest();
|
||||
|
||||
private:
|
||||
private:
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,33 +14,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include <alibabacloud/core/location/LocationRequest.h>
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Location
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT DescribeEndpointsRequest : public LocationRequest
|
||||
{
|
||||
public:
|
||||
DescribeEndpointsRequest();
|
||||
~DescribeEndpointsRequest();
|
||||
namespace AlibabaCloud {
|
||||
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);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
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);
|
||||
};
|
||||
} // namespace Model
|
||||
} // namespace Location
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,51 +14,46 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
|
||||
#include <alibabacloud/core/ServiceResult.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <alibabacloud/core/ServiceResult.h>
|
||||
|
||||
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 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;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
private:
|
||||
std::vector<Endpoint> endpoints_;
|
||||
bool success_;
|
||||
};
|
||||
} // namespace Model
|
||||
} // namespace Location
|
||||
} // namespace AlibabaCloud
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,45 +14,64 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include <alibabacloud/core/RpcServiceClient.h>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "model/AssumeRoleRequest.h"
|
||||
#include "model/AssumeRoleResult.h"
|
||||
#include "model/GetCallerIdentityRequest.h"
|
||||
#include "model/GetCallerIdentityResult.h"
|
||||
|
||||
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;
|
||||
|
||||
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();
|
||||
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;
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
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;
|
||||
};
|
||||
} // namespace Sts
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,25 +14,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_STSSERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_STS_STSSERVICEREQUEST_H_
|
||||
#ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_STS_STSREQUEST_H_
|
||||
#define CORE_INCLUDE_ALIBABACLOUD_CORE_STS_STSREQUEST_H_
|
||||
|
||||
#include <alibabacloud/core/RpcServiceRequest.h>
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Sts
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT StsRequest : public RpcServiceRequest
|
||||
{
|
||||
public:
|
||||
explicit StsRequest(const std::string & action);
|
||||
virtual ~StsRequest();
|
||||
namespace AlibabaCloud {
|
||||
namespace Sts {
|
||||
class ALIBABACLOUD_CORE_EXPORT StsRequest : public RpcServiceRequest {
|
||||
public:
|
||||
explicit StsRequest(const std::string & action);
|
||||
virtual ~StsRequest();
|
||||
|
||||
private:
|
||||
private:
|
||||
};
|
||||
} // namespace Sts
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_STS_STSSERVICEREQUEST_H_
|
||||
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_STS_STSREQUEST_H_
|
||||
|
||||
@@ -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,28 +20,24 @@
|
||||
#include <string>
|
||||
#include <alibabacloud/core/sts/StsRequest.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Sts
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT AssumeRoleRequest : public StsRequest
|
||||
{
|
||||
public:
|
||||
AssumeRoleRequest();
|
||||
~AssumeRoleRequest();
|
||||
namespace AlibabaCloud {
|
||||
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_
|
||||
|
||||
@@ -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,41 +19,35 @@
|
||||
|
||||
#include <alibabacloud/core/ServiceResult.h>
|
||||
|
||||
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 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;
|
||||
};
|
||||
|
||||
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_
|
||||
|
||||
@@ -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,22 +20,18 @@
|
||||
#include <string>
|
||||
#include <alibabacloud/core/sts/StsRequest.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Sts
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityRequest : public StsRequest
|
||||
{
|
||||
public:
|
||||
GetCallerIdentityRequest();
|
||||
~GetCallerIdentityRequest();
|
||||
namespace AlibabaCloud {
|
||||
namespace Sts {
|
||||
namespace Model {
|
||||
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityRequest : public StsRequest {
|
||||
public:
|
||||
GetCallerIdentityRequest();
|
||||
~GetCallerIdentityRequest();
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYREQUEST_H_
|
||||
|
||||
@@ -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,31 +19,27 @@
|
||||
|
||||
#include <alibabacloud/core/ServiceResult.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Sts
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityResult : public ServiceResult
|
||||
{
|
||||
public:
|
||||
GetCallerIdentityResult();
|
||||
explicit GetCallerIdentityResult(const std::string &payload);
|
||||
~GetCallerIdentityResult();
|
||||
namespace AlibabaCloud {
|
||||
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_
|
||||
|
||||
@@ -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,27 +18,24 @@
|
||||
#include "Executor.h"
|
||||
|
||||
static AlibabaCloud::Executor * executor = nullptr;
|
||||
|
||||
void AlibabaCloud::InitializeSdk()
|
||||
{
|
||||
if (IsSdkInitialized())
|
||||
return;
|
||||
|
||||
executor = new Executor;
|
||||
executor->start();
|
||||
void AlibabaCloud::InitializeSdk() {
|
||||
if (IsSdkInitialized())
|
||||
return;
|
||||
|
||||
executor = new Executor;
|
||||
executor->start();
|
||||
}
|
||||
|
||||
bool AlibabaCloud::IsSdkInitialized()
|
||||
{
|
||||
return executor != nullptr;
|
||||
bool AlibabaCloud::IsSdkInitialized() {
|
||||
return executor != nullptr;
|
||||
}
|
||||
|
||||
void AlibabaCloud::ShutdownSdk()
|
||||
{
|
||||
if (!IsSdkInitialized())
|
||||
return;
|
||||
|
||||
executor->shutdown();
|
||||
delete executor;
|
||||
executor = nullptr;
|
||||
void AlibabaCloud::ShutdownSdk() {
|
||||
if (!IsSdkInitialized())
|
||||
return;
|
||||
|
||||
executor->shutdown();
|
||||
delete executor;
|
||||
executor = nullptr;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -17,28 +17,25 @@
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
AsyncCallerContext::AsyncCallerContext() :
|
||||
uuid_(GenerateUuid())
|
||||
{
|
||||
uuid_(GenerateUuid()) {
|
||||
}
|
||||
|
||||
AsyncCallerContext::AsyncCallerContext(const std::string &uuid) :
|
||||
uuid_(uuid)
|
||||
{
|
||||
uuid_(uuid) {
|
||||
}
|
||||
|
||||
AsyncCallerContext::~AsyncCallerContext()
|
||||
{
|
||||
AsyncCallerContext::~AsyncCallerContext() {
|
||||
}
|
||||
|
||||
std::string AsyncCallerContext::uuid()const
|
||||
{
|
||||
return uuid_;
|
||||
std::string AsyncCallerContext::uuid()const {
|
||||
return uuid_;
|
||||
}
|
||||
|
||||
void AsyncCallerContext::setUuid(const std::string &uuid)
|
||||
{
|
||||
uuid_ = uuid;
|
||||
void AsyncCallerContext::setUuid(const std::string &uuid) {
|
||||
uuid_ = uuid;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,46 +16,40 @@
|
||||
|
||||
#include <alibabacloud/core/ClientConfiguration.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
ClientConfiguration::ClientConfiguration(const std::string ®ionId,
|
||||
const NetworkProxy &proxy):
|
||||
regionId_(regionId),
|
||||
proxy_(proxy),
|
||||
endpoint_()
|
||||
{
|
||||
const NetworkProxy &proxy):
|
||||
regionId_(regionId),
|
||||
proxy_(proxy),
|
||||
endpoint_() {
|
||||
}
|
||||
|
||||
ClientConfiguration::~ClientConfiguration()
|
||||
{
|
||||
ClientConfiguration::~ClientConfiguration() {
|
||||
}
|
||||
|
||||
std::string ClientConfiguration::endpoint() const
|
||||
{
|
||||
return endpoint_;
|
||||
std::string ClientConfiguration::endpoint() const {
|
||||
return endpoint_;
|
||||
}
|
||||
|
||||
NetworkProxy ClientConfiguration::proxy()const
|
||||
{
|
||||
return proxy_;
|
||||
NetworkProxy ClientConfiguration::proxy()const {
|
||||
return proxy_;
|
||||
}
|
||||
|
||||
std::string ClientConfiguration::regionId()const
|
||||
{
|
||||
return regionId_;
|
||||
std::string ClientConfiguration::regionId()const {
|
||||
return regionId_;
|
||||
}
|
||||
|
||||
void ClientConfiguration::setEndpoint(const std::string & endpoint)
|
||||
{
|
||||
endpoint_ = endpoint;
|
||||
void ClientConfiguration::setEndpoint(const std::string & endpoint) {
|
||||
endpoint_ = endpoint;
|
||||
}
|
||||
|
||||
void ClientConfiguration::setProxy(const NetworkProxy &proxy)
|
||||
{
|
||||
proxy_ = proxy;
|
||||
void ClientConfiguration::setProxy(const NetworkProxy &proxy) {
|
||||
proxy_ = proxy;
|
||||
}
|
||||
|
||||
void ClientConfiguration::setRegionId(const std::string ®ionId)
|
||||
{
|
||||
regionId_ = regionId;
|
||||
}
|
||||
void ClientConfiguration::setRegionId(const std::string ®ionId) {
|
||||
regionId_ = regionId;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -15,284 +15,256 @@
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/CommonClient.h>
|
||||
#include <alibabacloud/core/location/LocationClient.h>
|
||||
#include <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
#include <ctime>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <alibabacloud/core/location/LocationClient.h>
|
||||
#include <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace Location;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string SERVICE_NAME = "Common";
|
||||
namespace {
|
||||
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>())
|
||||
{
|
||||
CommonClient::CommonClient(const Credentials &credentials,
|
||||
const ClientConfiguration &configuration) :
|
||||
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>())
|
||||
{
|
||||
CommonClient::CommonClient(
|
||||
const std::shared_ptr<CredentialsProvider>& credentialsProvider,
|
||||
const ClientConfiguration & configuration) :
|
||||
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>())
|
||||
{
|
||||
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>()) {
|
||||
}
|
||||
|
||||
CommonClient::~CommonClient()
|
||||
{
|
||||
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());
|
||||
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());
|
||||
}
|
||||
|
||||
CommonClient::CommonResponseOutcome CommonClient::commonResponse(const CommonRequest & request) const
|
||||
{
|
||||
auto outcome = makeRequest(request.domain(), request, request.httpMethod());
|
||||
|
||||
if (outcome.isSuccess())
|
||||
return CommonResponseOutcome(CommonResponse(outcome.result()));
|
||||
else
|
||||
return CommonResponseOutcome(Error(outcome.error()));
|
||||
CommonClient::CommonResponseOutcome CommonClient::commonResponse(
|
||||
const CommonRequest & request) const {
|
||||
auto outcome = makeRequest(request.domain(), request, request.httpMethod());
|
||||
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);
|
||||
};
|
||||
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);
|
||||
};
|
||||
|
||||
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);
|
||||
});
|
||||
CommonClient::CommonResponseOutcomeCallable
|
||||
CommonClient::commonResponseCallable(const CommonRequest & request) const {
|
||||
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);
|
||||
HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint,
|
||||
const ServiceRequest & msg, HttpRequest::Method method) const {
|
||||
return buildHttpRequest(endpoint,
|
||||
dynamic_cast<const CommonRequest& >(msg), method);
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
if (msg.requestPattern() == CommonRequest::RpcPattern)
|
||||
return buildRpcHttpRequest(endpoint, msg, method);
|
||||
else
|
||||
return buildRoaHttpRequest(endpoint, 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);
|
||||
}
|
||||
|
||||
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;
|
||||
HttpRequest CommonClient::buildRoaHttpRequest(const std::string & endpoint,
|
||||
const CommonRequest &msg, HttpRequest::Method method) const {
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
std::string value = p.second;
|
||||
StringReplace(value, "\t", " ");
|
||||
StringReplace(value, "\n", " ");
|
||||
StringReplace(value, "\r", " ");
|
||||
StringReplace(value, "\f", " ");
|
||||
materials[key] = value;
|
||||
}
|
||||
Url url;
|
||||
if (msg.scheme().empty()) {
|
||||
url.setScheme("https");
|
||||
} else {
|
||||
url.setScheme(msg.scheme());
|
||||
}
|
||||
url.setHost(endpoint);
|
||||
url.setPath(msg.resourcePath());
|
||||
|
||||
if (materials.empty())
|
||||
return std::string();
|
||||
std::stringstream ss;
|
||||
for (const auto &p : materials)
|
||||
ss << p.first << ":" << p.second << "\n";
|
||||
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;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
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 CommonClient::buildRoaHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
HttpRequest request(url);
|
||||
request.setMethod(method);
|
||||
if (msg.headerParameter("Accept").empty()) {
|
||||
request.setHeader("Accept", "application/json");
|
||||
} else {
|
||||
request.setHeader("Accept", msg.headerParameter("Accept"));
|
||||
}
|
||||
|
||||
Url url;
|
||||
url.setScheme("https");
|
||||
url.setHost(endpoint);
|
||||
url.setPath(msg.resourcePath());
|
||||
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());
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
HttpRequest request(url);
|
||||
request.setMethod(method);
|
||||
request.setHeader("Accept", "application/json");
|
||||
if (msg.hasContent()) {
|
||||
std::stringstream ss;
|
||||
ss << msg.contentSize();
|
||||
request.setHeader("Content-Length", ss.str());
|
||||
request.setHeader("Content-Type", "application/octet-stream");
|
||||
request.setHeader("Content-MD5", ComputeContentMD5(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;
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildRpcHttpRequest(const std::string & endpoint,
|
||||
const CommonRequest &msg, HttpRequest::Method method) const {
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
std::string CommonClient::canonicalizedQuery(const std::map<std::string, std::string>& params) const
|
||||
{
|
||||
if (params.empty())
|
||||
return std::string();
|
||||
Url url;
|
||||
if (msg.scheme().empty()) {
|
||||
url.setScheme("https");
|
||||
} else {
|
||||
url.setScheme(msg.scheme());
|
||||
}
|
||||
url.setHost(endpoint);
|
||||
url.setPath(msg.resourcePath());
|
||||
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildRpcHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
Url url;
|
||||
url.setScheme("https");
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,78 +16,78 @@
|
||||
|
||||
#include <alibabacloud/core/CommonRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
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_;
|
||||
CommonRequest::~CommonRequest() {
|
||||
}
|
||||
|
||||
void CommonRequest::setDomain(const std::string &domain)
|
||||
{
|
||||
domain_ = domain;
|
||||
std::string CommonRequest::domain()const {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
CommonRequest::RequestPattern CommonRequest::requestPattern() const
|
||||
{
|
||||
return requestPattern_;
|
||||
void CommonRequest::setDomain(const std::string &domain) {
|
||||
domain_ = domain;
|
||||
}
|
||||
|
||||
void CommonRequest::setRequestPattern(RequestPattern pattern)
|
||||
{
|
||||
requestPattern_ = pattern;
|
||||
CommonRequest::RequestPattern CommonRequest::requestPattern() const {
|
||||
return requestPattern_;
|
||||
}
|
||||
|
||||
void CommonRequest::setHttpMethod(HttpRequest::Method method)
|
||||
{
|
||||
httpMethod_ = method;
|
||||
void CommonRequest::setRequestPattern(RequestPattern pattern) {
|
||||
requestPattern_ = pattern;
|
||||
}
|
||||
|
||||
HttpRequest::Method CommonRequest::httpMethod() const
|
||||
{
|
||||
return httpMethod_;
|
||||
void CommonRequest::setHttpMethod(HttpRequest::Method method) {
|
||||
httpMethod_ = method;
|
||||
}
|
||||
|
||||
CommonRequest::ParameterValueType CommonRequest::queryParameter(const ParameterNameType &name)const
|
||||
{
|
||||
return queryParams_.at(name);
|
||||
HttpRequest::Method CommonRequest::httpMethod() const {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
CommonRequest::ParameterCollection CommonRequest::queryParameters() const
|
||||
{
|
||||
return queryParams_;
|
||||
CommonRequest::ParameterCollection CommonRequest::queryParameters() const {
|
||||
return queryParams_;
|
||||
}
|
||||
|
||||
void CommonRequest::setQueryParameter(const ParameterNameType &name, const ParameterValueType &value)
|
||||
{
|
||||
queryParams_[name] = value;
|
||||
}
|
||||
|
||||
CommonRequest::ParameterValueType CommonRequest::headerParameter(const ParameterNameType &name)const
|
||||
{
|
||||
return headerParams_.at(name);
|
||||
void CommonRequest::setQueryParameter(const ParameterNameType &name,
|
||||
const ParameterValueType &value) {
|
||||
queryParams_[name] = value;
|
||||
}
|
||||
|
||||
CommonRequest::ParameterCollection CommonRequest::headerParameters() const
|
||||
{
|
||||
return headerParams_;
|
||||
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;
|
||||
}
|
||||
|
||||
void CommonRequest::setHeaderParameter(const ParameterNameType &name, const ParameterValueType &value)
|
||||
{
|
||||
headerParams_[name] = value;
|
||||
CommonRequest::ParameterCollection CommonRequest::headerParameters() const {
|
||||
return headerParams_;
|
||||
}
|
||||
|
||||
|
||||
void CommonRequest::setHeaderParameter(const ParameterNameType &name,
|
||||
const ParameterValueType &value) {
|
||||
headerParams_[name] = value;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,23 +16,21 @@
|
||||
|
||||
#include <alibabacloud/core/CommonResponse.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
CommonResponse::CommonResponse() :
|
||||
payload_()
|
||||
{
|
||||
payload_() {
|
||||
}
|
||||
|
||||
CommonResponse::CommonResponse(const std::string &payload) :
|
||||
payload_(payload)
|
||||
{
|
||||
payload_(payload) {
|
||||
}
|
||||
|
||||
CommonResponse::~CommonResponse()
|
||||
{
|
||||
CommonResponse::~CommonResponse() {
|
||||
}
|
||||
|
||||
std::string CommonResponse::payload() const
|
||||
{
|
||||
return payload_;
|
||||
std::string CommonResponse::payload() const {
|
||||
return payload_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,64 +25,69 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
CoreClient::CoreClient(const std::string & servicename, const ClientConfiguration &configuration) :
|
||||
serviceName_(servicename),
|
||||
configuration_(configuration),
|
||||
httpClient_(new CurlHttpClient)
|
||||
{
|
||||
httpClient_->setProxy(configuration.proxy());
|
||||
CoreClient::CoreClient(const std::string & servicename,
|
||||
const ClientConfiguration &configuration) :
|
||||
serviceName_(servicename),
|
||||
configuration_(configuration),
|
||||
httpClient_(new CurlHttpClient) {
|
||||
httpClient_->setProxy(configuration.proxy());
|
||||
}
|
||||
|
||||
CoreClient::~CoreClient()
|
||||
{
|
||||
delete httpClient_;
|
||||
CoreClient::~CoreClient() {
|
||||
delete httpClient_;
|
||||
}
|
||||
|
||||
ClientConfiguration CoreClient::configuration()const
|
||||
{
|
||||
return configuration_;
|
||||
ClientConfiguration CoreClient::configuration()const {
|
||||
return configuration_;
|
||||
}
|
||||
|
||||
std::string CoreClient::serviceName()const
|
||||
{
|
||||
return serviceName_;
|
||||
std::string CoreClient::serviceName()const {
|
||||
return serviceName_;
|
||||
}
|
||||
|
||||
void CoreClient::asyncExecute(Runnable * r)const
|
||||
{
|
||||
Executor::instance()->execute(r);
|
||||
void CoreClient::asyncExecute(Runnable * r)const {
|
||||
Executor::instance()->execute(r);
|
||||
}
|
||||
|
||||
HttpClient::HttpResponseOutcome CoreClient::AttemptRequest(const std::string & endpoint, const ServiceRequest & request, HttpRequest::Method method) const
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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", "");
|
||||
Error CoreClient::buildCoreError(const HttpResponse &response)const {
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
if (!reader.parse(std::string(response.body(), response.bodySize()), value)) {
|
||||
if (response.bodySize() > 0) {
|
||||
return Error("InvalidResponse", response.body());
|
||||
} else {
|
||||
return Error("InvalidResponse", "body is empty");
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
if (value["Code"].asString().empty() || value["Message"].asString().empty()) {
|
||||
error.setDetail(std::string(response.body()));
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
bool CoreClient::hasResponseError(const HttpResponse &response)const
|
||||
{
|
||||
return response.statusCode() < 200 || response.statusCode() > 299;
|
||||
}
|
||||
bool CoreClient::hasResponseError(const HttpResponse &response)const {
|
||||
return response.statusCode() < 200 || response.statusCode() > 299;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,47 +16,41 @@
|
||||
|
||||
#include <alibabacloud/core/Credentials.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
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) {
|
||||
}
|
||||
|
||||
Credentials::~Credentials()
|
||||
{
|
||||
Credentials::~Credentials() {
|
||||
}
|
||||
|
||||
std::string Credentials::accessKeyId () const
|
||||
{
|
||||
return accessKeyId_;
|
||||
std::string Credentials::accessKeyId() const {
|
||||
return accessKeyId_;
|
||||
}
|
||||
|
||||
std::string Credentials::accessKeySecret () const
|
||||
{
|
||||
return accessKeySecret_;
|
||||
std::string Credentials::accessKeySecret() const {
|
||||
return accessKeySecret_;
|
||||
}
|
||||
|
||||
void Credentials::setAccessKeyId(const std::string &accessKeyId)
|
||||
{
|
||||
accessKeyId_ = accessKeyId;
|
||||
void Credentials::setAccessKeyId(const std::string &accessKeyId) {
|
||||
accessKeyId_ = accessKeyId;
|
||||
}
|
||||
|
||||
void Credentials::setAccessKeySecret(const std::string &accessKeySecret)
|
||||
{
|
||||
accessKeySecret_ = accessKeySecret;
|
||||
void Credentials::setAccessKeySecret(const std::string &accessKeySecret) {
|
||||
accessKeySecret_ = accessKeySecret;
|
||||
}
|
||||
|
||||
void Credentials::setSessionToken (const std::string &sessionToken)
|
||||
{
|
||||
sessionToken_ = sessionToken;
|
||||
void Credentials::setSessionToken(const std::string &sessionToken) {
|
||||
sessionToken_ = sessionToken;
|
||||
}
|
||||
|
||||
std::string Credentials::sessionToken () const
|
||||
{
|
||||
return sessionToken_;
|
||||
std::string Credentials::sessionToken() const {
|
||||
return sessionToken_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
@@ -15,127 +15,139 @@
|
||||
*/
|
||||
|
||||
#include "CurlHttpClient.h"
|
||||
#include "Utils.h"
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
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 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;
|
||||
|
||||
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());
|
||||
|
||||
if (!proxy.user().empty()) {
|
||||
out.clear();
|
||||
out << proxy.user() << ":" << proxy.password();
|
||||
curl_easy_setopt(curlHandle, CURLOPT_PROXYUSERPWD, out.str().c_str());
|
||||
}
|
||||
}
|
||||
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 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;
|
||||
|
||||
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());
|
||||
|
||||
if (!proxy.user().empty()) {
|
||||
out.clear();
|
||||
out << proxy.user() << ":" << proxy.password();
|
||||
curl_easy_setopt(curlHandle, CURLOPT_PROXYUSERPWD, out.str().c_str());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CurlHttpClient::CurlHttpClient() :
|
||||
HttpClient(),
|
||||
curlHandle_(curl_easy_init())
|
||||
{
|
||||
HttpClient(),
|
||||
curlHandle_(curl_easy_init()) {
|
||||
}
|
||||
|
||||
CurlHttpClient::~CurlHttpClient()
|
||||
{
|
||||
curl_easy_cleanup(curlHandle_);
|
||||
CurlHttpClient::~CurlHttpClient() {
|
||||
curl_easy_cleanup(curlHandle_);
|
||||
}
|
||||
|
||||
HttpClient::HttpResponseOutcome CurlHttpClient::makeRequest(const HttpRequest &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::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);
|
||||
HttpClient::HttpResponseOutcome
|
||||
CurlHttpClient::makeRequest(const HttpRequest &request) {
|
||||
curl_easy_reset(curlHandle_);
|
||||
HttpResponse response(request);
|
||||
|
||||
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());
|
||||
std::string url = request.url().toString();
|
||||
switch (request.method()) {
|
||||
case HttpRequest::Method::Get:
|
||||
break;
|
||||
case HttpRequest::Method::Post: {
|
||||
if (request.bodySize() > 0) {
|
||||
curl_easy_setopt(curlHandle_, CURLOPT_POSTFIELDS, request.body());
|
||||
} else {
|
||||
curl_easy_setopt(curlHandle_, CURLOPT_POSTFIELDS, "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HttpRequest::Method::Put:
|
||||
curl_easy_setopt(curlHandle_, CURLOPT_UPLOAD, 1L);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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."));
|
||||
}
|
||||
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());
|
||||
|
||||
if (GetEnv("DEBUG") == "sdk") {
|
||||
curl_easy_setopt(curlHandle_, CURLOPT_VERBOSE, 1L);
|
||||
}
|
||||
|
||||
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: " +
|
||||
HttpMethodToString(request.method()) + " " + request.url().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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,24 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CURLHTTPCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_CURLHTTPCLIENT_H_
|
||||
#ifndef CORE_SRC_CURLHTTPCLIENT_H_
|
||||
#define CORE_SRC_CURLHTTPCLIENT_H_
|
||||
|
||||
#include <alibabacloud/core/HttpClient.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class CurlHttpClient : public HttpClient
|
||||
{
|
||||
public:
|
||||
CurlHttpClient();
|
||||
~CurlHttpClient();
|
||||
namespace AlibabaCloud {
|
||||
class CurlHttpClient : public HttpClient {
|
||||
public:
|
||||
CurlHttpClient();
|
||||
~CurlHttpClient();
|
||||
|
||||
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) override;
|
||||
private:
|
||||
CURL *curlHandle_;
|
||||
};
|
||||
}
|
||||
HttpResponseOutcome makeRequest(const HttpRequest &request) override;
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_CURLHTTPCLIENT_H_
|
||||
private:
|
||||
CURL *curlHandle_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_SRC_CURLHTTPCLIENT_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -14,56 +14,51 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "EcsMetadataFetcher.h"
|
||||
#include <alibabacloud/core/Url.h>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <alibabacloud/core/Url.h>
|
||||
#include "EcsMetadataFetcher.h"
|
||||
#include "CurlHttpClient.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
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/";
|
||||
EcsMetadataFetcher::EcsMetadataFetcher() {
|
||||
}
|
||||
|
||||
EcsMetadataFetcher::EcsMetadataFetcher()
|
||||
{
|
||||
EcsMetadataFetcher::~EcsMetadataFetcher() {
|
||||
}
|
||||
|
||||
EcsMetadataFetcher::~EcsMetadataFetcher()
|
||||
{
|
||||
std::string EcsMetadataFetcher::roleName()const {
|
||||
return roleName_;
|
||||
}
|
||||
|
||||
std::string EcsMetadataFetcher::roleName()const
|
||||
{
|
||||
return roleName_;
|
||||
void EcsMetadataFetcher::setRoleName(const std::string & roleName) {
|
||||
roleName_ = roleName;
|
||||
}
|
||||
|
||||
void EcsMetadataFetcher::setRoleName(const std::string & roleName)
|
||||
{
|
||||
roleName_ = roleName;
|
||||
std::string EcsMetadataFetcher::getMetadata() {
|
||||
return getMetadata(METADATA_SERVICE_HOST, URL_IN_ECS_METADATA);
|
||||
}
|
||||
|
||||
std::string EcsMetadataFetcher::getMetadata()
|
||||
{
|
||||
std::stringstream path;
|
||||
path << URL_IN_ECS_METADATA << roleName_;
|
||||
std::string EcsMetadataFetcher::getMetadata(const std::string host,
|
||||
const std::string in_path) {
|
||||
std::stringstream path;
|
||||
path << in_path << roleName_;
|
||||
|
||||
Url credentialUrl;
|
||||
credentialUrl.setHost(METADATA_SERVICE_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();
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -14,26 +14,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ECSMETADATASERVICECREDENTIALSFETCHER_H_
|
||||
#define ALIBABACLOUD_CORE_ECSMETADATASERVICECREDENTIALSFETCHER_H_
|
||||
#ifndef CORE_SRC_ECSMETADATAFETCHER_H_
|
||||
#define CORE_SRC_ECSMETADATAFETCHER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class EcsMetadataFetcher
|
||||
{
|
||||
public:
|
||||
EcsMetadataFetcher();
|
||||
~EcsMetadataFetcher();
|
||||
|
||||
std::string roleName()const;
|
||||
void setRoleName(const std::string & roleName);
|
||||
|
||||
std::string getMetadata();
|
||||
private:
|
||||
std::string roleName_;
|
||||
};
|
||||
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/";
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_ECSMETADATASERVICECREDENTIALSFETCHER_H_
|
||||
namespace AlibabaCloud {
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_SRC_ECSMETADATAFETCHER_H_
|
||||
|
||||
@@ -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.
|
||||
@@ -15,191 +15,225 @@
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/EndpointProvider.h>
|
||||
#include <json/json.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <json/json.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Location;
|
||||
|
||||
namespace
|
||||
{
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#include <algorithm>
|
||||
#ifndef WIN32
|
||||
#include "LocalEndpoints.h"
|
||||
#else
|
||||
# include <strings.h>
|
||||
#include "LocalEndpointsForWindows.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\":\"\"}"
|
||||
"]}";
|
||||
namespace AlibabaCloud {
|
||||
|
||||
namespace {
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
bool local_endpoints_loaded = false;
|
||||
typedef std::string productType;
|
||||
typedef std::string regionType;
|
||||
typedef std::string endpointType;
|
||||
typedef std::string mappingType;
|
||||
typedef std::vector<regionType> regionsType;
|
||||
typedef std::map<productType, endpointType> regionalType;
|
||||
typedef struct {
|
||||
regionsType regions;
|
||||
regionalType regional;
|
||||
} productInfoType;
|
||||
|
||||
static std::vector<regionType> allRegions;
|
||||
static std::vector<productType> allProductsInLocalEndpoints;
|
||||
static std::map<productType, productInfoType> allLocalEndpoints;
|
||||
|
||||
static void LoadLocalEndpoints() {
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
|
||||
if (local_endpoints_loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
std::string LOCAL_ENDPOINTS_CONFIG = WIN_LOCAL_ENDPOINTS_CONFIG_1 +
|
||||
WIN_LOCAL_ENDPOINTS_CONFIG_2 + WIN_LOCAL_ENDPOINTS_CONFIG_3;
|
||||
#endif
|
||||
|
||||
if (!reader.parse(LOCAL_ENDPOINTS_CONFIG, value)){
|
||||
return;
|
||||
}
|
||||
|
||||
auto regions = value["regions"];
|
||||
for (const auto ®ion : regions) {
|
||||
allRegions.push_back(region.asString());
|
||||
}
|
||||
|
||||
auto products = value["products"];
|
||||
for (const auto &product : products) {
|
||||
allProductsInLocalEndpoints.push_back(product.asString());
|
||||
}
|
||||
|
||||
auto endpoints = value["endpoints"];
|
||||
for (auto &product : allProductsInLocalEndpoints ) {
|
||||
auto endpoint_per_product = endpoints[product];
|
||||
productInfoType p;
|
||||
|
||||
auto regions = endpoint_per_product["regions"];
|
||||
auto regional = endpoint_per_product["regional"];
|
||||
|
||||
for (auto & r : regions) {
|
||||
const std::string region = r.asString();
|
||||
p.regions.push_back(region);
|
||||
p.regional[region] = endpoint_per_product["regional"][region].asString();
|
||||
}
|
||||
allLocalEndpoints[product] = p;
|
||||
}
|
||||
local_endpoints_loaded = true;
|
||||
}
|
||||
|
||||
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_()
|
||||
{
|
||||
loadInternalProductsInfo();
|
||||
} // namespace
|
||||
|
||||
EndpointProvider::EndpointProvider(
|
||||
const std::shared_ptr<Location::LocationClient>& locationClient,
|
||||
const std::string regionId,
|
||||
const std::string product,
|
||||
const std::string serviceCode, int durationSeconds) :
|
||||
LocationClient(locationClient),
|
||||
regionId_(regionId),
|
||||
product_(product),
|
||||
serviceCode_(serviceCode),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedEndpoint_(),
|
||||
expiry_() {
|
||||
transform(product_.begin(), product_.end(), product_.begin(), ::tolower);
|
||||
loadLocalProductsInfo();
|
||||
}
|
||||
|
||||
EndpointProvider::~EndpointProvider()
|
||||
{
|
||||
EndpointProvider::EndpointProvider(
|
||||
const Credentials& credentials,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::string ®ionId,
|
||||
const std::string &product,
|
||||
const std::string &serviceCode,
|
||||
int durationSeconds) :
|
||||
LocationClient(credentials, configuration),
|
||||
regionId_(regionId),
|
||||
product_(product),
|
||||
serviceCode_(serviceCode),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedEndpoint_(),
|
||||
expiry_() {
|
||||
transform(product_.begin(), product_.end(), product_.begin(), ::tolower);
|
||||
loadLocalProductsInfo();
|
||||
}
|
||||
|
||||
bool EndpointProvider::loadInternalProductsInfo()
|
||||
{
|
||||
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 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;
|
||||
EndpointProvider::~EndpointProvider() {
|
||||
}
|
||||
|
||||
bool EndpointProvider::checkExpiry()const
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
|
||||
|
||||
return (diff > 0 - 60);
|
||||
bool EndpointProvider::loadLocalProductsInfo() {
|
||||
LoadLocalEndpoints();
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
std::string EndpointProvider::localEndpoint(
|
||||
const std::string regionId, const std::string product) {
|
||||
|
||||
for (auto e : p.regionalEndpoints)
|
||||
{
|
||||
if (strcasecmp(e.first.c_str(), regionId.c_str()) != 0)
|
||||
continue;
|
||||
if (!local_endpoints_loaded) {
|
||||
// impossible
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return e.second;
|
||||
}
|
||||
return p.globalEndpoint;
|
||||
}
|
||||
return std::string();
|
||||
std::vector<regionType>::iterator allRegionsit;
|
||||
allRegionsit = std::find(allRegions.begin(), allRegions.end(), regionId);
|
||||
if (allRegionsit == allRegions.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<productType>::iterator allProductsInLocalEndpointsit;
|
||||
allProductsInLocalEndpointsit = std::find(allProductsInLocalEndpoints.begin(), allProductsInLocalEndpoints.end(), product);
|
||||
if (allProductsInLocalEndpointsit == allProductsInLocalEndpoints.end()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<regionType> vec = allLocalEndpoints[product].regions;
|
||||
std::vector<regionType>::iterator it;
|
||||
it = std::find(vec.begin(), vec.end(), regionId);
|
||||
if (it == vec.end()) {
|
||||
return std::string();
|
||||
}
|
||||
return allLocalEndpoints[product].regional[regionId];
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::getEndpoint()
|
||||
{
|
||||
if (!locationClient_->configuration().endpoint().empty())
|
||||
return EndpointOutcome(locationClient_->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;
|
||||
}
|
||||
|
||||
std::string endpoint = internalEndpoint(regionId_, product_);
|
||||
if (!endpoint.empty())
|
||||
return EndpointOutcome(endpoint);
|
||||
|
||||
return EndpointOutcome(Error("InvalidRegionId", "The specified region does not exist."));
|
||||
bool EndpointProvider::checkExpiry()const {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto diff =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
|
||||
return (diff > 0 - 60);
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::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 = locationClient_->describeEndpoints(request);
|
||||
if (!outcome.isSuccess())
|
||||
return EndpointOutcome(outcome.error());
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::getEndpoint() {
|
||||
// 1st priority: user specified via configuration
|
||||
if (!configuration().endpoint().empty()) {
|
||||
return EndpointOutcome(configuration().endpoint());
|
||||
}
|
||||
|
||||
auto all = outcome.result().endpoints();
|
||||
if (all.size() > 0)
|
||||
cachedEndpoint_ = all.front().endpoint;
|
||||
// 2nd priority: local configuration
|
||||
std::string endpoint = localEndpoint(regionId_, product_);
|
||||
if (!endpoint.empty()) {
|
||||
return EndpointOutcome(endpoint);
|
||||
}
|
||||
|
||||
std::time_t t = std::time(nullptr) + durationSeconds_;
|
||||
expiry_ = std::chrono::system_clock::from_time_t(t);
|
||||
}
|
||||
}
|
||||
// service code is mandatory for location service.
|
||||
if (serviceCode_.empty()) {
|
||||
return EndpointOutcome(
|
||||
Error("InvalidRegionId",
|
||||
"Product[" + product_ + "] at region[" +
|
||||
regionId_ + "] does not exist."));
|
||||
}
|
||||
|
||||
return EndpointOutcome(cachedEndpoint_);
|
||||
}
|
||||
// 3rd priority: request from location service
|
||||
EndpointOutcome outcome = loadRemoteEndpoint();
|
||||
if (outcome.isSuccess()) {
|
||||
return outcome;
|
||||
}
|
||||
|
||||
if (outcome.error().errorCode() == "Illegal Parameter") {
|
||||
return EndpointOutcome(Error("InvalidProduct",
|
||||
"Prodcut[" + serviceCode_ + "] does not exist."));
|
||||
}
|
||||
return outcome;
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::loadRemoteEndpoint() {
|
||||
if (checkExpiry()) {
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
if (checkExpiry()) {
|
||||
Location::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;
|
||||
|
||||
std::time_t t = std::time(nullptr) + durationSeconds_;
|
||||
expiry_ = std::chrono::system_clock::from_time_t(t);
|
||||
}
|
||||
}
|
||||
return EndpointOutcome(cachedEndpoint_);
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,21 +16,25 @@
|
||||
|
||||
#include <alibabacloud/core/Error.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
Error::Error(std::string code, const std::string message) :
|
||||
errorCode_(code),
|
||||
message_(message),
|
||||
host_(),
|
||||
requestId_()
|
||||
{
|
||||
errorCode_(code),
|
||||
message_(message),
|
||||
host_(),
|
||||
requestId_(),
|
||||
detail_() {
|
||||
}
|
||||
|
||||
std::string Error::errorCode()const { return errorCode_; }
|
||||
std::string Error::errorMessage() const { return message_; }
|
||||
std::string Error::host() const { return host_; }
|
||||
std::string Error::requestId() const { return requestId_; }
|
||||
std::string Error::detail() const { return detail_; }
|
||||
void Error::setErrorCode(const std::string &code) { errorCode_ = code; }
|
||||
void Error::setErrorMessage(const std::string& message) { message_ = message; }
|
||||
void Error::setHost(const std::string& host) { host_ = host; }
|
||||
void Error::setRequestId(const std::string& request) { requestId_ = request; }
|
||||
void Error::setDetail(const std::string& detail) { detail_ = detail; }
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -17,108 +17,98 @@
|
||||
#include "Executor.h"
|
||||
#include <alibabacloud/core/Runnable.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
Executor *Executor::self_ = nullptr;
|
||||
|
||||
Executor::Executor() :
|
||||
cvMutex_(),
|
||||
shutdown_(true),
|
||||
tasksQueue_(),
|
||||
tasksQueueMutex_(),
|
||||
thread_()
|
||||
{
|
||||
self_ = this;
|
||||
cvMutex_(),
|
||||
shutdown_(true),
|
||||
tasksQueue_(),
|
||||
tasksQueueMutex_(),
|
||||
thread_() {
|
||||
self_ = this;
|
||||
}
|
||||
|
||||
Executor::~Executor()
|
||||
{
|
||||
self_ = nullptr;
|
||||
shutdown();
|
||||
Executor::~Executor() {
|
||||
self_ = nullptr;
|
||||
shutdown();
|
||||
}
|
||||
|
||||
Executor * Executor::instance()
|
||||
{
|
||||
return self_;
|
||||
Executor * Executor::instance() {
|
||||
return self_;
|
||||
}
|
||||
|
||||
bool Executor::start()
|
||||
{
|
||||
if (!isShutdown())
|
||||
return true;
|
||||
bool Executor::start() {
|
||||
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_;
|
||||
bool Executor::isShutdown()const {
|
||||
return shutdown_;
|
||||
}
|
||||
|
||||
void Executor::execute(Runnable* task)
|
||||
{
|
||||
if (isShutdown())
|
||||
return;
|
||||
void Executor::execute(Runnable* task) {
|
||||
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();
|
||||
void Executor::wakeUp() {
|
||||
std::unique_lock<std::mutex> lk(cvMutex_);
|
||||
cv_.notify_one();
|
||||
}
|
||||
|
||||
void Executor::shutdown()
|
||||
{
|
||||
if (isShutdown())
|
||||
return;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(tasksQueueMutex_);
|
||||
while (tasksQueue_.size() > 0) {
|
||||
auto task = tasksQueue_.front();
|
||||
delete task;
|
||||
tasksQueue_.pop();
|
||||
}
|
||||
}
|
||||
void Executor::shutdown() {
|
||||
if (isShutdown())
|
||||
return;
|
||||
|
||||
shutdown_ = true;
|
||||
wakeUp();
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(tasksQueueMutex_);
|
||||
while (tasksQueue_.size() > 0) {
|
||||
auto task = tasksQueue_.front();
|
||||
delete task;
|
||||
tasksQueue_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
if (thread_.joinable())
|
||||
thread_.join();
|
||||
}
|
||||
shutdown_ = true;
|
||||
wakeUp();
|
||||
|
||||
if (thread_.joinable())
|
||||
thread_.join();
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_EXECUTOR_H_
|
||||
#define ALIBABACLOUD_CORE_EXECUTOR_H_
|
||||
#ifndef CORE_SRC_EXECUTOR_H_
|
||||
#define CORE_SRC_EXECUTOR_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
@@ -24,30 +24,29 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
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_;
|
||||
};
|
||||
}
|
||||
namespace AlibabaCloud {
|
||||
class Runnable;
|
||||
class Executor {
|
||||
public:
|
||||
Executor();
|
||||
~Executor();
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_EXECUTOR_H_
|
||||
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_;
|
||||
};
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
#endif // CORE_SRC_EXECUTOR_H_
|
||||
|
||||
@@ -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,78 +22,81 @@
|
||||
#include <openssl/hmac.h>
|
||||
#endif
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
HmacSha1Signer::HmacSha1Signer() :
|
||||
Signer(HmacSha1, "HMAC-SHA1", "1.0")
|
||||
{
|
||||
Signer(HmacSha1, "HMAC-SHA1", "1.0") {
|
||||
}
|
||||
|
||||
HmacSha1Signer::~HmacSha1Signer()
|
||||
{
|
||||
HmacSha1Signer::~HmacSha1Signer() {
|
||||
}
|
||||
|
||||
std::string HmacSha1Signer::generate(const std::string & src, const std::string & secret) const
|
||||
{
|
||||
if (src.empty())
|
||||
return std::string();
|
||||
std::string HmacSha1Signer::generate(const std::string & src,
|
||||
const std::string & secret) const {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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,23 +19,21 @@
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
HttpClient::HttpClient() :
|
||||
proxy_()
|
||||
{
|
||||
proxy_() {
|
||||
}
|
||||
|
||||
HttpClient::~HttpClient()
|
||||
{
|
||||
HttpClient::~HttpClient() {
|
||||
}
|
||||
|
||||
NetworkProxy HttpClient::proxy()const
|
||||
{
|
||||
return proxy_;
|
||||
NetworkProxy HttpClient::proxy()const {
|
||||
return proxy_;
|
||||
}
|
||||
|
||||
void HttpClient::setProxy(const NetworkProxy &proxy)
|
||||
{
|
||||
proxy_ = proxy;
|
||||
}
|
||||
void HttpClient::setProxy(const NetworkProxy &proxy) {
|
||||
proxy_ = proxy;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -17,157 +17,142 @@
|
||||
#include <alibabacloud/core/HttpMessage.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
namespace
|
||||
{
|
||||
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"
|
||||
};
|
||||
} // namespace
|
||||
|
||||
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_)
|
||||
{
|
||||
setBody(other.body_, other.bodySize_);
|
||||
body_(nullptr),
|
||||
bodySize_(other.bodySize_),
|
||||
headers_(other.headers_) {
|
||||
setBody(other.body_, other.bodySize_);
|
||||
}
|
||||
|
||||
HttpMessage::HttpMessage(HttpMessage &&other)
|
||||
{
|
||||
*this = std::move(other);
|
||||
HttpMessage::HttpMessage(HttpMessage &&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;
|
||||
HttpMessage& HttpMessage::operator=(const HttpMessage &other) {
|
||||
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;
|
||||
HttpMessage& HttpMessage::operator=(HttpMessage &&other) {
|
||||
if (this != &other)
|
||||
*this = std::move(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void HttpMessage::addHeader(const HeaderNameType & name, const HeaderValueType & value)
|
||||
{
|
||||
setHeader(name, value);
|
||||
void HttpMessage::addHeader(const HeaderNameType & name,
|
||||
const HeaderValueType & value) {
|
||||
setHeader(name, value);
|
||||
}
|
||||
|
||||
void HttpMessage::addHeader(KnownHeader header, const HeaderValueType & value)
|
||||
{
|
||||
setHeader(header, value);
|
||||
void HttpMessage::addHeader(KnownHeader header, const HeaderValueType & 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();
|
||||
HttpMessage::HeaderValueType HttpMessage::header(
|
||||
const HeaderNameType & name) const {
|
||||
auto it = headers_.find(name);
|
||||
if (it != headers_.end())
|
||||
return it->second;
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
HttpMessage::HeaderCollection HttpMessage::headers() const
|
||||
{
|
||||
return headers_;
|
||||
HttpMessage::HeaderCollection HttpMessage::headers() const {
|
||||
return headers_;
|
||||
}
|
||||
|
||||
void HttpMessage::removeHeader(const HeaderNameType & name)
|
||||
{
|
||||
headers_.erase(name);
|
||||
void HttpMessage::removeHeader(const HeaderNameType & name) {
|
||||
headers_.erase(name);
|
||||
}
|
||||
|
||||
void HttpMessage::removeHeader(KnownHeader header)
|
||||
{
|
||||
removeHeader(KnownHeaderMapper[header]);
|
||||
void HttpMessage::removeHeader(KnownHeader header) {
|
||||
removeHeader(KnownHeaderMapper[header]);
|
||||
}
|
||||
|
||||
void HttpMessage::setHeader(const HeaderNameType & name, const HeaderValueType & value)
|
||||
{
|
||||
headers_[name] = value;
|
||||
void HttpMessage::setHeader(const HeaderNameType & name,
|
||||
const HeaderValueType & value) {
|
||||
headers_[name] = value;
|
||||
}
|
||||
|
||||
void HttpMessage::setHeader(KnownHeader header, const std::string & value)
|
||||
{
|
||||
setHeader(KnownHeaderMapper[header], value);
|
||||
void HttpMessage::setHeader(KnownHeader header,
|
||||
const std::string & value) {
|
||||
setHeader(KnownHeaderMapper[header], value);
|
||||
}
|
||||
|
||||
HttpMessage::~HttpMessage()
|
||||
{
|
||||
setBody(nullptr, 0);
|
||||
HttpMessage::~HttpMessage() {
|
||||
setBody(nullptr, 0);
|
||||
}
|
||||
|
||||
const char* HttpMessage::body()const
|
||||
{
|
||||
return body_;
|
||||
const char* HttpMessage::body()const {
|
||||
return body_;
|
||||
}
|
||||
|
||||
size_t HttpMessage::bodySize()const
|
||||
{
|
||||
return bodySize_;
|
||||
size_t HttpMessage::bodySize()const {
|
||||
return bodySize_;
|
||||
}
|
||||
|
||||
bool HttpMessage::hasBody() const
|
||||
{
|
||||
return (bodySize_ != 0);
|
||||
bool HttpMessage::hasBody() const {
|
||||
return (bodySize_ != 0);
|
||||
}
|
||||
|
||||
HttpMessage::HeaderValueType HttpMessage::header(KnownHeader header)const
|
||||
{
|
||||
return this->header(KnownHeaderMapper[header]);
|
||||
HttpMessage::HeaderValueType HttpMessage::header(KnownHeader header)const {
|
||||
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];
|
||||
std::copy(data, data + size, body_);
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
bool HttpMessage::nocaseLess::operator()(const std::string & s1,
|
||||
const std::string & s2) const
|
||||
{
|
||||
return strcasecmp(s1.c_str(), s2.c_str()) < 0;
|
||||
const std::string & s2) const {
|
||||
return strcasecmp(s1.c_str(), s2.c_str()) < 0;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,36 +16,32 @@
|
||||
|
||||
#include <alibabacloud/core/HttpRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
HttpRequest::HttpRequest(const Url &url, Method method) :
|
||||
HttpMessage(),
|
||||
url_(url),
|
||||
method_(method)
|
||||
{
|
||||
HttpMessage(),
|
||||
url_(url),
|
||||
method_(method) {
|
||||
}
|
||||
|
||||
HttpRequest::~HttpRequest()
|
||||
{
|
||||
HttpRequest::~HttpRequest() {
|
||||
}
|
||||
|
||||
HttpRequest::Method HttpRequest::method() const
|
||||
{
|
||||
return method_;
|
||||
HttpRequest::Method HttpRequest::method() const {
|
||||
return method_;
|
||||
}
|
||||
|
||||
|
||||
void HttpRequest::setMethod(Method method)
|
||||
{
|
||||
method_ = method;
|
||||
void HttpRequest::setMethod(Method method) {
|
||||
method_ = method;
|
||||
}
|
||||
|
||||
void HttpRequest::setUrl(const Url &url)
|
||||
{
|
||||
url_ = url;
|
||||
void HttpRequest::setUrl(const Url &url) {
|
||||
url_ = url;
|
||||
}
|
||||
|
||||
Url HttpRequest::url()const
|
||||
{
|
||||
return url_;
|
||||
Url HttpRequest::url()const {
|
||||
return url_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,42 +16,37 @@
|
||||
|
||||
#include <alibabacloud/core/HttpResponse.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
#define INVALID_STATUS_CODE -1
|
||||
namespace {
|
||||
#define INVALID_STATUS_CODE -1
|
||||
}
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
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) {
|
||||
}
|
||||
|
||||
HttpResponse::~HttpResponse()
|
||||
{
|
||||
HttpResponse::~HttpResponse() {
|
||||
}
|
||||
|
||||
HttpRequest HttpResponse::request() const
|
||||
{
|
||||
return request_;
|
||||
HttpRequest HttpResponse::request() const {
|
||||
return request_;
|
||||
}
|
||||
|
||||
void HttpResponse::setStatusCode(int code)
|
||||
{
|
||||
statusCode_ = code;
|
||||
void HttpResponse::setStatusCode(int code) {
|
||||
statusCode_ = code;
|
||||
}
|
||||
|
||||
int HttpResponse::statusCode() const
|
||||
{
|
||||
return statusCode_;
|
||||
int HttpResponse::statusCode() const {
|
||||
return statusCode_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
#include <alibabacloud/core/InstanceProfileCredentials.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
InstanceProfileCredentials::InstanceProfileCredentials() :
|
||||
BasicSessionCredentials(Credentials::InstanceProfile)
|
||||
{
|
||||
BasicSessionCredentials(Credentials::InstanceProfile) {
|
||||
}
|
||||
|
||||
InstanceProfileCredentials::~InstanceProfileCredentials()
|
||||
{
|
||||
}
|
||||
InstanceProfileCredentials::~InstanceProfileCredentials() {
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -15,93 +15,82 @@
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/InstanceProfileCredentialsProvider.h>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <json/json.h>
|
||||
#include "EcsMetadataFetcher.h"
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(const std::string & roleName, int durationSeconds):
|
||||
CredentialsProvider(),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedCredentials_("", ""),
|
||||
fetcher_(new EcsMetadataFetcher),
|
||||
expiry_()
|
||||
{
|
||||
fetcher_->setRoleName(roleName);
|
||||
namespace AlibabaCloud {
|
||||
|
||||
InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(
|
||||
const std::string & roleName, int durationSeconds):
|
||||
CredentialsProvider(),
|
||||
EcsMetadataFetcher(),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedCredentials_("", ""),
|
||||
expiry_() {
|
||||
setRoleName(roleName);
|
||||
}
|
||||
|
||||
InstanceProfileCredentialsProvider::~InstanceProfileCredentialsProvider()
|
||||
{
|
||||
delete fetcher_;
|
||||
InstanceProfileCredentialsProvider::~InstanceProfileCredentialsProvider() {
|
||||
}
|
||||
|
||||
std::string InstanceProfileCredentialsProvider::roleName()const
|
||||
{
|
||||
return fetcher_->roleName();
|
||||
Credentials InstanceProfileCredentialsProvider::getCredentials() {
|
||||
loadCredentials();
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
return cachedCredentials_;
|
||||
}
|
||||
|
||||
Credentials InstanceProfileCredentialsProvider::getCredentials()
|
||||
{
|
||||
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();
|
||||
|
||||
return (diff > 0 - 60);
|
||||
}
|
||||
|
||||
bool InstanceProfileCredentialsProvider::checkExpiry()const
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
|
||||
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;
|
||||
}
|
||||
|
||||
return (diff > 0 - 60);
|
||||
}
|
||||
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();
|
||||
|
||||
void InstanceProfileCredentialsProvider::loadCredentials()
|
||||
{
|
||||
if (checkExpiry())
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
if (checkExpiry())
|
||||
{
|
||||
auto outcome = fetcher_->getMetadata();
|
||||
Json::Value value;
|
||||
Json::Reader reader;
|
||||
if (reader.parse(outcome, value))
|
||||
{
|
||||
if (value["Code"] == nullptr
|
||||
&&value["AccessKeyId"] == nullptr
|
||||
&&value["AccessKeySecret"] == nullptr
|
||||
&&value["SecurityToken"] == nullptr
|
||||
&&value["Expiration"] == nullptr)
|
||||
{
|
||||
cachedCredentials_ = Credentials("","");
|
||||
return;
|
||||
}
|
||||
cachedCredentials_ = Credentials(accessKeyId,
|
||||
accessKeySecret,
|
||||
securityToken);
|
||||
|
||||
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);
|
||||
|
||||
std::tm tm = {};
|
||||
std::tm tm = {};
|
||||
#if defined(__GNUG__) && __GNUC__ < 5
|
||||
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");
|
||||
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");
|
||||
#endif
|
||||
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
}
|
||||
}
|
||||
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
3504
core/src/LocalEndpoints.h
Normal file
3504
core/src/LocalEndpoints.h
Normal file
File diff suppressed because it is too large
Load Diff
3508
core/src/LocalEndpointsForWindows.h
Executable file
3508
core/src/LocalEndpointsForWindows.h
Executable file
File diff suppressed because it is too large
Load Diff
@@ -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.
|
||||
@@ -16,71 +16,61 @@
|
||||
|
||||
#include <alibabacloud/core/NetworkProxy.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
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) {
|
||||
}
|
||||
|
||||
NetworkProxy::~NetworkProxy()
|
||||
{
|
||||
NetworkProxy::~NetworkProxy() {
|
||||
}
|
||||
|
||||
std::string NetworkProxy::hostName() const
|
||||
{
|
||||
return hostName_;
|
||||
std::string NetworkProxy::hostName() const {
|
||||
return hostName_;
|
||||
}
|
||||
|
||||
std::string NetworkProxy::password() const
|
||||
{
|
||||
return password_;
|
||||
std::string NetworkProxy::password() const {
|
||||
return password_;
|
||||
}
|
||||
|
||||
uint16_t NetworkProxy::port() const
|
||||
{
|
||||
return port_;
|
||||
uint16_t NetworkProxy::port() const {
|
||||
return port_;
|
||||
}
|
||||
|
||||
void NetworkProxy::setHostName(const std::string &hostName)
|
||||
{
|
||||
hostName_ = hostName;
|
||||
void NetworkProxy::setHostName(const std::string &hostName) {
|
||||
hostName_ = hostName;
|
||||
}
|
||||
|
||||
void NetworkProxy::setPassword(const std::string &password)
|
||||
{
|
||||
password_ = password;
|
||||
void NetworkProxy::setPassword(const std::string &password) {
|
||||
password_ = password;
|
||||
}
|
||||
|
||||
void NetworkProxy::setPort(uint16_t port)
|
||||
{
|
||||
port_ = port;
|
||||
void NetworkProxy::setPort(uint16_t port) {
|
||||
port_ = port;
|
||||
}
|
||||
|
||||
void NetworkProxy::setType(NetworkProxy::Type type)
|
||||
{
|
||||
type_ = type;
|
||||
void NetworkProxy::setType(NetworkProxy::Type type) {
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
void NetworkProxy::setUser(const std::string &user)
|
||||
{
|
||||
user_ = user;
|
||||
void NetworkProxy::setUser(const std::string &user) {
|
||||
user_ = user;
|
||||
}
|
||||
|
||||
NetworkProxy::Type NetworkProxy::type() const
|
||||
{
|
||||
return type_;
|
||||
NetworkProxy::Type NetworkProxy::type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
std::string NetworkProxy::user() const
|
||||
{
|
||||
return user_;
|
||||
std::string NetworkProxy::user() const {
|
||||
return user_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
@@ -15,166 +15,136 @@
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/RoaServiceClient.h>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
//#include <alibabacloud/core/RoaErrorMarshaller.h>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
}
|
||||
|
||||
RoaServiceClient::~RoaServiceClient()
|
||||
{
|
||||
RoaServiceClient::~RoaServiceClient() {
|
||||
}
|
||||
|
||||
std::string RoaServiceClient::canonicalizedResource(const std::string &path, std::map <std::string, std::string> ¶ms)const
|
||||
{
|
||||
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::string str = path;
|
||||
str.append("?").append(ss.str().substr(1));
|
||||
return 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());
|
||||
}
|
||||
|
||||
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::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";
|
||||
|
||||
return ss.str();
|
||||
HttpRequest RoaServiceClient::buildHttpRequest(const std::string & endpoint,
|
||||
const ServiceRequest &msg, HttpRequest::Method method)const {
|
||||
return buildHttpRequest(endpoint,
|
||||
dynamic_cast<const RoaServiceRequest& >(msg), method);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
HttpRequest RoaServiceClient::buildHttpRequest(const std::string & endpoint,
|
||||
const RoaServiceRequest &msg, HttpRequest::Method method) const {
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
HttpRequest RoaServiceClient::buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const
|
||||
{
|
||||
return buildHttpRequest(endpoint, dynamic_cast<const RoaServiceRequest& >(msg), method);
|
||||
}
|
||||
Url url;
|
||||
if (msg.scheme().empty()) {
|
||||
url.setScheme("https");
|
||||
} else {
|
||||
url.setScheme(msg.scheme());
|
||||
}
|
||||
url.setHost(endpoint);
|
||||
url.setPath(msg.resourcePath());
|
||||
|
||||
HttpRequest RoaServiceClient::buildHttpRequest(const std::string & endpoint, const RoaServiceRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
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;
|
||||
}
|
||||
|
||||
Url url;
|
||||
url.setScheme("https");
|
||||
url.setHost(endpoint);
|
||||
url.setPath(msg.resourcePath());
|
||||
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));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
HttpRequest request(url);
|
||||
request.setMethod(method);
|
||||
if (msg.parameter("Accept").empty()) {
|
||||
request.setHeader("Accept", "application/json");
|
||||
} else {
|
||||
request.setHeader("Accept", msg.parameter("Accept"));
|
||||
}
|
||||
|
||||
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 (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());
|
||||
}
|
||||
|
||||
HttpRequest request(url);
|
||||
request.setMethod(method);
|
||||
request.setHeader("Accept", "application/json");
|
||||
if (msg.hasContent()) {
|
||||
std::stringstream ss;
|
||||
ss << msg.contentSize();
|
||||
request.setHeader("Content-Length", ss.str());
|
||||
request.setHeader("Content-Type", "application/octet-stream");
|
||||
request.setHeader("Content-MD5", ComputeContentMD5(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;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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,14 @@
|
||||
#include <sstream>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
RoaServiceRequest::RoaServiceRequest(const std::string & product, const std::string & version) :
|
||||
ServiceRequest(product, version)
|
||||
{
|
||||
RoaServiceRequest::RoaServiceRequest(const std::string & product,
|
||||
const std::string & version) :
|
||||
ServiceRequest(product, version) {
|
||||
}
|
||||
|
||||
RoaServiceRequest::~RoaServiceRequest()
|
||||
{
|
||||
RoaServiceRequest::~RoaServiceRequest() {
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -15,115 +15,103 @@
|
||||
*/
|
||||
|
||||
#include <alibabacloud/core/RpcServiceClient.h>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
}
|
||||
|
||||
RpcServiceClient::~RpcServiceClient()
|
||||
{
|
||||
RpcServiceClient::~RpcServiceClient() {
|
||||
}
|
||||
|
||||
std::string RpcServiceClient::canonicalizedQuery(const std::map<std::string, std::string>& params) const
|
||||
{
|
||||
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);
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
HttpRequest RpcServiceClient::buildHttpRequest(const std::string & endpoint,
|
||||
const ServiceRequest &msg, HttpRequest::Method method)const {
|
||||
return buildHttpRequest(endpoint,
|
||||
dynamic_cast<const RpcServiceRequest& >(msg), method);
|
||||
}
|
||||
|
||||
HttpRequest RpcServiceClient::buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method )const
|
||||
{
|
||||
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();
|
||||
|
||||
HttpRequest RpcServiceClient::buildHttpRequest(const std::string & endpoint, const RpcServiceRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
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;
|
||||
url.setScheme("https");
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,25 +16,24 @@
|
||||
|
||||
#include <alibabacloud/core/RpcServiceRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
RpcServiceRequest::RpcServiceRequest(const std::string & product, const std::string & version, const std::string & action) :
|
||||
ServiceRequest(product, version)
|
||||
{
|
||||
setActionName(action);
|
||||
RpcServiceRequest::RpcServiceRequest(const std::string & product,
|
||||
const std::string & version, const std::string & action) :
|
||||
ServiceRequest(product, version) {
|
||||
setActionName(action);
|
||||
}
|
||||
|
||||
RpcServiceRequest::~RpcServiceRequest()
|
||||
{
|
||||
RpcServiceRequest::~RpcServiceRequest() {
|
||||
}
|
||||
|
||||
std::string RpcServiceRequest::actionName()const
|
||||
{
|
||||
return parameter("Action");
|
||||
std::string RpcServiceRequest::actionName()const {
|
||||
return parameter("Action");
|
||||
}
|
||||
|
||||
|
||||
void RpcServiceRequest::setActionName(const std::string & name)
|
||||
{
|
||||
setParameter("Action", name);
|
||||
}
|
||||
void RpcServiceRequest::setActionName(const std::string & name) {
|
||||
setParameter("Action", name);
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
#include <alibabacloud/core/Runnable.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
Runnable::Runnable(const std::function<void()> f) :
|
||||
f_(f)
|
||||
{
|
||||
f_(f) {
|
||||
}
|
||||
|
||||
void Runnable::run() const
|
||||
{
|
||||
f_();
|
||||
}
|
||||
void Runnable::run() const {
|
||||
f_();
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,142 +16,140 @@
|
||||
|
||||
#include <alibabacloud/core/ServiceRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
ServiceRequest::ServiceRequest(const std::string &product, const std::string &version) :
|
||||
content_(nullptr),
|
||||
contentSize_(0),
|
||||
params_(),
|
||||
product_(product),
|
||||
resourcePath_("/"),
|
||||
version_(version)
|
||||
{
|
||||
ServiceRequest::ServiceRequest(const std::string &product,
|
||||
const std::string &version) :
|
||||
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_)
|
||||
{
|
||||
setContent(other.content_, other.contentSize_);
|
||||
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_);
|
||||
}
|
||||
|
||||
ServiceRequest::ServiceRequest(ServiceRequest &&other)
|
||||
{
|
||||
*this = std::move(other);
|
||||
ServiceRequest::ServiceRequest(ServiceRequest &&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;
|
||||
ServiceRequest& ServiceRequest::operator=(const ServiceRequest &other) {
|
||||
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;
|
||||
ServiceRequest& ServiceRequest::operator=(ServiceRequest &&other) {
|
||||
if (this != &other)
|
||||
*this = std::move(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ServiceRequest::~ServiceRequest()
|
||||
{
|
||||
if (content_)
|
||||
delete content_;
|
||||
ServiceRequest::~ServiceRequest() {
|
||||
if (content_)
|
||||
delete content_;
|
||||
}
|
||||
|
||||
const char * ServiceRequest::content() const
|
||||
{
|
||||
return content_;
|
||||
const char * ServiceRequest::content() const {
|
||||
return content_;
|
||||
}
|
||||
|
||||
size_t ServiceRequest::contentSize() const
|
||||
{
|
||||
return contentSize_;
|
||||
size_t ServiceRequest::contentSize() const {
|
||||
return contentSize_;
|
||||
}
|
||||
|
||||
bool ServiceRequest::hasContent() const
|
||||
{
|
||||
return (contentSize_ != 0);
|
||||
bool ServiceRequest::hasContent() const {
|
||||
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_);
|
||||
}
|
||||
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_);
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceRequest::addParameter(const ParameterNameType & name, const ParameterValueType & value)
|
||||
{
|
||||
setParameter(name, value);
|
||||
void ServiceRequest::addParameter(const ParameterNameType & name,
|
||||
const ParameterValueType & value) {
|
||||
setParameter(name, value);
|
||||
}
|
||||
|
||||
ServiceRequest::ParameterValueType ServiceRequest::parameter(const ParameterNameType &name)const
|
||||
{
|
||||
return params_.at(name);
|
||||
ServiceRequest::ParameterValueType ServiceRequest::parameter(
|
||||
const ParameterNameType &name)const {
|
||||
ParameterCollection::const_iterator it = params_.find(name);
|
||||
if (it == params_.end()) {
|
||||
return ParameterValueType("");
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
ServiceRequest::ParameterCollection ServiceRequest::parameters() const
|
||||
{
|
||||
return params_;
|
||||
ServiceRequest::ParameterCollection ServiceRequest::parameters() const {
|
||||
return params_;
|
||||
}
|
||||
|
||||
void ServiceRequest::removeParameter(const ParameterNameType & name)
|
||||
{
|
||||
params_.erase(name);
|
||||
void ServiceRequest::removeParameter(const ParameterNameType & name) {
|
||||
params_.erase(name);
|
||||
}
|
||||
|
||||
void ServiceRequest::setParameter(const ParameterNameType &name, const ParameterValueType &value)
|
||||
{
|
||||
params_[name] = value;
|
||||
void ServiceRequest::setParameter(const ParameterNameType &name,
|
||||
const ParameterValueType &value) {
|
||||
params_[name] = value;
|
||||
}
|
||||
|
||||
void ServiceRequest::setParameters(const ParameterCollection & params)
|
||||
{
|
||||
params_ = params;
|
||||
void ServiceRequest::setParameters(const ParameterCollection & params) {
|
||||
params_ = params;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::version()const
|
||||
{
|
||||
return version_;
|
||||
std::string ServiceRequest::version()const {
|
||||
return version_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setVersion(const std::string &version)
|
||||
{
|
||||
version_ = version;
|
||||
void ServiceRequest::setVersion(const std::string &version) {
|
||||
version_ = version;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::product() const
|
||||
{
|
||||
return product_;
|
||||
std::string ServiceRequest::product() const {
|
||||
return product_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setProduct(const std::string & product)
|
||||
{
|
||||
product_ = product;
|
||||
void ServiceRequest::setProduct(const std::string & product) {
|
||||
product_ = product;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::resourcePath() const
|
||||
{
|
||||
return resourcePath_;
|
||||
std::string ServiceRequest::resourcePath() const {
|
||||
return resourcePath_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setResourcePath(const std::string & path)
|
||||
{
|
||||
resourcePath_ = path;
|
||||
}
|
||||
void ServiceRequest::setResourcePath(const std::string & path) {
|
||||
resourcePath_ = path;
|
||||
}
|
||||
|
||||
void ServiceRequest::setScheme(const std::string scheme) {
|
||||
scheme_ = scheme;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::scheme() const {
|
||||
return scheme_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,23 +16,21 @@
|
||||
|
||||
#include <alibabacloud/core/ServiceResult.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
ServiceResult::ServiceResult() :
|
||||
requestId_()
|
||||
{
|
||||
requestId_() {
|
||||
}
|
||||
|
||||
ServiceResult::~ServiceResult()
|
||||
{
|
||||
ServiceResult::~ServiceResult() {
|
||||
}
|
||||
|
||||
std::string ServiceResult::requestId() const
|
||||
{
|
||||
return requestId_;
|
||||
std::string ServiceResult::requestId() const {
|
||||
return requestId_;
|
||||
}
|
||||
|
||||
void ServiceResult::setRequestId(const std::string & requestId)
|
||||
{
|
||||
requestId_ = requestId;
|
||||
void ServiceResult::setRequestId(const std::string & requestId) {
|
||||
requestId_ = requestId;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,30 +16,28 @@
|
||||
|
||||
#include <alibabacloud/core/Signer.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
Signer::Signer(Type type, const std::string & name, const std::string & version) :
|
||||
type_(type),
|
||||
name_(name),
|
||||
version_(version)
|
||||
{
|
||||
Signer::Signer(Type type, const std::string & name,
|
||||
const std::string & version) :
|
||||
type_(type),
|
||||
name_(name),
|
||||
version_(version) {
|
||||
}
|
||||
|
||||
Signer::~Signer()
|
||||
{
|
||||
Signer::~Signer() {
|
||||
}
|
||||
|
||||
std::string Signer::name() const
|
||||
{
|
||||
return name_;
|
||||
std::string Signer::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
Signer::Type Signer::type() const
|
||||
{
|
||||
return type_;
|
||||
Signer::Type Signer::type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
std::string Signer::version() const
|
||||
{
|
||||
return version_;
|
||||
std::string Signer::version() const {
|
||||
return version_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -16,25 +16,25 @@
|
||||
|
||||
#include <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
SimpleCredentialsProvider::SimpleCredentialsProvider(const Credentials &credentials):
|
||||
CredentialsProvider(),
|
||||
credentials_(credentials)
|
||||
{
|
||||
SimpleCredentialsProvider::SimpleCredentialsProvider(
|
||||
const Credentials &credentials):
|
||||
CredentialsProvider(),
|
||||
credentials_(credentials) {
|
||||
}
|
||||
|
||||
SimpleCredentialsProvider::SimpleCredentialsProvider(const std::string & accessKeyId, const std::string & accessKeySecret) :
|
||||
CredentialsProvider(),
|
||||
credentials_(accessKeyId, accessKeySecret)
|
||||
{
|
||||
SimpleCredentialsProvider::SimpleCredentialsProvider(
|
||||
const std::string & accessKeyId, const std::string & accessKeySecret) :
|
||||
CredentialsProvider(),
|
||||
credentials_(accessKeyId, accessKeySecret) {
|
||||
}
|
||||
|
||||
SimpleCredentialsProvider::~SimpleCredentialsProvider()
|
||||
{
|
||||
SimpleCredentialsProvider::~SimpleCredentialsProvider() {
|
||||
}
|
||||
|
||||
Credentials SimpleCredentialsProvider::getCredentials()
|
||||
{
|
||||
return credentials_;
|
||||
Credentials SimpleCredentialsProvider::getCredentials() {
|
||||
return credentials_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
@@ -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.
|
||||
@@ -18,71 +18,71 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Sts;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
StsAssumeRoleCredentialsProvider::StsAssumeRoleCredentialsProvider(const std::shared_ptr<StsClient>& stsClient, const std::string & roleArn, const std::string & roleSessionName, const std::string & policy, int durationSeconds) :
|
||||
CredentialsProvider(),
|
||||
stsClient_(stsClient),
|
||||
roleArn_(roleArn),
|
||||
roleSessionName_(roleSessionName),
|
||||
policy_(policy),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedCredentials_("", ""),
|
||||
expiry_()
|
||||
{
|
||||
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_() {
|
||||
}
|
||||
|
||||
StsAssumeRoleCredentialsProvider::~StsAssumeRoleCredentialsProvider()
|
||||
{
|
||||
StsAssumeRoleCredentialsProvider::~StsAssumeRoleCredentialsProvider() {
|
||||
}
|
||||
|
||||
Credentials StsAssumeRoleCredentialsProvider::getCredentials()
|
||||
{
|
||||
loadCredentials();
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
return cachedCredentials_;
|
||||
Credentials StsAssumeRoleCredentialsProvider::getCredentials() {
|
||||
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();
|
||||
bool StsAssumeRoleCredentialsProvider::checkExpiry()const {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto diff =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(now - expiry_).count();
|
||||
|
||||
return (diff > 0 - 60);
|
||||
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_);
|
||||
void StsAssumeRoleCredentialsProvider::loadCredentials() {
|
||||
if (checkExpiry()) {
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
if (checkExpiry()) {
|
||||
Sts::Model::AssumeRoleRequest request;
|
||||
request.setRoleArn(roleArn_);
|
||||
request.setRoleSessionName(roleSessionName_);
|
||||
request.setPolicy(policy_);
|
||||
request.setDurationSeconds(durationSeconds_);
|
||||
|
||||
auto assumeRoleOutcome = stsClient_->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);
|
||||
#else
|
||||
std::stringstream ss(stsCredentials.expiration);
|
||||
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
|
||||
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");
|
||||
#endif
|
||||
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
459
core/src/Url.cc
459
core/src/Url.cc
@@ -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,327 +18,296 @@
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
namespace AlibabaCloud {
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
#define INVALID_PORT -1
|
||||
}
|
||||
|
||||
Url::Url(const std::string & url) :
|
||||
scheme_(),
|
||||
userName_(),
|
||||
password_(),
|
||||
host_(),
|
||||
path_(),
|
||||
port_(INVALID_PORT),
|
||||
query_(),
|
||||
fragment_()
|
||||
{
|
||||
if(!url.empty())
|
||||
fromString(url);
|
||||
scheme_(),
|
||||
userName_(),
|
||||
password_(),
|
||||
host_(),
|
||||
path_(),
|
||||
port_(INVALID_PORT),
|
||||
query_(),
|
||||
fragment_() {
|
||||
if (!url.empty())
|
||||
fromString(url);
|
||||
}
|
||||
|
||||
Url::~Url()
|
||||
{
|
||||
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_;
|
||||
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_;
|
||||
}
|
||||
|
||||
bool Url::operator!=(const Url &url) const
|
||||
{
|
||||
return !(*this == url);
|
||||
bool Url::operator!=(const Url &url) const {
|
||||
return !(*this == url);
|
||||
}
|
||||
|
||||
std::string Url::authority() const
|
||||
{
|
||||
if (!isValid())
|
||||
return std::string();
|
||||
std::string Url::authority() const {
|
||||
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();
|
||||
void Url::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_;
|
||||
std::string Url::fragment() const {
|
||||
return fragment_;
|
||||
}
|
||||
|
||||
void Url::fromString(const std::string & url)
|
||||
{
|
||||
clear();
|
||||
if (url.empty())
|
||||
return;
|
||||
void Url::fromString(const std::string & url) {
|
||||
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();
|
||||
bool Url::hasFragment() const {
|
||||
return !fragment_.empty();
|
||||
}
|
||||
|
||||
bool Url::hasQuery() const
|
||||
{
|
||||
return !query_.empty();
|
||||
bool Url::hasQuery() const {
|
||||
return !query_.empty();
|
||||
}
|
||||
|
||||
std::string Url::host() const
|
||||
{
|
||||
return host_;
|
||||
std::string Url::host() const {
|
||||
return host_;
|
||||
}
|
||||
|
||||
bool Url::isEmpty() const
|
||||
{
|
||||
return scheme_.empty()
|
||||
&& userName_.empty()
|
||||
&& password_.empty()
|
||||
&& host_.empty()
|
||||
&& path_.empty()
|
||||
&& (port_ == INVALID_PORT)
|
||||
&& query_.empty()
|
||||
&& fragment_.empty();
|
||||
bool Url::isEmpty() const {
|
||||
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;
|
||||
bool Url::isValid() const {
|
||||
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_;
|
||||
int Url::port() const {
|
||||
return port_;
|
||||
}
|
||||
|
||||
std::string Url::password() const
|
||||
{
|
||||
return password_;
|
||||
std::string Url::password() const {
|
||||
return password_;
|
||||
}
|
||||
|
||||
std::string Url::path() const
|
||||
{
|
||||
return path_;
|
||||
std::string Url::path() const {
|
||||
return path_;
|
||||
}
|
||||
|
||||
std::string Url::query() const
|
||||
{
|
||||
return query_;
|
||||
std::string Url::query() const {
|
||||
return query_;
|
||||
}
|
||||
|
||||
std::string Url::scheme() const
|
||||
{
|
||||
return scheme_;
|
||||
std::string Url::scheme() const {
|
||||
return scheme_;
|
||||
}
|
||||
|
||||
void Url::setAuthority(const std::string & authority)
|
||||
{
|
||||
if (authority.empty()) {
|
||||
setUserInfo("");
|
||||
setHost("");
|
||||
setPort(INVALID_PORT);
|
||||
return;
|
||||
}
|
||||
void Url::setAuthority(const std::string & authority) {
|
||||
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;
|
||||
void Url::setFragment(const std::string & 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);
|
||||
void Url::setHost(const std::string & host) {
|
||||
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;
|
||||
void Url::setPassword(const std::string & password) {
|
||||
password_ = password;
|
||||
}
|
||||
|
||||
void Url::setPath(const std::string & path)
|
||||
{
|
||||
path_ = path;
|
||||
void Url::setPath(const std::string & path) {
|
||||
path_ = path;
|
||||
}
|
||||
|
||||
void Url::setPort(int port)
|
||||
{
|
||||
port_ = port;
|
||||
void Url::setPort(int port) {
|
||||
port_ = port;
|
||||
}
|
||||
|
||||
void Url::setQuery(const std::string & query)
|
||||
{
|
||||
query_ = query;
|
||||
void Url::setQuery(const std::string & 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);
|
||||
void Url::setScheme(const std::string & scheme) {
|
||||
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;
|
||||
}
|
||||
void Url::setUserInfo(const std::string & userInfo) {
|
||||
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;
|
||||
void Url::setUserName(const std::string & userName) {
|
||||
userName_ = userName;
|
||||
}
|
||||
|
||||
std::string Url::toString() const
|
||||
{
|
||||
if (!isValid())
|
||||
return std::string();
|
||||
std::string Url::toString() const {
|
||||
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();
|
||||
std::string Url::userInfo() const {
|
||||
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_;
|
||||
std::string Url::userName() const {
|
||||
return userName_;
|
||||
}
|
||||
|
||||
} // namespace AlibabaCloud
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user