-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e53133
commit 39b749a
Showing
10 changed files
with
212 additions
and
16 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
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,70 @@ | ||
#include "binsrv/s3_storage_backend.hpp" | ||
|
||
#include <cstddef> | ||
#include <filesystem> | ||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include <aws/core/Aws.h> | ||
|
||
// TODO: remove this include when switching to clang-18 where transitive | ||
// IWYU 'export' pragmas are handled properly | ||
#include "binsrv/basic_storage_backend_fwd.hpp" | ||
|
||
#include "util/byte_span.hpp" | ||
#include "util/impl_helpers.hpp" | ||
|
||
namespace binsrv { | ||
|
||
using options_deimpl = util::deimpl<Aws::SDKOptions>; | ||
|
||
void s3_storage_backend::options_deleter::operator()(void *ptr) const noexcept { | ||
auto *casted_ptr{static_cast<Aws::SDKOptions *>(ptr)}; | ||
Aws::ShutdownAPI(*casted_ptr); | ||
// deleting via std::default_delete to avoid | ||
// cppcoreguidelines-owning-memory warnings | ||
using delete_helper = std::default_delete<Aws::SDKOptions>; | ||
delete_helper{}(casted_ptr); | ||
} | ||
|
||
s3_storage_backend::s3_storage_backend(std::string_view root_path) | ||
: root_path_{root_path}, options_{new Aws::SDKOptions} { | ||
Aws::InitAPI(*options_deimpl::get(options_)); | ||
} | ||
|
||
[[nodiscard]] storage_object_name_container | ||
s3_storage_backend::do_list_objects() { | ||
storage_object_name_container result; | ||
return result; | ||
} | ||
|
||
[[nodiscard]] std::string | ||
s3_storage_backend::do_get_object(std::string_view /*name*/) { | ||
static constexpr std::size_t file_size{8}; | ||
std::string file_content(file_size, 'x'); | ||
return file_content; | ||
} | ||
|
||
void s3_storage_backend::do_put_object(std::string_view /*name*/, | ||
util::const_byte_span /*content*/) {} | ||
|
||
void s3_storage_backend::do_open_stream(std::string_view /*name*/) {} | ||
|
||
void s3_storage_backend::do_write_data_to_stream( | ||
util::const_byte_span /*data*/) {} | ||
|
||
void s3_storage_backend::do_close_stream() {} | ||
|
||
[[nodiscard]] std::string s3_storage_backend::do_get_description() const { | ||
std::string res{"AWS S3 (SDK "}; | ||
const auto &casted_options = *options_deimpl::get(options_); | ||
res += std::to_string(casted_options.sdkVersion.major); | ||
res += '.'; | ||
res += std::to_string(casted_options.sdkVersion.minor); | ||
res += '.'; | ||
res += std::to_string(casted_options.sdkVersion.patch); | ||
res += ')'; | ||
return res; | ||
} | ||
} // namespace binsrv |
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,42 @@ | ||
#ifndef BINSRV_S3_STORAGE_BACKEND_HPP | ||
#define BINSRV_S3_STORAGE_BACKEND_HPP | ||
|
||
#include <filesystem> | ||
#include <string_view> | ||
|
||
#include "binsrv/basic_storage_backend.hpp" // IWYU pragma: export | ||
|
||
namespace binsrv { | ||
|
||
class [[nodiscard]] s3_storage_backend : public basic_storage_backend { | ||
public: | ||
explicit s3_storage_backend(std::string_view root_path); | ||
|
||
[[nodiscard]] const std::filesystem::path &get_root_path() const noexcept { | ||
return root_path_; | ||
} | ||
|
||
private: | ||
std::filesystem::path root_path_; | ||
struct options_deleter { | ||
void operator()(void *ptr) const noexcept; | ||
}; | ||
using options_ptr = std::unique_ptr<void, options_deleter>; | ||
options_ptr options_; | ||
|
||
[[nodiscard]] storage_object_name_container do_list_objects() override; | ||
|
||
[[nodiscard]] std::string do_get_object(std::string_view name) override; | ||
void do_put_object(std::string_view name, | ||
util::const_byte_span content) override; | ||
|
||
void do_open_stream(std::string_view name) override; | ||
void do_write_data_to_stream(util::const_byte_span data) override; | ||
void do_close_stream() override; | ||
|
||
[[nodiscard]] std::string do_get_description() const override; | ||
}; | ||
|
||
} // namespace binsrv | ||
|
||
#endif // BINSRV_S3_STORAGE_BACKEND_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