50
3rdparty/CMakeLists.txt
vendored
Normal file
50
3rdparty/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
ExternalProject_Add(jsoncpp
|
||||
URL https://github.com/open-source-parsers/jsoncpp/archive/0.10.5.tar.gz
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
||||
-DJSONCPP_WITH_TESTS=OFF
|
||||
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF
|
||||
-DJSONCPP_WITH_WARNING_AS_ERROR=OFF
|
||||
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF
|
||||
-DJSONCPP_WITH_CMAKE_PACKAGE=OFF
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DBUILD_STATIC_LIBS=ON
|
||||
)
|
||||
|
||||
ExternalProject_Add(curl
|
||||
URL https://github.com/curl/curl/releases/download/curl-7_55_1/curl-7.55.1.tar.gz
|
||||
CMAKE_ARGS -DBUILD_CURL_EXE=OFF
|
||||
-DBUILD_TESTING=OFF
|
||||
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
||||
-DCMAKE_USE_WINSSL=ON
|
||||
-DCURL_STATICLIB=ON
|
||||
-DENABLE_MANUAL=OFF
|
||||
-DHTTP_ONLY=ON
|
||||
)
|
||||
endif()
|
||||
|
||||
ExternalProject_Add(catch
|
||||
URL https://github.com/catchorg/Catch2/releases/download/v2.0.1/catch.hpp
|
||||
TIMEOUT 10
|
||||
DOWNLOAD_NO_EXTRACT 1
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND
|
||||
${CMAKE_COMMAND} -E copy_if_different <DOWNLOADED_FILE> <INSTALL_DIR>
|
||||
)
|
||||
52
CMakeLists.txt
Executable file
52
CMakeLists.txt
Executable file
@@ -0,0 +1,52 @@
|
||||
#
|
||||
# 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_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()
|
||||
336
Doxyfile
Normal file
336
Doxyfile
Normal file
@@ -0,0 +1,336 @@
|
||||
# Doxyfile 1.8.13
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = "alibabacloud-cpp-sdk"
|
||||
PROJECT_NUMBER = 0.0.1
|
||||
PROJECT_BRIEF = "Alibaba Cloud SDK for C++"
|
||||
PROJECT_LOGO =
|
||||
OUTPUT_DIRECTORY =
|
||||
CREATE_SUBDIRS = NO
|
||||
ALLOW_UNICODE_NAMES = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF = "The $name class" \
|
||||
"The $name widget" \
|
||||
"The $name file" \
|
||||
is \
|
||||
provides \
|
||||
specifies \
|
||||
contains \
|
||||
represents \
|
||||
a \
|
||||
an \
|
||||
the
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = YES
|
||||
STRIP_FROM_PATH =
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = NO
|
||||
QT_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
INHERIT_DOCS = YES
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 4
|
||||
ALIASES =
|
||||
TCL_SUBST =
|
||||
OPTIMIZE_OUTPUT_FOR_C = NO
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
OPTIMIZE_FOR_FORTRAN = NO
|
||||
OPTIMIZE_OUTPUT_VHDL = NO
|
||||
EXTENSION_MAPPING =
|
||||
MARKDOWN_SUPPORT = YES
|
||||
TOC_INCLUDE_HEADINGS = 0
|
||||
AUTOLINK_SUPPORT = YES
|
||||
BUILTIN_STL_SUPPORT = YES
|
||||
CPP_CLI_SUPPORT = NO
|
||||
SIP_SUPPORT = NO
|
||||
IDL_PROPERTY_SUPPORT = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
GROUP_NESTED_COMPOUNDS = NO
|
||||
SUBGROUPING = YES
|
||||
INLINE_GROUPED_CLASSES = NO
|
||||
INLINE_SIMPLE_STRUCTS = NO
|
||||
TYPEDEF_HIDES_STRUCT = NO
|
||||
LOOKUP_CACHE_SIZE = 0
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
EXTRACT_ALL = NO
|
||||
EXTRACT_PRIVATE = NO
|
||||
EXTRACT_PACKAGE = NO
|
||||
EXTRACT_STATIC = NO
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = NO
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
HIDE_COMPOUND_REFERENCE= NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
SHOW_GROUPED_MEMB_INC = NO
|
||||
FORCE_LOCAL_INCLUDES = NO
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_BRIEF_DOCS = NO
|
||||
SORT_MEMBERS_CTORS_1ST = NO
|
||||
SORT_GROUP_NAMES = NO
|
||||
SORT_BY_SCOPE_NAME = NO
|
||||
STRICT_PROTO_MATCHING = NO
|
||||
GENERATE_TODOLIST = YES
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = YES
|
||||
GENERATE_DEPRECATEDLIST= YES
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = NO
|
||||
SHOW_FILES = NO
|
||||
SHOW_NAMESPACES = YES
|
||||
FILE_VERSION_FILTER =
|
||||
LAYOUT_FILE =
|
||||
CITE_BIB_FILES =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to warning and progress messages
|
||||
#---------------------------------------------------------------------------
|
||||
QUIET = NO
|
||||
WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = YES
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
WARN_AS_ERROR = NO
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = ./
|
||||
INPUT_ENCODING = UTF-8
|
||||
FILE_PATTERNS = *.cc \
|
||||
*.h \
|
||||
*.md
|
||||
RECURSIVE = YES
|
||||
EXCLUDE =
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS = */3rdparty/* \
|
||||
*/CMakeFiles/* \
|
||||
*/src/*.h \
|
||||
*/tests/*
|
||||
EXCLUDE_SYMBOLS =
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS = *
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_PATTERNS =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
FILTER_SOURCE_PATTERNS =
|
||||
USE_MDFILE_AS_MAINPAGE = ./README.md
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to source browsing
|
||||
#---------------------------------------------------------------------------
|
||||
SOURCE_BROWSER = YES
|
||||
INLINE_SOURCES = NO
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
REFERENCED_BY_RELATION = NO
|
||||
REFERENCES_RELATION = NO
|
||||
REFERENCES_LINK_SOURCE = YES
|
||||
SOURCE_TOOLTIPS = YES
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
CLANG_ASSISTED_PARSING = NO
|
||||
CLANG_OPTIONS =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
ALPHABETICAL_INDEX = YES
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the HTML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_HTML = YES
|
||||
HTML_OUTPUT = html
|
||||
HTML_FILE_EXTENSION = .html
|
||||
HTML_HEADER =
|
||||
HTML_FOOTER =
|
||||
HTML_STYLESHEET =
|
||||
HTML_EXTRA_STYLESHEET =
|
||||
HTML_EXTRA_FILES =
|
||||
HTML_COLORSTYLE_HUE = 220
|
||||
HTML_COLORSTYLE_SAT = 100
|
||||
HTML_COLORSTYLE_GAMMA = 80
|
||||
HTML_TIMESTAMP = NO
|
||||
HTML_DYNAMIC_SECTIONS = NO
|
||||
HTML_INDEX_NUM_ENTRIES = 100
|
||||
GENERATE_DOCSET = NO
|
||||
DOCSET_FEEDNAME = "Doxygen generated docs"
|
||||
DOCSET_BUNDLE_ID = org.doxygen.Project
|
||||
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
|
||||
DOCSET_PUBLISHER_NAME = Publisher
|
||||
GENERATE_HTMLHELP = NO
|
||||
CHM_FILE =
|
||||
HHC_LOCATION =
|
||||
GENERATE_CHI = NO
|
||||
CHM_INDEX_ENCODING =
|
||||
BINARY_TOC = NO
|
||||
TOC_EXPAND = NO
|
||||
GENERATE_QHP = NO
|
||||
QCH_FILE =
|
||||
QHP_NAMESPACE = org.doxygen.Project
|
||||
QHP_VIRTUAL_FOLDER = doc
|
||||
QHP_CUST_FILTER_NAME =
|
||||
QHP_CUST_FILTER_ATTRS =
|
||||
QHP_SECT_FILTER_ATTRS =
|
||||
QHG_LOCATION =
|
||||
GENERATE_ECLIPSEHELP = NO
|
||||
ECLIPSE_DOC_ID = org.doxygen.Project
|
||||
DISABLE_INDEX = NO
|
||||
GENERATE_TREEVIEW = NO
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
TREEVIEW_WIDTH = 250
|
||||
EXT_LINKS_IN_WINDOW = NO
|
||||
FORMULA_FONTSIZE = 10
|
||||
FORMULA_TRANSPARENT = YES
|
||||
USE_MATHJAX = NO
|
||||
MATHJAX_FORMAT = HTML-CSS
|
||||
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
|
||||
MATHJAX_EXTENSIONS =
|
||||
MATHJAX_CODEFILE =
|
||||
SEARCHENGINE = YES
|
||||
SERVER_BASED_SEARCH = NO
|
||||
EXTERNAL_SEARCH = NO
|
||||
SEARCHENGINE_URL =
|
||||
SEARCHDATA_FILE = searchdata.xml
|
||||
EXTERNAL_SEARCH_ID =
|
||||
EXTRA_SEARCH_MAPPINGS =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_LATEX = YES
|
||||
LATEX_OUTPUT = latex
|
||||
LATEX_CMD_NAME = latex
|
||||
MAKEINDEX_CMD_NAME = makeindex
|
||||
COMPACT_LATEX = NO
|
||||
PAPER_TYPE = a4
|
||||
EXTRA_PACKAGES =
|
||||
LATEX_HEADER =
|
||||
LATEX_FOOTER =
|
||||
LATEX_EXTRA_STYLESHEET =
|
||||
LATEX_EXTRA_FILES =
|
||||
PDF_HYPERLINKS = YES
|
||||
USE_PDFLATEX = YES
|
||||
LATEX_BATCHMODE = NO
|
||||
LATEX_HIDE_INDICES = NO
|
||||
LATEX_SOURCE_CODE = NO
|
||||
LATEX_BIB_STYLE = plain
|
||||
LATEX_TIMESTAMP = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_RTF = NO
|
||||
RTF_OUTPUT = rtf
|
||||
COMPACT_RTF = NO
|
||||
RTF_HYPERLINKS = NO
|
||||
RTF_STYLESHEET_FILE =
|
||||
RTF_EXTENSIONS_FILE =
|
||||
RTF_SOURCE_CODE = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the man page output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_MAN = NO
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_SUBDIR =
|
||||
MAN_LINKS = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the XML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_XML = NO
|
||||
XML_OUTPUT = xml
|
||||
XML_PROGRAMLISTING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the DOCBOOK output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_DOCBOOK = NO
|
||||
DOCBOOK_OUTPUT = docbook
|
||||
DOCBOOK_PROGRAMLISTING = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options for the AutoGen Definitions output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the Perl module output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_PERLMOD = NO
|
||||
PERLMOD_LATEX = NO
|
||||
PERLMOD_PRETTY = YES
|
||||
PERLMOD_MAKEVAR_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the preprocessor
|
||||
#---------------------------------------------------------------------------
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = NO
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED =
|
||||
EXPAND_AS_DEFINED =
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to external references
|
||||
#---------------------------------------------------------------------------
|
||||
TAGFILES =
|
||||
GENERATE_TAGFILE =
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = YES
|
||||
EXTERNAL_PAGES = YES
|
||||
PERL_PATH = /usr/bin/perl
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = YES
|
||||
MSCGEN_PATH =
|
||||
DIA_PATH =
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
HAVE_DOT = NO
|
||||
DOT_NUM_THREADS = 0
|
||||
DOT_FONTNAME = Helvetica
|
||||
DOT_FONTSIZE = 10
|
||||
DOT_FONTPATH =
|
||||
CLASS_GRAPH = YES
|
||||
COLLABORATION_GRAPH = YES
|
||||
GROUP_GRAPHS = YES
|
||||
UML_LOOK = NO
|
||||
UML_LIMIT_NUM_FIELDS = 10
|
||||
TEMPLATE_RELATIONS = NO
|
||||
INCLUDE_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
CALL_GRAPH = NO
|
||||
CALLER_GRAPH = NO
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
DIRECTORY_GRAPH = YES
|
||||
DOT_IMAGE_FORMAT = png
|
||||
INTERACTIVE_SVG = NO
|
||||
DOT_PATH =
|
||||
DOTFILE_DIRS =
|
||||
MSCFILE_DIRS =
|
||||
DIAFILE_DIRS =
|
||||
PLANTUML_JAR_PATH =
|
||||
PLANTUML_CFG_FILE =
|
||||
PLANTUML_INCLUDE_PATH =
|
||||
DOT_GRAPH_MAX_NODES = 50
|
||||
MAX_DOT_GRAPH_DEPTH = 0
|
||||
DOT_TRANSPARENT = NO
|
||||
DOT_MULTI_TARGETS = NO
|
||||
GENERATE_LEGEND = YES
|
||||
DOT_CLEANUP = YES
|
||||
13
LICENSE
Normal file
13
LICENSE
Normal file
@@ -0,0 +1,13 @@
|
||||
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.
|
||||
25
core-tests/CMakeLists.txt
Normal file
25
core-tests/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
33
core-tests/httpmessage.cc
Normal file
33
core-tests/httpmessage.cc
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
18
core-tests/main.cc
Normal file
18
core-tests/main.cc
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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>
|
||||
31
core-tests/signer.cc
Normal file
31
core-tests/signer.cc
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
63
core-tests/url.cc
Normal file
63
core-tests/url.cc
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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() == "");
|
||||
}
|
||||
181
core/CMakeLists.txt
Executable file
181
core/CMakeLists.txt
Executable file
@@ -0,0 +1,181 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
configure_file(src/Config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/alibabacloud/core/Config.h @ONLY)
|
||||
|
||||
set(core_public_header
|
||||
include/alibabacloud/core/AlibabaCloud.h
|
||||
include/alibabacloud/core/AsyncCallerContext.h
|
||||
include/alibabacloud/core/ClientConfiguration.h
|
||||
include/alibabacloud/core/CommonClient.h
|
||||
include/alibabacloud/core/CommonRequest.h
|
||||
include/alibabacloud/core/CommonResponse.h
|
||||
include/alibabacloud/core/Config.h
|
||||
include/alibabacloud/core/CoreClient.h
|
||||
include/alibabacloud/core/CoreExport.h
|
||||
include/alibabacloud/core/Credentials.h
|
||||
include/alibabacloud/core/CredentialsProvider.h
|
||||
include/alibabacloud/core/EcsInstanceProfileConfigLoader.h
|
||||
include/alibabacloud/core/EndpointProvider.h
|
||||
include/alibabacloud/core/Error.h
|
||||
include/alibabacloud/core/Global.h
|
||||
include/alibabacloud/core/HmacSha1Signer.h
|
||||
include/alibabacloud/core/HttpClient.h
|
||||
include/alibabacloud/core/HttpMessage.h
|
||||
include/alibabacloud/core/HttpResponse.h
|
||||
include/alibabacloud/core/HttpRequest.h
|
||||
include/alibabacloud/core/InstanceProfileConfigLoader.h
|
||||
include/alibabacloud/core/InstanceProfileCredentialsProvider.h
|
||||
include/alibabacloud/core/NetworkProxy.h
|
||||
include/alibabacloud/core/Outcome.h
|
||||
include/alibabacloud/core/Profile.h
|
||||
include/alibabacloud/core/Runnable.h
|
||||
include/alibabacloud/core/RoaServiceClient.h
|
||||
include/alibabacloud/core/RoaServiceRequest.h
|
||||
include/alibabacloud/core/RpcServiceClient.h
|
||||
include/alibabacloud/core/RpcServiceRequest.h
|
||||
include/alibabacloud/core/ServiceRequest.h
|
||||
include/alibabacloud/core/ServiceResult.h
|
||||
include/alibabacloud/core/Signer.h
|
||||
include/alibabacloud/core/SimpleCredentialsProvider.h
|
||||
include/alibabacloud/core/StsAssumeRoleCredentialsProvider.h
|
||||
include/alibabacloud/core/Url.h
|
||||
include/alibabacloud/core/location/LocationClient.h
|
||||
include/alibabacloud/core/location/LocationRequest.h
|
||||
include/alibabacloud/core/location/model/DescribeEndpointsRequest.h
|
||||
include/alibabacloud/core/location/model/DescribeEndpointsResult.h
|
||||
include/alibabacloud/core/sts/StsClient.h
|
||||
include/alibabacloud/core/sts/StsRequest.h
|
||||
include/alibabacloud/core/sts/model/AssumeRoleRequest.h
|
||||
include/alibabacloud/core/sts/model/AssumeRoleResult.h
|
||||
include/alibabacloud/core/sts/model/GetCallerIdentityRequest.h
|
||||
include/alibabacloud/core/sts/model/GetCallerIdentityResult.h
|
||||
)
|
||||
|
||||
set(core_src
|
||||
src/AlibabaCloud.cc
|
||||
src/AsyncCallerContext.cc
|
||||
src/ClientConfiguration.cc
|
||||
src/CommonClient.cc
|
||||
src/CommonRequest.cc
|
||||
src/CommonResponse.cc
|
||||
src/CoreClient.cc
|
||||
src/Credentials.cc
|
||||
src/CredentialsProvider.cc
|
||||
src/CurlHttpClient.h
|
||||
src/CurlHttpClient.cc
|
||||
src/EcsInstanceProfileConfigLoader.cc
|
||||
src/EcsMetadataClient.h
|
||||
src/EcsMetadataClient.cc
|
||||
src/EndpointProvider.cc
|
||||
src/Error.cc
|
||||
src/Executor.cc
|
||||
src/Executor.h
|
||||
src/HmacSha1Signer.cc
|
||||
src/HttpClient.cc
|
||||
src/HttpMessage.cc
|
||||
src/HttpResponse.cc
|
||||
src/HttpRequest.cc
|
||||
src/InstanceProfileConfigLoader.cc
|
||||
src/InstanceProfileCredentialsProvider.cc
|
||||
src/NetworkProxy.cc
|
||||
src/Outcome.cc
|
||||
src/Profile.cc
|
||||
src/Runnable.cc
|
||||
src/RoaServiceClient.cc
|
||||
src/RoaServiceRequest.cc
|
||||
src/RpcServiceClient.cc
|
||||
src/RpcServiceRequest.cc
|
||||
src/ServiceRequest.cc
|
||||
src/ServiceResult.cc
|
||||
src/Signer.cc
|
||||
src/SimpleCredentialsProvider.cc
|
||||
src/StsAssumeRoleCredentialsProvider.cc
|
||||
src/Url.cc
|
||||
src/Utils.h
|
||||
src/Utils.cc
|
||||
src/location/LocationClient.cc
|
||||
src/location/LocationRequest.cc
|
||||
src/location/model/DescribeEndpointsRequest.cc
|
||||
src/location/model/DescribeEndpointsResult.cc
|
||||
src/sts/StsClient.cc
|
||||
src/sts/StsRequest.cc
|
||||
src/sts/model/AssumeRoleRequest.cc
|
||||
src/sts/model/AssumeRoleResult.cc
|
||||
src/sts/model/GetCallerIdentityRequest.cc
|
||||
src/sts/model/GetCallerIdentityResult.cc
|
||||
)
|
||||
|
||||
add_library(core ${LIB_TYPE} ${core_public_header} ${core_src})
|
||||
|
||||
set_target_properties(core
|
||||
PROPERTIES
|
||||
LINKER_LANGUAGE CXX
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
OUTPUT_NAME ${TARGET_OUTPUT_NAME_PREFIX}core
|
||||
PUBLIC_HEADER "${core_public_header}"
|
||||
)
|
||||
|
||||
if(${LIB_TYPE} STREQUAL "SHARED")
|
||||
set_target_properties(core
|
||||
PROPERTIES
|
||||
DEFINE_SYMBOL ALIBABACLOUD_CORE_LIBRARY)
|
||||
endif()
|
||||
|
||||
target_include_directories(core
|
||||
PRIVATE include )
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
ExternalProject_Get_Property(curl INSTALL_DIR)
|
||||
set(curl_install_dir ${INSTALL_DIR})
|
||||
ExternalProject_Get_Property(jsoncpp INSTALL_DIR)
|
||||
set(jsoncpp_install_dir ${INSTALL_DIR})
|
||||
add_dependencies(core
|
||||
curl
|
||||
jsoncpp )
|
||||
target_include_directories(core
|
||||
PRIVATE ${curl_install_dir}/include
|
||||
${jsoncpp_install_dir}/include
|
||||
${tinyxml2_install_dir}/include)
|
||||
target_link_libraries(core
|
||||
Crypt32
|
||||
Rpcrt4
|
||||
Ws2_32
|
||||
${jsoncpp_install_dir}/lib/jsoncpp.lib
|
||||
debug ${curl_install_dir}/lib/libcurl-d.lib
|
||||
optimized ${curl_install_dir}/lib/libcurl.lib
|
||||
)
|
||||
target_compile_definitions(core
|
||||
PRIVATE CURL_STATICLIB
|
||||
_CRT_SECURE_NO_WARNINGS)
|
||||
else()
|
||||
target_include_directories(core
|
||||
PRIVATE /usr/include/jsoncpp)
|
||||
target_link_libraries(core
|
||||
crypto
|
||||
curl
|
||||
jsoncpp
|
||||
uuid )
|
||||
endif()
|
||||
|
||||
install(TARGETS core
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/core
|
||||
)
|
||||
1
core/include/alibabacloud/core/.gitignore
vendored
Normal file
1
core/include/alibabacloud/core/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Config.h
|
||||
29
core/include/alibabacloud/core/AlibabaCloud.h
Normal file
29
core/include/alibabacloud/core/AlibabaCloud.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ALIBABACLOUD_H_
|
||||
#define ALIBABACLOUD_CORE_ALIBABACLOUD_H_
|
||||
|
||||
#include "CoreExport.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
ALIBABACLOUD_CORE_EXPORT void InitializeSdk();
|
||||
ALIBABACLOUD_CORE_EXPORT bool IsSdkInitialized();
|
||||
ALIBABACLOUD_CORE_EXPORT void ShutdownSdk();
|
||||
}
|
||||
|
||||
#endif
|
||||
38
core/include/alibabacloud/core/AsyncCallerContext.h
Normal file
38
core/include/alibabacloud/core/AsyncCallerContext.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ASYNCCALLERCONTEXT_H_
|
||||
#define 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
|
||||
49
core/include/alibabacloud/core/ClientConfiguration.h
Normal file
49
core/include/alibabacloud/core/ClientConfiguration.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
#define ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "CredentialsProvider.h"
|
||||
#include "CoreExport.h"
|
||||
#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();
|
||||
|
||||
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_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_CLIENTCONFIGURATION_H_
|
||||
65
core/include/alibabacloud/core/CommonClient.h
Normal file
65
core/include/alibabacloud/core/CommonClient.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include "ClientConfiguration.h"
|
||||
#include "CoreExport.h"
|
||||
#include "CoreClient.h"
|
||||
#include "CredentialsProvider.h"
|
||||
#include "EndpointProvider.h"
|
||||
#include "CommonRequest.h"
|
||||
#include "CommonResponse.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();
|
||||
|
||||
CommonResponseOutcome commonResponse(const CommonRequest &request)const;
|
||||
void commonResponseAsync(const CommonRequest& request, const CommonResponseAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
|
||||
CommonResponseOutcomeCallable commonResponseCallable(const CommonRequest& request) const;
|
||||
|
||||
protected:
|
||||
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest & msg, HttpRequest::Method method) const override;
|
||||
HttpRequest buildHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
|
||||
HttpRequest buildRoaHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
|
||||
HttpRequest buildRpcHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
|
||||
virtual EndpointOutcome endpoint() const override;
|
||||
JsonOutcome makeRequest(const std::string &endpoint, const CommonRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
|
||||
|
||||
private:
|
||||
std::string canonicalizedQuery(const std::map <std::string, std::string> ¶ms)const;
|
||||
std::string canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const;
|
||||
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
std::shared_ptr<EndpointProvider> endpointProvider_;
|
||||
std::shared_ptr<Signer> signer_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_COMMONCLIENT_H_
|
||||
59
core/include/alibabacloud/core/CommonRequest.h
Normal file
59
core/include/alibabacloud/core/CommonRequest.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
#define 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:
|
||||
CommonRequest();
|
||||
~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 setUriPattern(const std::string &uriPattern);
|
||||
using ServiceRequest::setVersion;
|
||||
std::string uriPattern()const;
|
||||
protected:
|
||||
using ServiceRequest::product;
|
||||
|
||||
private:
|
||||
std::string domain_;
|
||||
std::string uriPattern_;
|
||||
ParameterCollection queryParams_;
|
||||
ParameterCollection headerParams_;
|
||||
HttpRequest::Method httpMethod_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_COMMONREQUEST_H_
|
||||
38
core/include/alibabacloud/core/CommonResponse.h
Normal file
38
core/include/alibabacloud/core/CommonResponse.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
#define 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();
|
||||
|
||||
std::string payload()const;
|
||||
private:
|
||||
std::string payload_;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_COMMONRESPONSE_H_
|
||||
55
core/include/alibabacloud/core/CoreClient.h
Normal file
55
core/include/alibabacloud/core/CoreClient.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CORECLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_CORECLIENT_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "ClientConfiguration.h"
|
||||
#include "CoreExport.h"
|
||||
#include "HttpClient.h"
|
||||
#include "HttpResponse.h"
|
||||
#include "HttpRequest.h"
|
||||
#include "Outcome.h"
|
||||
#include "ServiceRequest.h"
|
||||
#include "Runnable.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT CoreClient
|
||||
{
|
||||
public:
|
||||
CoreClient(const ClientConfiguration &configuration);
|
||||
virtual ~CoreClient();
|
||||
|
||||
ClientConfiguration configuration()const;
|
||||
protected:
|
||||
typedef Outcome<Error, std::string> EndpointOutcome;
|
||||
|
||||
HttpClient::HttpResponseOutcome AttemptRequest(const std::string & endpoint, const ServiceRequest &request, HttpRequest::Method method)const;
|
||||
Error buildCoreError(const HttpResponse &response)const;
|
||||
bool hasResponseError(const HttpResponse &response)const;
|
||||
virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, HttpRequest::Method method)const = 0;
|
||||
void asyncExecute(Runnable * r)const;
|
||||
virtual EndpointOutcome endpoint()const = 0;
|
||||
private:
|
||||
ClientConfiguration configuration_;
|
||||
std::shared_ptr<CredentialsProvider> credentialsProvider_;
|
||||
HttpClient *httpClient_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
32
core/include/alibabacloud/core/CoreExport.h
Normal file
32
core/include/alibabacloud/core/CoreExport.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_COREEXPORT_H_
|
||||
#define 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
|
||||
#else
|
||||
# define ALIBABACLOUD_CORE_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_COREEXPORT_H_
|
||||
47
core/include/alibabacloud/core/Credentials.h
Normal file
47
core/include/alibabacloud/core/Credentials.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CREDENTIAL_H_
|
||||
#define ALIBABACLOUD_CORE_CREDENTIAL_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();
|
||||
|
||||
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_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_CREDENTIAL_H_
|
||||
36
core/include/alibabacloud/core/CredentialsProvider.h
Normal file
36
core/include/alibabacloud/core/CredentialsProvider.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_CREDENTIALSPROVIDER_H_
|
||||
|
||||
#include "CoreExport.h"
|
||||
#include "Credentials.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT CredentialsProvider
|
||||
{
|
||||
public:
|
||||
CredentialsProvider() = default;
|
||||
virtual ~CredentialsProvider() = default;
|
||||
|
||||
virtual Credentials getCredentials() = 0;
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ECSINSTANCEPROFILECONFIGLOADER_H_
|
||||
#define ALIBABACLOUD_CORE_ECSINSTANCEPROFILECONFIGLOADER_H_
|
||||
|
||||
#include <memory>
|
||||
#include "InstanceProfileConfigLoader.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class EcsMetadataClient;
|
||||
class EcsInstanceProfileConfigLoader : public InstanceProfileConfigLoader
|
||||
{
|
||||
public:
|
||||
EcsInstanceProfileConfigLoader();
|
||||
EcsInstanceProfileConfigLoader(const std::shared_ptr<EcsMetadataClient>& metadataClient);
|
||||
~EcsInstanceProfileConfigLoader();
|
||||
|
||||
protected:
|
||||
virtual bool loadInternal() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<EcsMetadataClient> metadataClient_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_ECSINSTANCEPROFILECONFIGLOADER_H_
|
||||
51
core/include/alibabacloud/core/EndpointProvider.h
Normal file
51
core/include/alibabacloud/core/EndpointProvider.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <alibabacloud/core/location/LocationClient.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT EndpointProvider
|
||||
{
|
||||
public:
|
||||
EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient,
|
||||
const std::string regionId,
|
||||
const std::string serviceCode,
|
||||
int durationSeconds = 3600);
|
||||
~EndpointProvider();
|
||||
|
||||
std::string getEndpoint();
|
||||
|
||||
private:
|
||||
void loadEndpoint();
|
||||
bool checkExpiry()const;
|
||||
|
||||
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 serviceCode_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
48
core/include/alibabacloud/core/Error.h
Normal file
48
core/include/alibabacloud/core/Error.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ERROR_H_
|
||||
#define 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;
|
||||
|
||||
std::string errorCode()const;
|
||||
std::string errorMessage() const;
|
||||
std::string host() const;
|
||||
std::string requestId() const;
|
||||
void setErrorCode(const std::string &code);
|
||||
void setErrorMessage(const std::string& message);
|
||||
void setHost(const std::string& host);
|
||||
void setRequestId(const std::string& request);
|
||||
private:
|
||||
std::string errorCode_;
|
||||
std::string message_;
|
||||
std::string host_;
|
||||
std::string requestId_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_ERROR_H_
|
||||
41
core/include/alibabacloud/core/Global.h
Normal file
41
core/include/alibabacloud/core/Global.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_GLOBAL_H_
|
||||
#define 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)
|
||||
#elif defined(__linux__)
|
||||
# define ALIBABACLOUD_DECL_EXPORT __attribute__((visibility("default")))
|
||||
# define ALIBABACLOUD_DECL_IMPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#if !defined(ALIBABACLOUD_DECL_EXPORT)
|
||||
# define ALIBABACLOUD_DECL_EXPORT
|
||||
#endif
|
||||
|
||||
#if !defined(ALIBABACLOUD_DECL_IMPORT)
|
||||
# define ALIBABACLOUD_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_GLOBAL_H_
|
||||
34
core/include/alibabacloud/core/HmacSha1Signer.h
Normal file
34
core/include/alibabacloud/core/HmacSha1Signer.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
#define ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
|
||||
#include "Signer.h"
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_HMACSHA1SIGNER_H_
|
||||
43
core/include/alibabacloud/core/HttpClient.h
Normal file
43
core/include/alibabacloud/core/HttpClient.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_HTTPCLIENT_H_
|
||||
|
||||
#include <alibabacloud/core/HttpRequest.h>
|
||||
#include <alibabacloud/core/HttpResponse.h>
|
||||
#include <alibabacloud/core/NetworkProxy.h>
|
||||
#include <alibabacloud/core/Outcome.h>
|
||||
#include <alibabacloud/core/Error.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class HttpClient
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, HttpResponse> HttpResponseOutcome;
|
||||
|
||||
HttpClient();
|
||||
virtual ~HttpClient();
|
||||
|
||||
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) = 0;
|
||||
NetworkProxy proxy()const;
|
||||
void setProxy(const NetworkProxy &proxy);
|
||||
private:
|
||||
NetworkProxy proxy_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
82
core/include/alibabacloud/core/HttpMessage.h
Normal file
82
core/include/alibabacloud/core/HttpMessage.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPMESSAGE_H_
|
||||
#define 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
|
||||
};
|
||||
|
||||
typedef std::string HeaderNameType;
|
||||
typedef std::string HeaderValueType;
|
||||
typedef std::map<HeaderNameType, HeaderValueType, nocaseLess> HeaderCollection;
|
||||
|
||||
HttpMessage(const HttpMessage &other);
|
||||
HttpMessage(HttpMessage &&other);
|
||||
HttpMessage& operator=(const HttpMessage &other);
|
||||
HttpMessage& operator=(HttpMessage &&other);
|
||||
virtual ~HttpMessage();
|
||||
|
||||
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_
|
||||
53
core/include/alibabacloud/core/HttpRequest.h
Normal file
53
core/include/alibabacloud/core/HttpRequest.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPREQUEST_H_
|
||||
#define 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();
|
||||
|
||||
Method method()const;
|
||||
void setMethod(Method method);
|
||||
void setUrl(const Url &url);
|
||||
Url url()const;
|
||||
private:
|
||||
Method method_;
|
||||
Url url_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
43
core/include/alibabacloud/core/HttpResponse.h
Normal file
43
core/include/alibabacloud/core/HttpResponse.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
#define 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();
|
||||
|
||||
HttpRequest request()const;
|
||||
void setStatusCode(int code);
|
||||
int statusCode()const;
|
||||
private:
|
||||
int statusCode_;
|
||||
HttpRequest request_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_HTTPRESPONSE_H_
|
||||
47
core/include/alibabacloud/core/InstanceProfileConfigLoader.h
Normal file
47
core/include/alibabacloud/core/InstanceProfileConfigLoader.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_INSTANCEPROFILECONFIGLOADER_H_
|
||||
#define ALIBABACLOUD_CORE_INSTANCEPROFILECONFIGLOADER_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "Profile.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class InstanceProfileConfigLoader
|
||||
{
|
||||
public:
|
||||
InstanceProfileConfigLoader();
|
||||
virtual ~InstanceProfileConfigLoader();
|
||||
|
||||
bool load();
|
||||
bool persistProfiles(const std::map<std::string, Profile>& profiles);
|
||||
|
||||
std::map<std::string, Profile> allProfiles() const;
|
||||
std::chrono::system_clock::time_point lastLoadTime() const;
|
||||
|
||||
protected:
|
||||
virtual bool loadInternal() = 0;
|
||||
virtual bool persistInternal(const std::map<std::string, Profile>&);
|
||||
|
||||
std::map<std::string, Profile> profiles_;
|
||||
std::chrono::system_clock::time_point lastLoadTime_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_INSTANCEPROFILECONFIGLOADER_H_
|
||||
34
core/include/alibabacloud/core/InstanceProfileCredentials.h
Normal file
34
core/include/alibabacloud/core/InstanceProfileCredentials.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
#define ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
|
||||
#include "BasicSessionCredentials.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class InstanceProfileCredentials : public BasicSessionCredentials
|
||||
{
|
||||
public:
|
||||
InstanceProfileCredentials();
|
||||
~InstanceProfileCredentials();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALS_H_
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_INSTANCEPROFILECREDENTIALSPROVIDER_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include "CredentialsProvider.h"
|
||||
#include "Credentials.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class EcsInstanceProfileConfigLoader;
|
||||
class InstanceProfileConfigLoader;
|
||||
class ALIBABACLOUD_CORE_EXPORT InstanceProfileCredentialsProvider : public CredentialsProvider
|
||||
{
|
||||
public:
|
||||
InstanceProfileCredentialsProvider(size_t refreshRateMs = (1000 * 60 * 10));
|
||||
InstanceProfileCredentialsProvider(const std::shared_ptr<EcsInstanceProfileConfigLoader>&, size_t refreshRateMs = (1000 * 60 * 10));
|
||||
|
||||
virtual Credentials getCredentials() override;
|
||||
private:
|
||||
void refreshIfExpired();
|
||||
virtual bool isTimeToRefresh(long reloadFrequency);
|
||||
|
||||
std::chrono::system_clock::time_point lastLoaded_;
|
||||
std::shared_ptr<InstanceProfileConfigLoader> metadataConfigLoader_;
|
||||
size_t loadFrequencyMs_;
|
||||
mutable std::mutex m_reloadMutex;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
59
core/include/alibabacloud/core/NetworkProxy.h
Normal file
59
core/include/alibabacloud/core/NetworkProxy.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_NETWORKPROXY_H_
|
||||
#define 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();
|
||||
|
||||
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_
|
||||
72
core/include/alibabacloud/core/Outcome.h
Normal file
72
core/include/alibabacloud/core/Outcome.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_OUTCOME_H_
|
||||
#define 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;
|
||||
}
|
||||
|
||||
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_
|
||||
52
core/include/alibabacloud/core/Profile.h
Normal file
52
core/include/alibabacloud/core/Profile.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_PROFILE_H_
|
||||
#define ALIBABACLOUD_CORE_PROFILE_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <alibabacloud/core/Credentials.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class Profile
|
||||
{
|
||||
public:
|
||||
std::string name() const;
|
||||
void setName(const std::string& value);
|
||||
Credentials credentials() const;
|
||||
void setCredentials(const Credentials& value);
|
||||
std::string region() const;
|
||||
void setRegion(const std::string& value);
|
||||
std::string roleArn() const;
|
||||
void setRoleArn(const std::string& value);
|
||||
std::string sourceProfile() const;
|
||||
void setSourceProfile(const std::string& value);
|
||||
void setAllKeyValPairs(const std::map<std::string, std::string>& map);
|
||||
std::string value(const std::string& key);
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string region_;
|
||||
Credentials credentials_;
|
||||
std::string roleArn_;
|
||||
std::string sourceProfile_;
|
||||
std::map<std::string, std::string> allKeyValPairs_;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_PROFILE_H_
|
||||
54
core/include/alibabacloud/core/RoaServiceClient.h
Normal file
54
core/include/alibabacloud/core/RoaServiceClient.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_ROASERVICECLIENT_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "CoreClient.h"
|
||||
#include "CredentialsProvider.h"
|
||||
#include "HmacSha1Signer.h"
|
||||
#include "HttpRequest.h"
|
||||
#include "RoaServiceRequest.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class RoaErrorMarshaller;
|
||||
class ALIBABACLOUD_CORE_EXPORT RoaServiceClient : public CoreClient
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, std::string> JsonOutcome;
|
||||
|
||||
RoaServiceClient(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_
|
||||
32
core/include/alibabacloud/core/RoaServiceRequest.h
Normal file
32
core/include/alibabacloud/core/RoaServiceRequest.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_ROASERVICEREQUEST_H_
|
||||
|
||||
#include "ServiceRequest.h"
|
||||
|
||||
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_
|
||||
55
core/include/alibabacloud/core/RpcServiceClient.h
Normal file
55
core/include/alibabacloud/core/RpcServiceClient.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_RPCSERVICECLIENT_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "CoreClient.h"
|
||||
#include "CredentialsProvider.h"
|
||||
#include "HmacSha1Signer.h"
|
||||
#include "HttpRequest.h"
|
||||
#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;
|
||||
|
||||
RpcServiceClient(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_
|
||||
36
core/include/alibabacloud/core/RpcServiceRequest.h
Normal file
36
core/include/alibabacloud/core/RpcServiceRequest.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
|
||||
#include "ServiceRequest.h"
|
||||
|
||||
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);
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_RPCSERVICEREQUEST_H_
|
||||
35
core/include/alibabacloud/core/Runnable.h
Normal file
35
core/include/alibabacloud/core/Runnable.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
#define 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;
|
||||
|
||||
private:
|
||||
std::function<void()> f_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_RUNNABLE_H_
|
||||
68
core/include/alibabacloud/core/ServiceRequest.h
Normal file
68
core/include/alibabacloud/core/ServiceRequest.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
|
||||
#include <map>
|
||||
#include "CoreExport.h"
|
||||
#include "Url.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT ServiceRequest
|
||||
{
|
||||
public:
|
||||
typedef std::string ParameterNameType;
|
||||
typedef std::string ParameterValueType;
|
||||
typedef std::map<ParameterNameType, ParameterValueType> ParameterCollection;
|
||||
|
||||
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);
|
||||
|
||||
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_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_SERVICEREQUEST_H_
|
||||
40
core/include/alibabacloud/core/ServiceResult.h
Normal file
40
core/include/alibabacloud/core/ServiceResult.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
#define ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
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_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_SERVICERESULT_H_
|
||||
46
core/include/alibabacloud/core/Signer.h
Normal file
46
core/include/alibabacloud/core/Signer.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SIGNER_H_
|
||||
#define ALIBABACLOUD_CORE_SIGNER_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
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_
|
||||
37
core/include/alibabacloud/core/SimpleCredentialsProvider.h
Normal file
37
core/include/alibabacloud/core/SimpleCredentialsProvider.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
|
||||
#include "CredentialsProvider.h"
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT SimpleCredentialsProvider : public CredentialsProvider
|
||||
{
|
||||
public:
|
||||
SimpleCredentialsProvider(const Credentials &credentials);
|
||||
SimpleCredentialsProvider(const std::string &accessKeyId,
|
||||
const std::string &accessKeySecret);
|
||||
~SimpleCredentialsProvider();
|
||||
|
||||
virtual Credentials getCredentials() override;
|
||||
private:
|
||||
Credentials credentials_;
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_SIMPLECREDENTIALSPROVIDER_H_
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_STS_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
#define ALIBABACLOUD_STS_STSASSUMEROLECREDENTIALSPROVIDER_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <alibabacloud/core/CredentialsProvider.h>
|
||||
#include <alibabacloud/core/sts/StsClient.h>
|
||||
|
||||
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();
|
||||
|
||||
virtual Credentials getCredentials() override;
|
||||
private:
|
||||
void loadCredentials();
|
||||
bool checkExpiry()const;
|
||||
|
||||
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_
|
||||
75
core/include/alibabacloud/core/Url.h
Normal file
75
core/include/alibabacloud/core/Url.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_URL_H_
|
||||
#define ALIBABACLOUD_CORE_URL_H_
|
||||
|
||||
#include <string>
|
||||
#include "CoreExport.h"
|
||||
|
||||
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_
|
||||
51
core/include/alibabacloud/core/location/LocationClient.h
Normal file
51
core/include/alibabacloud/core/location/LocationClient.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include <alibabacloud/core/RpcServiceClient.h>
|
||||
#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();
|
||||
|
||||
DescribeEndpointsOutcome describeEndpoints(const Model::DescribeEndpointsRequest &request)const;
|
||||
void describeEndpointsAsync(const Model::DescribeEndpointsRequest& request, const DescribeEndpointsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
|
||||
DescribeEndpointsOutcomeCallable describeEndpointsCallable(const Model::DescribeEndpointsRequest& request) const;
|
||||
private:
|
||||
virtual EndpointOutcome endpoint()const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_LOCATION_LOCATIONCLIENT_H_
|
||||
38
core/include/alibabacloud/core/location/LocationRequest.h
Normal file
38
core/include/alibabacloud/core/location/LocationRequest.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
|
||||
#include <alibabacloud/core/RpcServiceRequest.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Location
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT LocationRequest : public RpcServiceRequest
|
||||
{
|
||||
public:
|
||||
explicit LocationRequest(const std::string & action);
|
||||
virtual ~LocationRequest();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_LOCATION_LOCATIONREQUEST_H_
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include <alibabacloud/core/location/LocationRequest.h>
|
||||
|
||||
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_
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
#define ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_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;
|
||||
};
|
||||
|
||||
DescribeEndpointsResult();
|
||||
explicit DescribeEndpointsResult(const std::string &payload);
|
||||
~DescribeEndpointsResult();
|
||||
|
||||
std::vector<Endpoint> endpoints()const;
|
||||
void setEndpoints(const std::vector<Endpoint> &endpoints);
|
||||
|
||||
bool success()const;
|
||||
void setSuccess(const bool &success);
|
||||
|
||||
protected:
|
||||
void parse(const std::string &payload);
|
||||
private:
|
||||
std::vector<Endpoint> endpoints_;
|
||||
bool success_;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_LOCATION_MODEL_DESCRIBEENDPOINTSRESULT_H_
|
||||
60
core/include/alibabacloud/core/sts/StsClient.h
Normal file
60
core/include/alibabacloud/core/sts/StsClient.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include <alibabacloud/core/RpcServiceClient.h>
|
||||
#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();
|
||||
|
||||
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;
|
||||
private:
|
||||
virtual EndpointOutcome endpoint()const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_STS_STSCLIENT_H_
|
||||
38
core/include/alibabacloud/core/sts/StsRequest.h
Normal file
38
core/include/alibabacloud/core/sts/StsRequest.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_STSSERVICEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_STS_STSSERVICEREQUEST_H_
|
||||
|
||||
#include <alibabacloud/core/RpcServiceRequest.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Sts
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT StsRequest : public RpcServiceRequest
|
||||
{
|
||||
public:
|
||||
explicit StsRequest(const std::string & action);
|
||||
virtual ~StsRequest();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_STS_STSSERVICEREQUEST_H_
|
||||
47
core/include/alibabacloud/core/sts/model/AssumeRoleRequest.h
Normal file
47
core/include/alibabacloud/core/sts/model/AssumeRoleRequest.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLEREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLEREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include <alibabacloud/core/sts/StsRequest.h>
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLEREQUEST_H_
|
||||
59
core/include/alibabacloud/core/sts/model/AssumeRoleResult.h
Normal file
59
core/include/alibabacloud/core/sts/model/AssumeRoleResult.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLERESULT_H_
|
||||
#define ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLERESULT_H_
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
AssumeRoleResult();
|
||||
explicit AssumeRoleResult(const std::string &payload);
|
||||
~AssumeRoleResult();
|
||||
|
||||
AssumedRoleUser assumedRoleUser()const;
|
||||
Credentials credentials()const;
|
||||
private:
|
||||
void parse(const std::string &payload);
|
||||
|
||||
AssumedRoleUser assumedRoleUser_;
|
||||
Credentials credentials_;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_STS_MODEL_ASSUMEROLERESULT_H_
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYREQUEST_H_
|
||||
#define ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include <alibabacloud/core/sts/StsRequest.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Sts
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_CORE_EXPORT GetCallerIdentityRequest : public StsRequest
|
||||
{
|
||||
public:
|
||||
GetCallerIdentityRequest();
|
||||
~GetCallerIdentityRequest();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYREQUEST_H_
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYRESULT_H_
|
||||
#define ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYRESULT_H_
|
||||
|
||||
#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();
|
||||
|
||||
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_;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_STS_MODEL_GETCALLERIDENTITYRESULT_H_
|
||||
44
core/src/AlibabaCloud.cc
Normal file
44
core/src/AlibabaCloud.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/AlibabaCloud.h>
|
||||
#include "Executor.h"
|
||||
|
||||
static AlibabaCloud::Executor * executor = nullptr;
|
||||
|
||||
void AlibabaCloud::InitializeSdk()
|
||||
{
|
||||
if (IsSdkInitialized())
|
||||
return;
|
||||
|
||||
executor = new Executor;
|
||||
executor->start();
|
||||
}
|
||||
|
||||
bool AlibabaCloud::IsSdkInitialized()
|
||||
{
|
||||
return executor != nullptr;
|
||||
}
|
||||
|
||||
void AlibabaCloud::ShutdownSdk()
|
||||
{
|
||||
if (!IsSdkInitialized())
|
||||
return;
|
||||
|
||||
executor->shutdown();
|
||||
delete executor;
|
||||
executor = nullptr;
|
||||
}
|
||||
44
core/src/AsyncCallerContext.cc
Normal file
44
core/src/AsyncCallerContext.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
AsyncCallerContext::AsyncCallerContext() :
|
||||
uuid_(GenerateUuid())
|
||||
{
|
||||
}
|
||||
|
||||
AsyncCallerContext::AsyncCallerContext(const std::string &uuid) :
|
||||
uuid_(uuid)
|
||||
{
|
||||
}
|
||||
|
||||
AsyncCallerContext::~AsyncCallerContext()
|
||||
{
|
||||
}
|
||||
|
||||
std::string AsyncCallerContext::uuid()const
|
||||
{
|
||||
return uuid_;
|
||||
}
|
||||
|
||||
void AsyncCallerContext::setUuid(const std::string &uuid)
|
||||
{
|
||||
uuid_ = uuid;
|
||||
}
|
||||
61
core/src/ClientConfiguration.cc
Normal file
61
core/src/ClientConfiguration.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/ClientConfiguration.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
ClientConfiguration::ClientConfiguration(const std::string ®ionId,
|
||||
const NetworkProxy &proxy):
|
||||
regionId_(regionId),
|
||||
proxy_(proxy),
|
||||
endpoint_()
|
||||
{
|
||||
}
|
||||
|
||||
ClientConfiguration::~ClientConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
std::string ClientConfiguration::endpoint() const
|
||||
{
|
||||
return endpoint_;
|
||||
}
|
||||
|
||||
NetworkProxy ClientConfiguration::proxy()const
|
||||
{
|
||||
return proxy_;
|
||||
}
|
||||
|
||||
std::string ClientConfiguration::regionId()const
|
||||
{
|
||||
return regionId_;
|
||||
}
|
||||
|
||||
void ClientConfiguration::setEndpoint(const std::string & endpoint)
|
||||
{
|
||||
endpoint_ = endpoint;
|
||||
}
|
||||
|
||||
void ClientConfiguration::setProxy(const NetworkProxy &proxy)
|
||||
{
|
||||
proxy_ = proxy;
|
||||
}
|
||||
|
||||
void ClientConfiguration::setRegionId(const std::string ®ionId)
|
||||
{
|
||||
regionId_ = regionId;
|
||||
}
|
||||
313
core/src/CommonClient.cc
Normal file
313
core/src/CommonClient.cc
Normal file
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/CommonClient.h>
|
||||
#include <ctime>
|
||||
#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
|
||||
{
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const Credentials &credentials, const ClientConfiguration &configuration) :
|
||||
CoreClient(configuration),
|
||||
credentialsProvider_(std::make_shared<SimpleCredentialsProvider>(credentials))
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "ecs");
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
|
||||
CoreClient(configuration),
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
credentialsProvider_ = credentialsProvider;
|
||||
auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "ecs");
|
||||
}
|
||||
|
||||
CommonClient::CommonClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
|
||||
CoreClient(configuration),
|
||||
signer_(std::make_shared<HmacSha1Signer>())
|
||||
{
|
||||
credentialsProvider_ = std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret);
|
||||
|
||||
auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "ecs");
|
||||
}
|
||||
|
||||
CommonClient::~CommonClient()
|
||||
{
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
CoreClient::EndpointOutcome CommonClient::endpoint() const
|
||||
{
|
||||
return EndpointOutcome();
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint, const ServiceRequest & msg, HttpRequest::Method method) const
|
||||
{
|
||||
return buildHttpRequest(endpoint, dynamic_cast<const CommonRequest& >(msg), method);
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
if (msg.uriPattern().empty() ||
|
||||
(strcasecmp(msg.uriPattern().c_str(),"rpc") == 0))
|
||||
return buildRpcHttpRequest(endpoint, msg, method);
|
||||
else
|
||||
return buildRoaHttpRequest(endpoint, msg, method);
|
||||
}
|
||||
|
||||
std::string CommonClient::canonicalizedHeaders(const HttpMessage::HeaderCollection &headers)const
|
||||
{
|
||||
std::map <std::string, std::string> materials;
|
||||
for (const auto &p : headers)
|
||||
{
|
||||
std::string key = p.first;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
if (key.find("x-acs-") != 0)
|
||||
continue;
|
||||
|
||||
std::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 CommonClient::buildRoaHttpRequest(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.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;
|
||||
#if defined(__GNUG__) && __GNUC__ < 5
|
||||
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");
|
||||
#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());
|
||||
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 sign;
|
||||
sign << "acs "
|
||||
<< credentials.accessKeyId()
|
||||
<< ":"
|
||||
<< signer_->generate(plaintext.str(), credentials.accessKeySecret());
|
||||
request.setHeader("Authorization", sign.str());
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
std::string CommonClient::canonicalizedQuery(const std::map<std::string, std::string>& params) const
|
||||
{
|
||||
if (params.empty())
|
||||
return std::string();
|
||||
|
||||
std::stringstream ss;
|
||||
for (const auto &p : params)
|
||||
{
|
||||
std::string key = UrlEncode(p.first);
|
||||
StringReplace(key, "+", "%20");
|
||||
StringReplace(key, "*", "%2A");
|
||||
StringReplace(key, "%7E", "~");
|
||||
std::string value = UrlEncode(p.second);
|
||||
StringReplace(value, "+", "%20");
|
||||
StringReplace(value, "*", "%2A");
|
||||
StringReplace(value, "%7E", "~");
|
||||
ss << "&" << key << "=" << value;
|
||||
}
|
||||
return ss.str().substr(1);
|
||||
}
|
||||
|
||||
HttpRequest CommonClient::buildRpcHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
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;
|
||||
#if defined(__GNUG__) && __GNUC__ < 5
|
||||
char tmbuff[26];
|
||||
strftime(tmbuff, 26, "%FT%TZ", std::gmtime(&t));
|
||||
ss << tmbuff;
|
||||
#else
|
||||
ss << std::put_time(std::gmtime(&t), "%FT%TZ");
|
||||
#endif
|
||||
queryParams["Timestamp"] = ss.str();
|
||||
queryParams["Version"] = msg.version();
|
||||
|
||||
std::stringstream plaintext;
|
||||
plaintext << HttpMethodToString(method)
|
||||
<< "&"
|
||||
<< UrlEncode(url.path())
|
||||
<< "&"
|
||||
<< UrlEncode(canonicalizedQuery(queryParams));
|
||||
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
93
core/src/CommonRequest.cc
Normal file
93
core/src/CommonRequest.cc
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/CommonRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
CommonRequest::CommonRequest():
|
||||
ServiceRequest("",""),
|
||||
domain_(),
|
||||
queryParams_(),
|
||||
httpMethod_(HttpRequest::Get),
|
||||
uriPattern_("rpc")
|
||||
{
|
||||
}
|
||||
|
||||
CommonRequest::~CommonRequest()
|
||||
{}
|
||||
|
||||
std::string CommonRequest::domain()const
|
||||
{
|
||||
return domain_;
|
||||
}
|
||||
|
||||
void CommonRequest::setDomain(const std::string &domain)
|
||||
{
|
||||
domain_ = domain;
|
||||
}
|
||||
|
||||
std::string CommonRequest::uriPattern() const
|
||||
{
|
||||
return uriPattern_;
|
||||
}
|
||||
|
||||
void CommonRequest::setUriPattern(const std::string & uriPattern)
|
||||
{
|
||||
uriPattern_ = uriPattern;
|
||||
}
|
||||
|
||||
void CommonRequest::setHttpMethod(HttpRequest::Method method)
|
||||
{
|
||||
httpMethod_ = method;
|
||||
}
|
||||
|
||||
HttpRequest::Method CommonRequest::httpMethod() const
|
||||
{
|
||||
return httpMethod_;
|
||||
}
|
||||
|
||||
CommonRequest::ParameterValueType CommonRequest::queryParameter(const ParameterNameType &name)const
|
||||
{
|
||||
return queryParams_.at(name);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
CommonRequest::ParameterCollection CommonRequest::headerParameters() const
|
||||
{
|
||||
return headerParams_;
|
||||
}
|
||||
|
||||
void CommonRequest::setHeaderParameter(const ParameterNameType &name, const ParameterValueType &value)
|
||||
{
|
||||
headerParams_[name] = value;
|
||||
}
|
||||
|
||||
38
core/src/CommonResponse.cc
Normal file
38
core/src/CommonResponse.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/CommonResponse.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
CommonResponse::CommonResponse() :
|
||||
payload_()
|
||||
{
|
||||
}
|
||||
|
||||
CommonResponse::CommonResponse(const std::string &payload) :
|
||||
payload_(payload)
|
||||
{
|
||||
}
|
||||
|
||||
CommonResponse::~CommonResponse()
|
||||
{
|
||||
}
|
||||
|
||||
std::string CommonResponse::payload() const
|
||||
{
|
||||
return payload_;
|
||||
}
|
||||
25
core/src/Config.h.in
Normal file
25
core/src/Config.h.in
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CONFIG_H_
|
||||
#define ALIBABACLOUD_CORE_CONFIG_H_
|
||||
|
||||
// version = (major << 16) + (minor << 8) + patch
|
||||
#define ALIBABACLOUD_VERSION ((@PROJECT_VERSION_MAJOR@ << 16) + (@PROJECT_VERSION_MINOR@ << 8) + @PROJECT_VERSION_PATCH@)
|
||||
|
||||
#define ALIBABACLOUD_VERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_CONFIG_H_
|
||||
82
core/src/CoreClient.cc
Normal file
82
core/src/CoreClient.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/CoreClient.h>
|
||||
#include <json/json.h>
|
||||
#include <alibabacloud/core/Signer.h>
|
||||
#include "CurlHttpClient.h"
|
||||
#include "Executor.h"
|
||||
|
||||
/*!
|
||||
* \class AlibabaCloud::CoreClient CoreClient.h <alibabacloud/core/CoreClient.h>
|
||||
*
|
||||
*/
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
CoreClient::CoreClient(const ClientConfiguration &configuration) :
|
||||
configuration_(configuration),
|
||||
httpClient_(new CurlHttpClient)
|
||||
{
|
||||
httpClient_->setProxy(configuration.proxy());
|
||||
}
|
||||
|
||||
CoreClient::~CoreClient()
|
||||
{
|
||||
delete httpClient_;
|
||||
}
|
||||
|
||||
ClientConfiguration CoreClient::configuration()const
|
||||
{
|
||||
return configuration_;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 error;
|
||||
error.setErrorCode(value["Code"].asString());
|
||||
error.setErrorMessage(value["Message"].asString());
|
||||
error.setHost(value["HostId"].asString());
|
||||
error.setRequestId(value["RequestId"].asString());
|
||||
return error;
|
||||
}
|
||||
|
||||
bool CoreClient::hasResponseError(const HttpResponse &response)const
|
||||
{
|
||||
return response.statusCode() < 200 || response.statusCode() > 299;
|
||||
}
|
||||
62
core/src/Credentials.cc
Executable file
62
core/src/Credentials.cc
Executable file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/Credentials.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
Credentials::Credentials(const std::string &accessKeyId,
|
||||
const std::string &accessKeySecret,
|
||||
const std::string &sessionToken) :
|
||||
accessKeyId_(accessKeyId),
|
||||
accessKeySecret_(accessKeySecret),
|
||||
sessionToken_(sessionToken)
|
||||
{
|
||||
}
|
||||
|
||||
Credentials::~Credentials()
|
||||
{
|
||||
}
|
||||
|
||||
std::string Credentials::accessKeyId () const
|
||||
{
|
||||
return accessKeyId_;
|
||||
}
|
||||
|
||||
std::string Credentials::accessKeySecret () const
|
||||
{
|
||||
return accessKeySecret_;
|
||||
}
|
||||
|
||||
void Credentials::setAccessKeyId(const std::string &accessKeyId)
|
||||
{
|
||||
accessKeyId_ = accessKeyId;
|
||||
}
|
||||
|
||||
void Credentials::setAccessKeySecret(const std::string &accessKeySecret)
|
||||
{
|
||||
accessKeySecret_ = accessKeySecret;
|
||||
}
|
||||
|
||||
void Credentials::setSessionToken (const std::string &sessionToken)
|
||||
{
|
||||
sessionToken_ = sessionToken;
|
||||
}
|
||||
|
||||
std::string Credentials::sessionToken () const
|
||||
{
|
||||
return sessionToken_;
|
||||
}
|
||||
17
core/src/CredentialsProvider.cc
Normal file
17
core/src/CredentialsProvider.cc
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/CredentialsProvider.h>
|
||||
134
core/src/CurlHttpClient.cc
Normal file
134
core/src/CurlHttpClient.cc
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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 "CurlHttpClient.h"
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
namespace
|
||||
{
|
||||
size_t recvBody(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
HttpResponse *response = static_cast<HttpResponse*>(userdata);
|
||||
response->setBody(ptr, nmemb);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CurlHttpClient::CurlHttpClient() :
|
||||
HttpClient(),
|
||||
curlHandle_(curl_easy_init())
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
curl_easy_setopt(curlHandle_, CURLOPT_WRITEDATA, &response);
|
||||
curl_easy_setopt(curlHandle_, CURLOPT_WRITEFUNCTION, recvBody);
|
||||
setCUrlProxy(curlHandle_, proxy());
|
||||
|
||||
CURLcode res = curl_easy_perform(curlHandle_);
|
||||
if (res == CURLE_OK) {
|
||||
long response_code;
|
||||
curl_easy_getinfo(curlHandle_, CURLINFO_RESPONSE_CODE, &response_code);
|
||||
response.setStatusCode(response_code);
|
||||
return HttpResponseOutcome(response);
|
||||
}
|
||||
|
||||
return HttpResponseOutcome(Error("NetworkError", ""));
|
||||
}
|
||||
37
core/src/CurlHttpClient.h
Normal file
37
core/src/CurlHttpClient.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_CURLHTTPCLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_CURLHTTPCLIENT_H_
|
||||
|
||||
#include <alibabacloud/core/HttpClient.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class CurlHttpClient : public HttpClient
|
||||
{
|
||||
public:
|
||||
CurlHttpClient();
|
||||
~CurlHttpClient();
|
||||
|
||||
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) override;
|
||||
private:
|
||||
CURL *curlHandle_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_CURLHTTPCLIENT_H_
|
||||
41
core/src/EcsInstanceProfileConfigLoader.cc
Normal file
41
core/src/EcsInstanceProfileConfigLoader.cc
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/EcsInstanceProfileConfigLoader.h>
|
||||
#include "EcsMetadataClient.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
EcsInstanceProfileConfigLoader::EcsInstanceProfileConfigLoader() :
|
||||
metadataClient_(std::make_shared<EcsMetadataClient>())
|
||||
{
|
||||
}
|
||||
|
||||
EcsInstanceProfileConfigLoader::EcsInstanceProfileConfigLoader(const std::shared_ptr<EcsMetadataClient>& client) :
|
||||
metadataClient_(client)
|
||||
{
|
||||
}
|
||||
|
||||
EcsInstanceProfileConfigLoader::~EcsInstanceProfileConfigLoader()
|
||||
{
|
||||
}
|
||||
|
||||
bool EcsInstanceProfileConfigLoader::loadInternal()
|
||||
{
|
||||
//TODO(fenglc): load form remote server
|
||||
|
||||
return false;
|
||||
}
|
||||
27
core/src/EcsMetadataClient.cc
Normal file
27
core/src/EcsMetadataClient.cc
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 "EcsMetadataClient.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
EcsMetadataClient::EcsMetadataClient()
|
||||
{
|
||||
}
|
||||
|
||||
EcsMetadataClient::~EcsMetadataClient()
|
||||
{
|
||||
}
|
||||
32
core/src/EcsMetadataClient.h
Normal file
32
core/src/EcsMetadataClient.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_ECSMETADATACLIENT_H_
|
||||
#define ALIBABACLOUD_CORE_ECSMETADATACLIENT_H_
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
class EcsMetadataClient
|
||||
{
|
||||
public:
|
||||
EcsMetadataClient();
|
||||
~EcsMetadataClient();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CORE_ECSMETADATACLIENT_H_
|
||||
77
core/src/EndpointProvider.cc
Normal file
77
core/src/EndpointProvider.cc
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/EndpointProvider.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Location;
|
||||
|
||||
EndpointProvider::EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient, const std::string regionId, const std::string serviceCode, int durationSeconds) :
|
||||
locationClient_(locationClient),
|
||||
regionId_(regionId),
|
||||
serviceCode_(serviceCode),
|
||||
durationSeconds_(durationSeconds),
|
||||
cachedMutex_(),
|
||||
cachedEndpoint_(),
|
||||
expiry_()
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
std::string EndpointProvider::getEndpoint()
|
||||
{
|
||||
loadEndpoint();
|
||||
std::lock_guard<std::mutex> locker(cachedMutex_);
|
||||
return cachedEndpoint_;
|
||||
}
|
||||
|
||||
void EndpointProvider::loadEndpoint()
|
||||
{
|
||||
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())
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
core/src/Error.cc
Normal file
36
core/src/Error.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/Error.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
Error::Error(std::string code, const std::string message) :
|
||||
errorCode_(code),
|
||||
message_(message),
|
||||
host_(),
|
||||
requestId_()
|
||||
{
|
||||
}
|
||||
|
||||
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_; }
|
||||
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; }
|
||||
124
core/src/Executor.cc
Normal file
124
core/src/Executor.cc
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 "Executor.h"
|
||||
#include <alibabacloud/core/Runnable.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
Executor *Executor::self_ = nullptr;
|
||||
|
||||
Executor::Executor() :
|
||||
cvMutex_(),
|
||||
shutdown_(true),
|
||||
tasksQueue_(),
|
||||
tasksQueueMutex_(),
|
||||
thread_()
|
||||
{
|
||||
self_ = this;
|
||||
}
|
||||
|
||||
Executor::~Executor()
|
||||
{
|
||||
self_ = nullptr;
|
||||
shutdown();
|
||||
}
|
||||
|
||||
Executor * Executor::instance()
|
||||
{
|
||||
return self_;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
if (task) {
|
||||
task->run();
|
||||
delete task;
|
||||
}
|
||||
}
|
||||
|
||||
if (!shutdown_) {
|
||||
std::unique_lock<std::mutex> lk(cvMutex_);
|
||||
cv_.wait(lk);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
shutdown_ = false;
|
||||
thread_ = std::thread(threadMain);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Executor::isShutdown()const
|
||||
{
|
||||
return shutdown_;
|
||||
}
|
||||
|
||||
void Executor::execute(Runnable* task)
|
||||
{
|
||||
if (isShutdown())
|
||||
return;
|
||||
|
||||
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::shutdown()
|
||||
{
|
||||
if (isShutdown())
|
||||
return;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(tasksQueueMutex_);
|
||||
while (tasksQueue_.size() > 0) {
|
||||
auto task = tasksQueue_.front();
|
||||
delete task;
|
||||
tasksQueue_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
shutdown_ = true;
|
||||
wakeUp();
|
||||
|
||||
if (thread_.joinable())
|
||||
thread_.join();
|
||||
}
|
||||
53
core/src/Executor.h
Normal file
53
core/src/Executor.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ALIBABACLOUD_CORE_EXECUTOR_H_
|
||||
#define ALIBABACLOUD_CORE_EXECUTOR_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#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_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CORE_EXECUTOR_H_
|
||||
99
core/src/HmacSha1Signer.cc
Normal file
99
core/src/HmacSha1Signer.cc
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/HmacSha1Signer.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#else
|
||||
#include <openssl/hmac.h>
|
||||
#endif
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
HmacSha1Signer::HmacSha1Signer() :
|
||||
Signer(HmacSha1, "HMAC-SHA1", "1.0")
|
||||
{
|
||||
}
|
||||
|
||||
HmacSha1Signer::~HmacSha1Signer()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
#else
|
||||
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();
|
||||
|
||||
char encodedData[100];
|
||||
EVP_EncodeBlock(reinterpret_cast<unsigned char*>(encodedData), md, mdLen);
|
||||
return encodedData;
|
||||
#endif
|
||||
}
|
||||
41
core/src/HttpClient.cc
Normal file
41
core/src/HttpClient.cc
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/HttpClient.h>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
HttpClient::HttpClient() :
|
||||
proxy_()
|
||||
{
|
||||
}
|
||||
|
||||
HttpClient::~HttpClient()
|
||||
{
|
||||
}
|
||||
|
||||
NetworkProxy HttpClient::proxy()const
|
||||
{
|
||||
return proxy_;
|
||||
}
|
||||
|
||||
void HttpClient::setProxy(const NetworkProxy &proxy)
|
||||
{
|
||||
proxy_ = proxy;
|
||||
}
|
||||
173
core/src/HttpMessage.cc
Normal file
173
core/src/HttpMessage.cc
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/HttpMessage.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
namespace
|
||||
{
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#else
|
||||
# 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"
|
||||
};
|
||||
}
|
||||
|
||||
HttpMessage::HttpMessage() :
|
||||
body_(nullptr),
|
||||
bodySize_(0),
|
||||
headers_()
|
||||
{
|
||||
}
|
||||
|
||||
HttpMessage::HttpMessage(const HttpMessage &other) :
|
||||
body_(nullptr),
|
||||
bodySize_(other.bodySize_),
|
||||
headers_(other.headers_)
|
||||
{
|
||||
setBody(other.body_, other.bodySize_);
|
||||
}
|
||||
|
||||
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=(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(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::HeaderCollection HttpMessage::headers() const
|
||||
{
|
||||
return headers_;
|
||||
}
|
||||
|
||||
void HttpMessage::removeHeader(const HeaderNameType & name)
|
||||
{
|
||||
headers_.erase(name);
|
||||
}
|
||||
|
||||
void HttpMessage::removeHeader(KnownHeader header)
|
||||
{
|
||||
removeHeader(KnownHeaderMapper[header]);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
HttpMessage::~HttpMessage()
|
||||
{
|
||||
setBody(nullptr, 0);
|
||||
}
|
||||
|
||||
const char* HttpMessage::body()const
|
||||
{
|
||||
return body_;
|
||||
}
|
||||
|
||||
size_t HttpMessage::bodySize()const
|
||||
{
|
||||
return bodySize_;
|
||||
}
|
||||
|
||||
bool HttpMessage::hasBody() const
|
||||
{
|
||||
return (bodySize_ != 0);
|
||||
}
|
||||
|
||||
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_);
|
||||
}
|
||||
}
|
||||
|
||||
bool HttpMessage::nocaseLess::operator()(const std::string & s1,
|
||||
const std::string & s2) const
|
||||
{
|
||||
return strcasecmp(s1.c_str(), s2.c_str()) < 0;
|
||||
}
|
||||
51
core/src/HttpRequest.cc
Normal file
51
core/src/HttpRequest.cc
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/HttpRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
HttpRequest::HttpRequest(const Url &url, Method method) :
|
||||
HttpMessage(),
|
||||
url_(url),
|
||||
method_(method)
|
||||
{
|
||||
}
|
||||
|
||||
HttpRequest::~HttpRequest()
|
||||
{
|
||||
}
|
||||
|
||||
HttpRequest::Method HttpRequest::method() const
|
||||
{
|
||||
return method_;
|
||||
}
|
||||
|
||||
|
||||
void HttpRequest::setMethod(Method method)
|
||||
{
|
||||
method_ = method;
|
||||
}
|
||||
|
||||
void HttpRequest::setUrl(const Url &url)
|
||||
{
|
||||
url_ = url;
|
||||
}
|
||||
|
||||
Url HttpRequest::url()const
|
||||
{
|
||||
return url_;
|
||||
}
|
||||
57
core/src/HttpResponse.cc
Normal file
57
core/src/HttpResponse.cc
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/HttpResponse.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
#define INVALID_STATUS_CODE -1
|
||||
}
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
HttpResponse::HttpResponse() :
|
||||
HttpMessage(),
|
||||
request_(),
|
||||
statusCode_(INVALID_STATUS_CODE)
|
||||
{
|
||||
}
|
||||
|
||||
HttpResponse::HttpResponse(const HttpRequest & request) :
|
||||
HttpMessage(),
|
||||
request_(request),
|
||||
statusCode_(INVALID_STATUS_CODE)
|
||||
{
|
||||
}
|
||||
|
||||
HttpResponse::~HttpResponse()
|
||||
{
|
||||
}
|
||||
|
||||
HttpRequest HttpResponse::request() const
|
||||
{
|
||||
return request_;
|
||||
}
|
||||
|
||||
void HttpResponse::setStatusCode(int code)
|
||||
{
|
||||
statusCode_ = code;
|
||||
}
|
||||
|
||||
int HttpResponse::statusCode() const
|
||||
{
|
||||
return statusCode_;
|
||||
}
|
||||
65
core/src/InstanceProfileConfigLoader.cc
Normal file
65
core/src/InstanceProfileConfigLoader.cc
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/InstanceProfileConfigLoader.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
InstanceProfileConfigLoader::InstanceProfileConfigLoader()
|
||||
{
|
||||
}
|
||||
|
||||
InstanceProfileConfigLoader::~InstanceProfileConfigLoader()
|
||||
{
|
||||
}
|
||||
|
||||
std::map<std::string, Profile> InstanceProfileConfigLoader::allProfiles() const
|
||||
{
|
||||
return profiles_;
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point InstanceProfileConfigLoader::lastLoadTime() const
|
||||
{
|
||||
return lastLoadTime_;
|
||||
}
|
||||
|
||||
bool InstanceProfileConfigLoader::persistInternal(const std::map<std::string, Profile>&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstanceProfileConfigLoader::load()
|
||||
{
|
||||
if (loadInternal())
|
||||
{
|
||||
lastLoadTime_ = std::chrono::system_clock::now();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstanceProfileConfigLoader::persistProfiles(const std::map<std::string, Profile>& profiles)
|
||||
{
|
||||
if (persistInternal(profiles))
|
||||
{
|
||||
profiles_ = profiles;
|
||||
lastLoadTime_ = std::chrono::system_clock::now();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
28
core/src/InstanceProfileCredentials.cc
Normal file
28
core/src/InstanceProfileCredentials.cc
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/InstanceProfileCredentials.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
InstanceProfileCredentials::InstanceProfileCredentials() :
|
||||
BasicSessionCredentials(Credentials::InstanceProfile)
|
||||
{
|
||||
}
|
||||
|
||||
InstanceProfileCredentials::~InstanceProfileCredentials()
|
||||
{
|
||||
}
|
||||
78
core/src/InstanceProfileCredentialsProvider.cc
Normal file
78
core/src/InstanceProfileCredentialsProvider.cc
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/InstanceProfileCredentialsProvider.h>
|
||||
#include <alibabacloud/core/EcsInstanceProfileConfigLoader.h>
|
||||
#include <alibabacloud/core/Profile.h>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
namespace
|
||||
{
|
||||
const char* const INSTANCE_PROFILE_KEY = "InstanceProfile";
|
||||
}
|
||||
|
||||
InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(size_t refreshRateMs) :
|
||||
metadataConfigLoader_(std::make_shared<EcsInstanceProfileConfigLoader>()),
|
||||
loadFrequencyMs_(refreshRateMs),
|
||||
lastLoaded_()
|
||||
{
|
||||
}
|
||||
|
||||
InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(const std::shared_ptr<EcsInstanceProfileConfigLoader>& loader, size_t refreshRateMs) :
|
||||
metadataConfigLoader_(loader),
|
||||
loadFrequencyMs_(refreshRateMs),
|
||||
lastLoaded_()
|
||||
{
|
||||
}
|
||||
|
||||
Credentials InstanceProfileCredentialsProvider::getCredentials()
|
||||
{
|
||||
refreshIfExpired();
|
||||
|
||||
auto profileIter = metadataConfigLoader_->allProfiles().find(INSTANCE_PROFILE_KEY);
|
||||
if (profileIter != metadataConfigLoader_->allProfiles().end())
|
||||
{
|
||||
return profileIter->second.credentials();
|
||||
}
|
||||
|
||||
return Credentials("","");
|
||||
}
|
||||
|
||||
bool InstanceProfileCredentialsProvider::isTimeToRefresh(long reloadFrequency)
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - lastLoaded_).count();
|
||||
|
||||
if(diff > reloadFrequency)
|
||||
{
|
||||
lastLoaded_ = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void InstanceProfileCredentialsProvider::refreshIfExpired()
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(m_reloadMutex);
|
||||
if (isTimeToRefresh(loadFrequencyMs_))
|
||||
metadataConfigLoader_->load();
|
||||
}
|
||||
86
core/src/NetworkProxy.cc
Normal file
86
core/src/NetworkProxy.cc
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/NetworkProxy.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
NetworkProxy::NetworkProxy(Type type,
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
NetworkProxy::~NetworkProxy()
|
||||
{
|
||||
}
|
||||
|
||||
std::string NetworkProxy::hostName() const
|
||||
{
|
||||
return hostName_;
|
||||
}
|
||||
|
||||
std::string NetworkProxy::password() const
|
||||
{
|
||||
return password_;
|
||||
}
|
||||
|
||||
uint16_t NetworkProxy::port() const
|
||||
{
|
||||
return port_;
|
||||
}
|
||||
|
||||
void NetworkProxy::setHostName(const std::string &hostName)
|
||||
{
|
||||
hostName_ = hostName;
|
||||
}
|
||||
|
||||
void NetworkProxy::setPassword(const std::string &password)
|
||||
{
|
||||
password_ = password;
|
||||
}
|
||||
|
||||
void NetworkProxy::setPort(uint16_t port)
|
||||
{
|
||||
port_ = port;
|
||||
}
|
||||
|
||||
void NetworkProxy::setType(NetworkProxy::Type type)
|
||||
{
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
void NetworkProxy::setUser(const std::string &user)
|
||||
{
|
||||
user_ = user;
|
||||
}
|
||||
|
||||
NetworkProxy::Type NetworkProxy::type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
std::string NetworkProxy::user() const
|
||||
{
|
||||
return user_;
|
||||
}
|
||||
17
core/src/Outcome.cc
Normal file
17
core/src/Outcome.cc
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/Outcome.h>
|
||||
61
core/src/Profile.cc
Normal file
61
core/src/Profile.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/Profile.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
std::string Profile::name() const
|
||||
{ return name_; }
|
||||
|
||||
void Profile::setName(const std::string& value)
|
||||
{ name_ = value; }
|
||||
|
||||
Credentials Profile::credentials() const
|
||||
{ return credentials_; }
|
||||
|
||||
void Profile::setCredentials(const Credentials& value)
|
||||
{ credentials_ = value; }
|
||||
|
||||
std::string Profile::region() const
|
||||
{ return region_; }
|
||||
|
||||
void Profile::setRegion(const std::string& value)
|
||||
{ region_ = value; }
|
||||
|
||||
std::string Profile::roleArn() const
|
||||
{ return roleArn_; }
|
||||
|
||||
void Profile::setRoleArn(const std::string& value)
|
||||
{ roleArn_ = value; }
|
||||
|
||||
std::string Profile::sourceProfile() const
|
||||
{ return sourceProfile_; }
|
||||
|
||||
void Profile::setSourceProfile(const std::string& value)
|
||||
{ sourceProfile_ = value; }
|
||||
|
||||
void Profile::setAllKeyValPairs(const std::map<std::string, std::string>& map)
|
||||
{
|
||||
allKeyValPairs_ = map;
|
||||
}
|
||||
|
||||
std::string Profile::value(const std::string& key)
|
||||
{
|
||||
auto iter = allKeyValPairs_.find(key);
|
||||
if (iter == allKeyValPairs_.end()) return "";
|
||||
return iter->second;
|
||||
}
|
||||
179
core/src/RoaServiceClient.cc
Normal file
179
core/src/RoaServiceClient.cc
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/RoaServiceClient.h>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
//#include <alibabacloud/core/RoaErrorMarshaller.h>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
RoaServiceClient::RoaServiceClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::shared_ptr<Signer> &signer) :
|
||||
CoreClient(configuration),
|
||||
credentialsProvider_(credentialsProvider),
|
||||
signer_(signer)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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 ServiceRequest &msg, HttpRequest::Method method)const
|
||||
{
|
||||
return buildHttpRequest(endpoint, dynamic_cast<const RoaServiceRequest& >(msg), method);
|
||||
}
|
||||
|
||||
HttpRequest RoaServiceClient::buildHttpRequest(const std::string & endpoint, const RoaServiceRequest &msg, HttpRequest::Method method) const
|
||||
{
|
||||
const Credentials credentials = credentialsProvider_->getCredentials();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
#if defined(__GNUG__) && __GNUC__ < 5
|
||||
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");
|
||||
#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());
|
||||
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 sign;
|
||||
sign << "acs "
|
||||
<< credentials.accessKeyId()
|
||||
<< ":"
|
||||
<< signer_->generate(plaintext.str(), credentials.accessKeySecret());
|
||||
request.setHeader("Authorization", sign.str());
|
||||
|
||||
return request;
|
||||
}
|
||||
32
core/src/RoaServiceRequest.cc
Normal file
32
core/src/RoaServiceRequest.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/RoaServiceRequest.h>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
RoaServiceRequest::RoaServiceRequest(const std::string & product, const std::string & version) :
|
||||
ServiceRequest(product, version)
|
||||
{
|
||||
}
|
||||
|
||||
RoaServiceRequest::~RoaServiceRequest()
|
||||
{
|
||||
}
|
||||
130
core/src/RpcServiceClient.cc
Normal file
130
core/src/RpcServiceClient.cc
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/RpcServiceClient.h>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <alibabacloud/core/HmacSha1Signer.h>
|
||||
#include "Utils.h"
|
||||
//#include <alibabacloud/core/RpcErrorMarshaller.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
RpcServiceClient::RpcServiceClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::shared_ptr<Signer> &signer) :
|
||||
CoreClient(configuration),
|
||||
credentialsProvider_(credentialsProvider),
|
||||
signer_(signer)
|
||||
{
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
#else
|
||||
ss << std::put_time(std::gmtime(&t), "%FT%TZ");
|
||||
#endif
|
||||
queryParams["Timestamp"] = ss.str();
|
||||
queryParams["Version"] = msg.version();
|
||||
|
||||
std::stringstream plaintext;
|
||||
plaintext << HttpMethodToString(method)
|
||||
<< "&"
|
||||
<< UrlEncode(url.path())
|
||||
<< "&"
|
||||
<< UrlEncode(canonicalizedQuery(queryParams));
|
||||
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
40
core/src/RpcServiceRequest.cc
Normal file
40
core/src/RpcServiceRequest.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/RpcServiceRequest.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
RpcServiceRequest::RpcServiceRequest(const std::string & product, const std::string & version, const std::string & action) :
|
||||
ServiceRequest(product, version)
|
||||
{
|
||||
setActionName(action);
|
||||
}
|
||||
|
||||
RpcServiceRequest::~RpcServiceRequest()
|
||||
{
|
||||
}
|
||||
|
||||
std::string RpcServiceRequest::actionName()const
|
||||
{
|
||||
return parameter("Action");
|
||||
}
|
||||
|
||||
|
||||
void RpcServiceRequest::setActionName(const std::string & name)
|
||||
{
|
||||
setParameter("Action", name);
|
||||
}
|
||||
29
core/src/Runnable.cc
Normal file
29
core/src/Runnable.cc
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/Runnable.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
Runnable::Runnable(const std::function<void()> f) :
|
||||
f_(f)
|
||||
{
|
||||
}
|
||||
|
||||
void Runnable::run() const
|
||||
{
|
||||
f_();
|
||||
}
|
||||
157
core/src/ServiceRequest.cc
Normal file
157
core/src/ServiceRequest.cc
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/ServiceRequest.h>
|
||||
|
||||
using 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 ServiceRequest &other) :
|
||||
content_(nullptr),
|
||||
contentSize_(other.contentSize_),
|
||||
params_(other.params_),
|
||||
product_(other.product_),
|
||||
resourcePath_(other.resourcePath_),
|
||||
version_(other.version_)
|
||||
{
|
||||
setContent(other.content_, other.contentSize_);
|
||||
}
|
||||
|
||||
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=(ServiceRequest &&other)
|
||||
{
|
||||
if (this != &other)
|
||||
*this = std::move(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ServiceRequest::~ServiceRequest()
|
||||
{
|
||||
if (content_)
|
||||
delete content_;
|
||||
}
|
||||
|
||||
const char * ServiceRequest::content() const
|
||||
{
|
||||
return content_;
|
||||
}
|
||||
|
||||
size_t ServiceRequest::contentSize() const
|
||||
{
|
||||
return contentSize_;
|
||||
}
|
||||
|
||||
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::addParameter(const ParameterNameType & name, const ParameterValueType & value)
|
||||
{
|
||||
setParameter(name, value);
|
||||
}
|
||||
|
||||
ServiceRequest::ParameterValueType ServiceRequest::parameter(const ParameterNameType &name)const
|
||||
{
|
||||
return params_.at(name);
|
||||
}
|
||||
|
||||
ServiceRequest::ParameterCollection ServiceRequest::parameters() const
|
||||
{
|
||||
return params_;
|
||||
}
|
||||
|
||||
void ServiceRequest::removeParameter(const ParameterNameType & name)
|
||||
{
|
||||
params_.erase(name);
|
||||
}
|
||||
|
||||
void ServiceRequest::setParameter(const ParameterNameType &name, const ParameterValueType &value)
|
||||
{
|
||||
params_[name] = value;
|
||||
}
|
||||
|
||||
void ServiceRequest::setParameters(const ParameterCollection & params)
|
||||
{
|
||||
params_ = params;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::version()const
|
||||
{
|
||||
return version_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setVersion(const std::string &version)
|
||||
{
|
||||
version_ = version;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::product() const
|
||||
{
|
||||
return product_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setProduct(const std::string & product)
|
||||
{
|
||||
product_ = product;
|
||||
}
|
||||
|
||||
std::string ServiceRequest::resourcePath() const
|
||||
{
|
||||
return resourcePath_;
|
||||
}
|
||||
|
||||
void ServiceRequest::setResourcePath(const std::string & path)
|
||||
{
|
||||
resourcePath_ = path;
|
||||
}
|
||||
38
core/src/ServiceResult.cc
Normal file
38
core/src/ServiceResult.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/ServiceResult.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
ServiceResult::ServiceResult() :
|
||||
requestId_()
|
||||
{
|
||||
}
|
||||
|
||||
ServiceResult::~ServiceResult()
|
||||
{
|
||||
}
|
||||
|
||||
std::string ServiceResult::requestId() const
|
||||
{
|
||||
return requestId_;
|
||||
}
|
||||
|
||||
void ServiceResult::setRequestId(const std::string & requestId)
|
||||
{
|
||||
requestId_ = requestId;
|
||||
}
|
||||
45
core/src/Signer.cc
Normal file
45
core/src/Signer.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/Signer.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
Signer::Signer(Type type, const std::string & name, const std::string & version) :
|
||||
type_(type),
|
||||
name_(name),
|
||||
version_(version)
|
||||
{
|
||||
}
|
||||
|
||||
Signer::~Signer()
|
||||
{
|
||||
}
|
||||
|
||||
std::string Signer::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
Signer::Type Signer::type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
std::string Signer::version() const
|
||||
{
|
||||
return version_;
|
||||
}
|
||||
40
core/src/SimpleCredentialsProvider.cc
Normal file
40
core/src/SimpleCredentialsProvider.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
SimpleCredentialsProvider::SimpleCredentialsProvider(const Credentials &credentials):
|
||||
CredentialsProvider(),
|
||||
credentials_(credentials)
|
||||
{
|
||||
}
|
||||
|
||||
SimpleCredentialsProvider::SimpleCredentialsProvider(const std::string & accessKeyId, const std::string & accessKeySecret) :
|
||||
CredentialsProvider(),
|
||||
credentials_(accessKeyId, accessKeySecret)
|
||||
{
|
||||
}
|
||||
|
||||
SimpleCredentialsProvider::~SimpleCredentialsProvider()
|
||||
{
|
||||
}
|
||||
|
||||
Credentials SimpleCredentialsProvider::getCredentials()
|
||||
{
|
||||
return credentials_;
|
||||
}
|
||||
88
core/src/StsAssumeRoleCredentialsProvider.cc
Normal file
88
core/src/StsAssumeRoleCredentialsProvider.cc
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/StsAssumeRoleCredentialsProvider.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Sts;
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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_);
|
||||
|
||||
auto assumeRoleOutcome = stsClient_->assumeRole(request);
|
||||
if (assumeRoleOutcome.isSuccess())
|
||||
{
|
||||
const auto stsCredentials = assumeRoleOutcome.result().credentials();
|
||||
cachedCredentials_ = Credentials(stsCredentials.accessKeyId,
|
||||
stsCredentials.accessKeySecret,
|
||||
stsCredentials.securityToken);
|
||||
|
||||
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");
|
||||
#endif
|
||||
expiry_ = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
344
core/src/Url.cc
Normal file
344
core/src/Url.cc
Normal file
@@ -0,0 +1,344 @@
|
||||
/*
|
||||
* 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 <alibabacloud/core/Url.h>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 !(*this == url);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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_;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
query = str.substr(pos + 1);
|
||||
str.erase(pos);
|
||||
}
|
||||
|
||||
pos = str.find('/');
|
||||
if (pos != str.npos) {
|
||||
path = str.substr(pos);
|
||||
str.erase(pos);
|
||||
}
|
||||
else
|
||||
path = "/";
|
||||
|
||||
authority = str;
|
||||
|
||||
setScheme(scheme);
|
||||
setAuthority(authority);
|
||||
setPath(path);
|
||||
setQuery(query);
|
||||
setFragment(fragment);
|
||||
}
|
||||
|
||||
bool Url::hasFragment() const
|
||||
{
|
||||
return !fragment_.empty();
|
||||
}
|
||||
|
||||
bool Url::hasQuery() const
|
||||
{
|
||||
return !query_.empty();
|
||||
}
|
||||
|
||||
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::isValid() const
|
||||
{
|
||||
if (isEmpty())
|
||||
return false;
|
||||
|
||||
if (host_.empty())
|
||||
return false;
|
||||
|
||||
bool valid = true;
|
||||
if (userName_.empty())
|
||||
valid = password_.empty();
|
||||
return valid;
|
||||
}
|
||||
|
||||
int Url::port() const
|
||||
{
|
||||
return port_;
|
||||
}
|
||||
|
||||
std::string Url::password() const
|
||||
{
|
||||
return password_;
|
||||
}
|
||||
|
||||
std::string Url::path() const
|
||||
{
|
||||
return path_;
|
||||
}
|
||||
|
||||
std::string Url::query() const
|
||||
{
|
||||
return query_;
|
||||
}
|
||||
|
||||
std::string Url::scheme() const
|
||||
{
|
||||
return scheme_;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
setUserInfo(userinfo);
|
||||
setHost(host);
|
||||
setPort(!port.empty() ? atoi(port.c_str()): INVALID_PORT);
|
||||
}
|
||||
|
||||
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::setPassword(const std::string & password)
|
||||
{
|
||||
password_ = password;
|
||||
}
|
||||
|
||||
void Url::setPath(const std::string & path)
|
||||
{
|
||||
path_ = path;
|
||||
}
|
||||
|
||||
void Url::setPort(int port)
|
||||
{
|
||||
port_ = port;
|
||||
}
|
||||
|
||||
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::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);
|
||||
}
|
||||
}
|
||||
|
||||
void Url::setUserName(const std::string & userName)
|
||||
{
|
||||
userName_ = userName;
|
||||
}
|
||||
|
||||
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::string Url::userInfo() const
|
||||
{
|
||||
if (!isValid())
|
||||
return std::string();
|
||||
|
||||
std::ostringstream out;
|
||||
out << userName_;
|
||||
if (!password_.empty())
|
||||
out << ":" << password_;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
std::string Url::userName() const
|
||||
{
|
||||
return userName_;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user