2019-11-05 07:54:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-12-06 14:37:21 +00:00
|
|
|
#include <Common/config.h>
|
|
|
|
|
|
|
|
#if USE_AWS_S3
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2021-10-27 23:10:39 +00:00
|
|
|
#include <aws/core/Aws.h>
|
|
|
|
#include <aws/core/client/ClientConfiguration.h>
|
2021-01-27 06:38:35 +00:00
|
|
|
#include <IO/S3/PocoHTTPClient.h>
|
2020-08-11 06:09:08 +00:00
|
|
|
#include <Poco/URI.h>
|
2019-11-05 07:54:13 +00:00
|
|
|
|
2019-12-11 14:21:48 +00:00
|
|
|
namespace Aws::S3
|
|
|
|
{
|
|
|
|
class S3Client;
|
|
|
|
}
|
2019-11-05 07:54:13 +00:00
|
|
|
|
2020-06-01 17:16:09 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2020-08-11 06:09:08 +00:00
|
|
|
class RemoteHostFilter;
|
2020-06-01 17:16:09 +00:00
|
|
|
struct HttpHeader;
|
|
|
|
using HeaderCollection = std::vector<HttpHeader>;
|
|
|
|
}
|
|
|
|
|
2019-12-06 14:37:21 +00:00
|
|
|
namespace DB::S3
|
2019-11-05 07:54:13 +00:00
|
|
|
{
|
2019-12-06 14:48:56 +00:00
|
|
|
class ClientFactory
|
|
|
|
{
|
2019-12-06 14:37:21 +00:00
|
|
|
public:
|
|
|
|
~ClientFactory();
|
2019-12-06 14:48:56 +00:00
|
|
|
|
2019-12-06 14:37:21 +00:00
|
|
|
static ClientFactory & instance();
|
2019-12-06 14:48:56 +00:00
|
|
|
|
2020-06-01 17:16:09 +00:00
|
|
|
std::shared_ptr<Aws::S3::S3Client> create(
|
2021-01-27 06:38:35 +00:00
|
|
|
const PocoHTTPClientConfiguration & cfg,
|
2020-06-01 17:16:09 +00:00
|
|
|
bool is_virtual_hosted_style,
|
|
|
|
const String & access_key_id,
|
|
|
|
const String & secret_access_key,
|
2021-01-28 06:32:41 +00:00
|
|
|
const String & server_side_encryption_customer_key_base64,
|
2020-08-11 06:09:08 +00:00
|
|
|
HeaderCollection headers,
|
2021-03-18 07:36:11 +00:00
|
|
|
bool use_environment_credentials,
|
2021-03-30 00:32:26 +00:00
|
|
|
bool use_insecure_imds_request);
|
2021-01-27 06:38:35 +00:00
|
|
|
|
|
|
|
PocoHTTPClientConfiguration createClientConfiguration(
|
2021-05-01 17:41:16 +00:00
|
|
|
const String & force_region,
|
2020-11-13 16:31:51 +00:00
|
|
|
const RemoteHostFilter & remote_host_filter,
|
2020-11-23 11:02:17 +00:00
|
|
|
unsigned int s3_max_redirects);
|
2020-06-01 17:16:09 +00:00
|
|
|
|
2019-12-06 14:37:21 +00:00
|
|
|
private:
|
2019-12-11 14:21:48 +00:00
|
|
|
ClientFactory();
|
|
|
|
|
|
|
|
Aws::SDKOptions aws_options;
|
2019-12-03 16:23:24 +00:00
|
|
|
};
|
|
|
|
|
2019-12-06 14:37:21 +00:00
|
|
|
/**
|
2019-12-06 14:54:20 +00:00
|
|
|
* Represents S3 URI.
|
|
|
|
*
|
2019-12-06 14:37:21 +00:00
|
|
|
* The following patterns are allowed:
|
|
|
|
* s3://bucket/key
|
|
|
|
* http(s)://endpoint/bucket/key
|
|
|
|
*/
|
2019-12-06 14:48:56 +00:00
|
|
|
struct URI
|
|
|
|
{
|
2019-12-09 10:58:57 +00:00
|
|
|
Poco::URI uri;
|
2019-12-06 14:37:21 +00:00
|
|
|
// Custom endpoint if URI scheme is not S3.
|
|
|
|
String endpoint;
|
|
|
|
String bucket;
|
|
|
|
String key;
|
2022-03-15 02:11:18 +00:00
|
|
|
String version_id;
|
2020-07-13 14:13:30 +00:00
|
|
|
String storage_name;
|
2019-12-03 16:23:24 +00:00
|
|
|
|
2020-05-20 13:47:53 +00:00
|
|
|
bool is_virtual_hosted_style;
|
|
|
|
|
2020-01-18 23:18:23 +00:00
|
|
|
explicit URI(const Poco::URI & uri_);
|
2021-07-25 18:46:31 +00:00
|
|
|
|
2021-08-20 13:12:30 +00:00
|
|
|
static void validateBucket(const String & bucket, const Poco::URI & uri);
|
2019-12-06 14:37:21 +00:00
|
|
|
};
|
2019-12-03 16:23:24 +00:00
|
|
|
|
2022-04-07 09:22:01 +00:00
|
|
|
size_t getObjectSize(std::shared_ptr<Aws::S3::S3Client> client_ptr, const String & bucket, const String & key, const String & version_id = {}, bool throw_on_error = true);
|
2022-03-21 14:52:26 +00:00
|
|
|
|
2019-12-03 16:23:24 +00:00
|
|
|
}
|
2019-11-05 07:54:13 +00:00
|
|
|
|
2019-12-09 12:36:06 +00:00
|
|
|
#endif
|