userver: /data/code/userver/libraries/s3api/src/s3api/clients/client.hpp Source File
Loading...
Searching...
No Matches
client.hpp
1#pragma once
2
3/// @file userver/s3api/clients/s3api.hpp
4/// @brief Client for any S3 api service
5///
6
7#include <chrono>
8#include <optional>
9#include <string>
10#include <unordered_map>
11#include <unordered_set>
12#include <vector>
13
14#include <userver/clients/http/request.hpp>
15#include <userver/clients/http/response.hpp>
16#include <userver/utils/overloaded.hpp>
17#include <userver/utils/str_icase.hpp>
18
19#include <userver/s3api/clients/s3api.hpp>
20
21#include <userver/s3api/authenticators/access_key.hpp>
22#include <userver/s3api/authenticators/interface.hpp>
23#include <userver/s3api/models/fwd.hpp>
24#include <userver/s3api/models/s3api_connection_type.hpp>
25
26USERVER_NAMESPACE_BEGIN
27
28namespace clients::http {
29class Client;
30}
31
32namespace s3api {
33
34/// Implementation of S3 client
35class ClientImpl : public Client {
36public:
37 ClientImpl(
38 std::shared_ptr<S3Connection> s3conn,
39 std::shared_ptr<authenticators::Authenticator> authenticator,
40 std::string bucket
41 );
42 // Deprecated, use constructor with general Authenticator interface
43 ClientImpl(
44 std::shared_ptr<S3Connection> s3conn,
45 std::shared_ptr<authenticators::AccessKey> authenticator,
46 std::string bucket
47 );
48 ~ClientImpl() override = default;
49
50 std::string PutObject(
51 std::string_view path,
52 std::string data,
53 const std::optional<Meta>& meta,
54 std::string_view content_type,
55 const std::optional<std::string>& content_disposition,
56 const std::optional<std::vector<Tag>>& tags
57 ) const final;
58
59 void DeleteObject(std::string_view path) const final;
60
61 std::optional<std::string> GetObject(
62 std::string_view path,
63 std::optional<std::string> versiong,
64 HeadersDataResponse* headers_data,
65 const HeaderDataRequest& headers_request
66 ) const final;
67
68 std::string TryGetObject(
69 std::string_view path,
70 std::optional<std::string> versiong,
71 HeadersDataResponse* headers_data,
72 const HeaderDataRequest& headers_request
73 ) const final;
74
75 std::optional<std::string> GetPartialObject(
76 std::string_view path,
77 std::string_view range,
78 std::optional<std::string> versiong,
79 HeadersDataResponse* headers_data,
80 const HeaderDataRequest& headers_request
81 ) const final;
82
83 std::string TryGetPartialObject(
84 std::string_view path,
85 std::string_view range,
86 std::optional<std::string> versiong,
87 HeadersDataResponse* headers_data,
88 const HeaderDataRequest& headers_request
89 ) const final;
90
91 std::string CopyObject(
92 std::string_view key_from,
93 std::string_view bucket_to,
94 std::string_view key_to,
95 const std::optional<Meta>& meta
96 ) final;
97
98 std::string CopyObject(std::string_view key_from, std::string_view key_to, const std::optional<Meta>& meta) final;
99
100 std::optional<HeadersDataResponse> GetObjectHead(std::string_view path, const HeaderDataRequest& request)
101 const final;
102
103 std::string GenerateDownloadUrl(std::string_view path, time_t expires, bool use_ssl) const final;
104
105 std::string GenerateDownloadUrlVirtualHostAddressing(
106 std::string_view path,
107 const std::chrono::system_clock::time_point& expires_at,
108 std::string_view protocol
109 ) const final;
110
111 std::string GenerateUploadUrlVirtualHostAddressing(
112 std::string_view data,
113 std::string_view content_type,
114 std::string_view path,
115 const std::chrono::system_clock::time_point& expires_at,
116 std::string_view protocol
117 ) const final;
118
119 std::optional<std::string>
120 ListBucketContents(std::string_view path, int max_keys, std::string marker, std::string delimiter) const final;
121
122 std::vector<ObjectMeta> ListBucketContentsParsed(std::string_view path_prefix) const final;
123
124 std::vector<std::string> ListBucketDirectories(std::string_view path_prefix) const final;
125
126 void UpdateConfig(ConnectionCfg&& config) final;
127
128 std::string_view GetBucketName() const final;
129
130private:
131 void Auth(Request& request) const;
132 std::string RequestApi(
133 Request& request,
134 std::string_view method_name,
135 HeadersDataResponse* headers_data = nullptr,
136 const HeaderDataRequest& headers_request = HeaderDataRequest()
137 ) const;
138
139 std::shared_ptr<S3Connection> conn_;
140 std::shared_ptr<authenticators::Authenticator> authenticator_;
141 std::string bucket_;
142};
143
144} // namespace s3api
145
146USERVER_NAMESPACE_END