7 #ifndef TURI_S3_UPLOADER_HPP 8 #define TURI_S3_UPLOADER_HPP 10 #ifndef TC_DISABLE_REMOTEFS 12 #include <aws/s3/S3Client.h> 14 #include <core/logging/assertions.hpp> 15 #include <core/storage/fileio/fs_utils.hpp> 34 std::string access_key_id;
35 std::string secret_key;
37 std::string object_name;
42 boost::optional<std::string> sdk_endpoint;
43 boost::optional<std::string> sdk_region;
44 boost::optional<std::string> sdk_proxy;
47 bool operator==(
const s3url& other)
const {
48 return access_key_id == other.access_key_id &&
49 secret_key == other.secret_key && bucket == other.bucket &&
50 object_name == other.object_name && endpoint == other.endpoint;
60 std::string string_from_s3url(
bool with_credentials =
true)
const {
61 std::string ret(
"s3://");
63 const size_t prot_len = ret.size();
65 if (with_credentials && !access_key_id.empty()) {
67 ret.append(access_key_id);
69 ret.append(secret_key);
75 if (!endpoint.empty()) {
83 if (!object_name.empty()) {
85 if (ret.size() > prot_len) ret.append(1,
'/');
86 ret.append(object_name);
92 friend std::ostream& operator<<(std::ostream& os,
const s3url& url) {
94 os <<
"endpoint used by sdk: " << *url.sdk_endpoint <<
"; ";
95 if (url.sdk_region) os <<
"region used by sdk: " << *url.sdk_region <<
"; ";
96 if (url.sdk_proxy) os <<
"proxy used by sdk: " << *url.sdk_proxy <<
"; ";
97 return os << url.string_from_s3url(
false);
196 std::string proxy =
"");
206 std::pair<file_status, list_objects_response> is_directory(
207 std::string s3_url, std::string proxy =
"");
215 std::string
delete_object(std::string s3_url, std::string proxy =
"");
224 std::string
delete_prefix(std::string s3_url, std::string proxy =
"");
276 static std::string toString(ops_enum operation) {
277 return _enum_to_str.at(operation);
280 static const std::vector<std::string> _enum_to_str;
283 template <
class Response>
284 std::ostream& reportS3Error(std::ostream& ss,
const s3url& parsed_url,
285 S3Operation::ops_enum operation,
286 const Response& outcome) {
287 auto error = outcome.GetError();
288 ss <<
"('" << parsed_url <<
", proxy: '" << parsed_url.sdk_proxy
289 <<
"', region: '" << parsed_url.sdk_region <<
"')" 290 <<
" Error while performing " << S3Operation::toString(operation)
291 <<
". Error Name: " << error.GetExceptionName()
292 <<
". Error Message: " << error.GetMessage()
293 <<
". HTTP Error Code: " <<
static_cast<int>(error.GetResponseCode());
298 #define reportS3ErrorDetailed(ss, parsed_url, operation, outcome) \ 299 reportS3Error(ss, parsed_url, operation, outcome) \ 300 << " in " << __FILE__ << " at " << __LINE__ 304 #endif // End ifndef TC_DISABLE_REMOTEFS std::string sanitize_s3_url(const std::string &url)
std::vector< std::string > directories
A list of all the "sub-directories" found. Encoded with url, see s3url.
void set_download_timeout(long timeout)
std::string get_s3_file_last_modified(const std::string &url)
std::string error
Non-empty if there was an error.
std::string delete_object(std::string s3_url, std::string proxy="")
std::string delete_prefix(std::string s3_url, std::string proxy="")
std::vector< std::string > objects
list_objects_response list_directory(std::string s3_url, std::string proxy="")
#define ASSERT_TRUE(cond)
bool parse_s3url(const std::string &url, s3url &ret, std::string &err_msg)
std::vector< std::string > objects_last_modified
Last modified time for the objects.
list_objects_response list_objects(std::string s3_url, std::string proxy="")
Aws::S3::S3Client init_aws_sdk_with_turi_env(s3url &parsed_url)
void set_upload_timeout(long timeout)
std::vector< size_t > objects_size
A list of all the objects size.