-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add s3api library, as a copy commit_hash:e32f3a9c6798b44f11f0df18a3ee35d6e7b684a3
- Loading branch information
aserebriyskiy
committed
Oct 30, 2024
1 parent
6e1f256
commit 6f45493
Showing
39 changed files
with
2,070 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
30 changes: 30 additions & 0 deletions
30
libraries/s3api/include/userver/s3api/authenticators/access_key.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
libraries/s3api/include/userver/s3api/authenticators/interface.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
libraries/s3api/include/userver/s3api/authenticators/utils.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.