Skip to content

Commit

Permalink
feat userver: add s3api library
Browse files Browse the repository at this point in the history
* Add s3api library, as a copy
commit_hash:e32f3a9c6798b44f11f0df18a3ee35d6e7b684a3
  • Loading branch information
aserebriyskiy committed Oct 30, 2024
1 parent 6e1f256 commit 6f45493
Show file tree
Hide file tree
Showing 39 changed files with 2,070 additions and 4 deletions.
33 changes: 33 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
"cmake/install/userver-core-config.cmake":"taxi/uservices/userver/cmake/install/userver-core-config.cmake",
"cmake/install/userver-grpc-config.cmake":"taxi/uservices/userver/cmake/install/userver-grpc-config.cmake",
"cmake/install/userver-kafka-config.cmake":"taxi/uservices/userver/cmake/install/userver-kafka-config.cmake",
"cmake/install/userver-lib-s3api-config.cmake":"taxi/uservices/userver/cmake/install/userver-lib-s3api-config.cmake",
"cmake/install/userver-mongo-config.cmake":"taxi/uservices/userver/cmake/install/userver-mongo-config.cmake",
"cmake/install/userver-mysql-config.cmake":"taxi/uservices/userver/cmake/install/userver-mysql-config.cmake",
"cmake/install/userver-otlp-config.cmake":"taxi/uservices/userver/cmake/install/userver-otlp-config.cmake",
Expand All @@ -398,6 +399,7 @@
"cmake/modules/FindLibEv.cmake":"taxi/uservices/userver/cmake/modules/FindLibEv.cmake",
"cmake/modules/FindNghttp2.cmake":"taxi/uservices/userver/cmake/modules/FindNghttp2.cmake",
"cmake/modules/FindPostgreSQLInternal.cmake":"taxi/uservices/userver/cmake/modules/FindPostgreSQLInternal.cmake",
"cmake/modules/FindPugixml.cmake":"taxi/uservices/userver/cmake/modules/FindPugixml.cmake",
"cmake/modules/FindPythonDev.cmake":"taxi/uservices/userver/cmake/modules/FindPythonDev.cmake",
"cmake/modules/FindRdKafka.cmake":"taxi/uservices/userver/cmake/modules/FindRdKafka.cmake",
"cmake/modules/FindRocksDB.cmake":"taxi/uservices/userver/cmake/modules/FindRocksDB.cmake",
Expand Down Expand Up @@ -2127,6 +2129,36 @@
"kafka/utest/include/userver/kafka/utest/kafka_fixture.hpp":"taxi/uservices/userver/kafka/utest/include/userver/kafka/utest/kafka_fixture.hpp",
"kafka/utest/src/kafka/utest/kafka_fixture.cpp":"taxi/uservices/userver/kafka/utest/src/kafka/utest/kafka_fixture.cpp",
"kafka/wrapper/include/librdkafka/rdkafka.h":"taxi/uservices/userver/kafka/wrapper/include/librdkafka/rdkafka.h",
"libraries/CMakeLists.txt":"taxi/uservices/userver/libraries/CMakeLists.txt",
"libraries/s3api/CMakeLists.txt":"taxi/uservices/userver/libraries/s3api/CMakeLists.txt",
"libraries/s3api/include/userver/s3api/authenticators/access_key.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/authenticators/access_key.hpp",
"libraries/s3api/include/userver/s3api/authenticators/interface.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/authenticators/interface.hpp",
"libraries/s3api/include/userver/s3api/authenticators/utils.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/authenticators/utils.hpp",
"libraries/s3api/include/userver/s3api/clients/fwd.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/clients/fwd.hpp",
"libraries/s3api/include/userver/s3api/clients/s3api.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/clients/s3api.hpp",
"libraries/s3api/include/userver/s3api/models/fwd.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/models/fwd.hpp",
"libraries/s3api/include/userver/s3api/models/request.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/models/request.hpp",
"libraries/s3api/include/userver/s3api/models/s3api_connection_type.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/models/s3api_connection_type.hpp",
"libraries/s3api/include/userver/s3api/models/secret.hpp":"taxi/uservices/userver/libraries/s3api/include/userver/s3api/models/secret.hpp",
"libraries/s3api/library.yaml":"taxi/uservices/userver/libraries/s3api/library.yaml",
"libraries/s3api/src/s3api/authenticators/access_key.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/authenticators/access_key.cpp",
"libraries/s3api/src/s3api/authenticators/utils.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/authenticators/utils.cpp",
"libraries/s3api/src/s3api/clients/client.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/clients/client.cpp",
"libraries/s3api/src/s3api/clients/client.hpp":"taxi/uservices/userver/libraries/s3api/src/s3api/clients/client.hpp",
"libraries/s3api/src/s3api/models/s3api_connection_type.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/models/s3api_connection_type.cpp",
"libraries/s3api/src/s3api/models/secret.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/models/secret.cpp",
"libraries/s3api/src/s3api/s3_connection.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/s3_connection.cpp",
"libraries/s3api/src/s3api/s3_connection.hpp":"taxi/uservices/userver/libraries/s3api/src/s3api/s3_connection.hpp",
"libraries/s3api/src/s3api/s3api_methods.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/s3api_methods.cpp",
"libraries/s3api/src/s3api/s3api_methods.hpp":"taxi/uservices/userver/libraries/s3api/src/s3api/s3api_methods.hpp",
"libraries/s3api/src/s3api/s3api_methods_test.cpp":"taxi/uservices/userver/libraries/s3api/src/s3api/s3api_methods_test.cpp",
"libraries/s3api/tests/ya.make":"taxi/uservices/userver/libraries/s3api/tests/ya.make",
"libraries/s3api/utest/CMakeLists.txt":"taxi/uservices/userver/libraries/s3api/utest/CMakeLists.txt",
"libraries/s3api/utest/include/userver/s3api/utest/client_gmock.hpp":"taxi/uservices/userver/libraries/s3api/utest/include/userver/s3api/utest/client_gmock.hpp",
"libraries/s3api/utest/src/client_gmock.cpp":"taxi/uservices/userver/libraries/s3api/utest/src/client_gmock.cpp",
"libraries/s3api/utest/ya.make":"taxi/uservices/userver/libraries/s3api/utest/ya.make",
"libraries/s3api/ya.make":"taxi/uservices/userver/libraries/s3api/ya.make",
"libraries/s3api/ya.make.ext":"taxi/uservices/userver/libraries/s3api/ya.make.ext",
"mongo/CMakeLists.txt":"taxi/uservices/userver/mongo/CMakeLists.txt",
"mongo/README.md":"taxi/uservices/userver/mongo/README.md",
"mongo/functional_tests/CMakeLists.txt":"taxi/uservices/userver/mongo/functional_tests/CMakeLists.txt",
Expand Down Expand Up @@ -3319,6 +3351,7 @@
"scripts/docs/en/userver/intro.md":"taxi/uservices/userver/scripts/docs/en/userver/intro.md",
"scripts/docs/en/userver/intro_io_bound_coro.md":"taxi/uservices/userver/scripts/docs/en/userver/intro_io_bound_coro.md",
"scripts/docs/en/userver/kafka.md":"taxi/uservices/userver/scripts/docs/en/userver/kafka.md",
"scripts/docs/en/userver/libraries/s3api.md":"taxi/uservices/userver/scripts/docs/en/userver/libraries/s3api.md",
"scripts/docs/en/userver/log_level_running_service.md":"taxi/uservices/userver/scripts/docs/en/userver/log_level_running_service.md",
"scripts/docs/en/userver/logging.md":"taxi/uservices/userver/scripts/docs/en/userver/logging.md",
"scripts/docs/en/userver/lru_cache.md":"taxi/uservices/userver/scripts/docs/en/userver/lru_cache.md",
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ if (USERVER_FEATURE_YDB)
list(APPEND USERVER_AVAILABLE_COMPONENTS ydb)
endif()

add_subdirectory(libraries)

_userver_export_targets()
_userver_make_install_config()

Expand Down
9 changes: 5 additions & 4 deletions cmake/UserverModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,29 @@ function(userver_module MODULE)
"${ARG_SOURCE_DIR}/src/*.hpp"
"${ARG_SOURCE_DIR}/include/*.hpp"
)
list(REMOVE_ITEM SOURCES ${ARG_IGNORE_SOURCES})
# cmake <= 3.19 has a bug in remove_item
list(REMOVE_ITEM SOURCES ${ARG_IGNORE_SOURCES} "")

list(TRANSFORM ARG_UTEST_DIRS APPEND "/*.cpp" OUTPUT_VARIABLE UTEST_DIRS_SOURCES)
file(GLOB_RECURSE UTEST_SOURCES
${ARG_UTEST_SOURCES}
${UTEST_DIRS_SOURCES}
)
list(REMOVE_ITEM SOURCES ${UTEST_SOURCES})
list(REMOVE_ITEM SOURCES ${UTEST_SOURCES} "")

list(TRANSFORM ARG_DBTEST_DIRS APPEND "/*.cpp" OUTPUT_VARIABLE DBTEST_DIRS_SOURCES)
file(GLOB_RECURSE DBTEST_SOURCES
${ARG_DBTEST_SOURCES}
${DBTEST_DIRS_SOURCES}
)
list(REMOVE_ITEM SOURCES ${DBTEST_SOURCES})
list(REMOVE_ITEM SOURCES ${DBTEST_SOURCES} "")

list(TRANSFORM ARG_UBENCH_DIRS APPEND "/*.cpp" OUTPUT_VARIABLE UBENCH_DIRS_SOURCES)
file(GLOB_RECURSE UBENCH_SOURCES
${ARG_UBENCH_SOURCES}
${UBENCH_DIRS_SOURCES}
)
list(REMOVE_ITEM SOURCES ${UBENCH_SOURCES})
list(REMOVE_ITEM SOURCES ${UBENCH_SOURCES} "")

add_library(userver-${MODULE} STATIC ${SOURCES})
set_target_properties(userver-${MODULE} PROPERTIES LINKER_LANGUAGE CXX)
Expand Down
14 changes: 14 additions & 0 deletions cmake/install/userver-lib-s3api-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include_guard(GLOBAL)

if(userver_lib_s3api_FOUND)
return()
endif()

find_package(userver REQUIRED COMPONENTS
core
)

include("${USERVER_CMAKE_DIR}/FindPugixml.cmake")

set(userver_lib_s3api_FOUND TRUE)

17 changes: 17 additions & 0 deletions cmake/modules/FindPugixml.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
_userver_module_begin(
NAME Pugixml
DEBIAN_NAMES libpugixml-dev
FORMULA_NAMES pugixml
PACMAN_NAMES pugixml
PKG_CONFIG_NAMES pugixml
)

_userver_module_find_include(
NAMES pugixml.hpp
)

_userver_module_find_library(
NAMES pugixml
)

_userver_module_end()
6 changes: 6 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
option(USERVER_FEATURE_S3API "Build S3 api client library" "${USERVER_LIB_ENABLED_DEFAULT}")

if (USERVER_FEATURE_S3API)
add_subdirectory(s3api)
endif()

18 changes: 18 additions & 0 deletions libraries/s3api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
project(userver-lib-s3api CXX)

find_package(Pugixml REQUIRED)

userver_module(lib-s3api
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES_PRIVATE pugixml
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
)

_userver_directory_install(COMPONENT lib-s3api FILES
"${USERVER_ROOT_DIR}/cmake/modules/FindPugixml.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver"
)

if(USERVER_FEATURE_UTEST)
add_subdirectory(utest)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

/// @file userver/s3api/authenticators/access_key.hpp
/// @brief Authenticator for using acess_key&secret_key for authentication

#include <string>
#include <unordered_map>

#include <userver/s3api/authenticators/interface.hpp>
#include <userver/s3api/models/fwd.hpp>

USERVER_NAMESPACE_BEGIN

namespace s3api::authenticators {

class AccessKey : public Authenticator {
public:
AccessKey(std::string access_key, Secret secret_key)
: access_key_{std::move(access_key)}, secret_key_{std::move(secret_key)} {}
std::unordered_map<std::string, std::string> Auth(const Request& request) const override;
std::unordered_map<std::string, std::string> Sign(const Request& request, time_t expires) const override;

private:
std::string access_key_;
Secret secret_key_;
};

} // namespace s3api::authenticators

USERVER_NAMESPACE_END
30 changes: 30 additions & 0 deletions libraries/s3api/include/userver/s3api/authenticators/interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

/// @file userver/s3api/authenticators/interface.hpp
/// @brief Interface for autheticators - classes that sign the request with auth data

#include <memory>
#include <string>
#include <unordered_map>

USERVER_NAMESPACE_BEGIN

namespace s3api {

struct Request;

namespace authenticators {

// This is base class for all authenticators
struct Authenticator {
virtual std::unordered_map<std::string, std::string> Auth(const Request& request) const = 0;
virtual std::unordered_map<std::string, std::string> Sign(const Request& request, time_t expires) const = 0;
virtual ~Authenticator() = default;
};

using AuthenticatorPtr = std::shared_ptr<Authenticator>;

} // namespace authenticators
} // namespace s3api

USERVER_NAMESPACE_END
29 changes: 29 additions & 0 deletions libraries/s3api/include/userver/s3api/authenticators/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

/// @file userver/s3api/authenticators/utils.hpp
/// @brief Helpers for writing your own authenticators

#include <string>

#include <userver/s3api/models/request.hpp>
#include <userver/s3api/models/secret.hpp>

USERVER_NAMESPACE_BEGIN

namespace s3api::authenticators {

std::string MakeHeaderDate();
std::string MakeHeaderContentMd5(const std::string& data);
std::string
MakeHeaderAuthorization(const std::string& string_to_sign, const std::string& access_key, const Secret& secret_key);
std::string MakeSignature(const std::string& string_to_sign, const Secret& secret_key);

std::string MakeStringToSign(
const Request& request,
const std::string& header_date,
const std::optional<std::string>& header_content_md5
);

} // namespace s3api::authenticators

USERVER_NAMESPACE_END
17 changes: 17 additions & 0 deletions libraries/s3api/include/userver/s3api/clients/fwd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

/// @file userver/s3api/clients/fwd.hpp
/// @brief Forward declarations

#include <memory>

USERVER_NAMESPACE_BEGIN

namespace s3api {

class Client;
using ClientPtr = std::shared_ptr<Client>;

} // namespace s3api

USERVER_NAMESPACE_END
Loading

0 comments on commit 6f45493

Please sign in to comment.