MinIO C++ SDK
client.h
1 // MinIO C++ Library for Amazon S3 Compatible Cloud Storage
2 // Copyright 2022 MinIO, Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef _MINIO_S3_CLIENT_H
17 #define _MINIO_S3_CLIENT_H
18 
19 #include <fstream>
20 
21 #include "args.h"
22 #include "request-builder.h"
23 #include "response.h"
24 
25 namespace minio {
26 namespace s3 {
27 utils::Multimap GetCommonListObjectsQueryParams(std::string delimiter,
28  std::string encoding_type,
29  unsigned int max_keys,
30  std::string prefix);
31 
32 class ListObjectsResult;
33 
38 class Client {
39  private:
40  http::BaseUrl& base_url_;
41  creds::Provider* provider_ = NULL;
42  std::map<std::string, std::string> region_map_;
43  bool debug_ = false;
44  bool ignore_cert_check_ = false;
45 
46  public:
47  Client(http::BaseUrl& base_url, creds::Provider* provider = NULL);
48 
49  void Debug(bool flag) { debug_ = flag; }
50 
51  void IgnoreCertCheck(bool flag) { ignore_cert_check_ = flag; }
52 
53  void HandleRedirectResponse(std::string& code, std::string& message,
54  int status_code, http::Method method,
55  utils::Multimap headers,
56  std::string_view bucket_name, bool retry = false);
57  Response GetErrorResponse(http::Response resp, std::string_view resource,
58  http::Method method, std::string_view bucket_name,
59  std::string_view object_name);
60  Response execute(RequestBuilder& builder);
61  Response Execute(RequestBuilder& builder);
62 
63  // S3 APIs
64  ListObjectsResponse ListObjectsV1(ListObjectsV1Args args);
65  ListObjectsResponse ListObjectsV2(ListObjectsV2Args args);
66  ListObjectsResponse ListObjectVersions(ListObjectVersionsArgs args);
67 
68  // Bucket operations
69  GetRegionResponse GetRegion(std::string_view bucket_name,
70  std::string_view region = "");
71  MakeBucketResponse MakeBucket(MakeBucketArgs args);
72  ListBucketsResponse ListBuckets(ListBucketsArgs args);
73  ListBucketsResponse ListBuckets();
74  BucketExistsResponse BucketExists(BucketExistsArgs args);
75  RemoveBucketResponse RemoveBucket(RemoveBucketArgs args);
76 
77  // Object operations
78  AbortMultipartUploadResponse AbortMultipartUpload(
80  CompleteMultipartUploadResponse CompleteMultipartUpload(
82  CreateMultipartUploadResponse CreateMultipartUpload(
84  PutObjectResponse PutObject(PutObjectApiArgs args);
85  UploadPartResponse UploadPart(UploadPartArgs args);
86  UploadPartCopyResponse UploadPartCopy(UploadPartCopyArgs args);
87  StatObjectResponse StatObject(StatObjectArgs args);
88  RemoveObjectResponse RemoveObject(RemoveObjectArgs args);
89  DownloadObjectResponse DownloadObject(DownloadObjectArgs args);
90  GetObjectResponse GetObject(GetObjectArgs args);
91  ListObjectsResult ListObjects(ListObjectsArgs args);
92  PutObjectResponse PutObject(PutObjectArgs& args, std::string& upload_id,
93  char* buf);
94  PutObjectResponse PutObject(PutObjectArgs args);
95  CopyObjectResponse CopyObject(CopyObjectArgs args);
96  StatObjectResponse CalculatePartCount(size_t& part_count,
97  std::list<ComposeSource> sources);
98  ComposeObjectResponse ComposeObject(ComposeObjectArgs args,
99  std::string& upload_id);
100  ComposeObjectResponse ComposeObject(ComposeObjectArgs args);
101  UploadObjectResponse UploadObject(UploadObjectArgs args);
102 }; // class Client
103 
105  private:
106  Client* client_ = NULL;
107  ListObjectsArgs* args_ = NULL;
108  bool failed_ = false;
109  ListObjectsResponse resp_;
110  std::list<Item>::iterator itr_;
111 
112  void Populate();
113 
114  public:
116  ListObjectsResult(Client* client, ListObjectsArgs* args);
117  Item& operator*() const { return *itr_; }
118  operator bool() const { return itr_ != resp_.contents.end(); }
119  ListObjectsResult& operator++() {
120  itr_++;
121  if (!failed_ && itr_ == resp_.contents.end() && resp_.is_truncated) {
122  Populate();
123  }
124  return *this;
125  }
126  ListObjectsResult operator++(int) {
127  ListObjectsResult curr = *this;
128  ++(*this);
129  return curr;
130  }
131 }; // class ListObjectsResult
132 } // namespace s3
133 } // namespace minio
134 #endif // #ifndef __MINIO_S3_CLIENT_H
Definition: creds.h:47
Definition: error.h:23
Definition: client.h:38
Definition: client.h:104
Definition: utils.h:119
Definition: http.h:53
Definition: http.h:108
Definition: args.h:27
Definition: args.h:32
Definition: response.h:71
Definition: args.h:227
Definition: args.h:209
Definition: args.h:137
Definition: args.h:144
Definition: response.h:52
Definition: response.h:138
Definition: response.h:62
Definition: args.h:192
Definition: args.h:151
Definition: response.h:158
Definition: args.h:175
Definition: args.h:182
Definition: args.h:76
Definition: args.h:56
Definition: args.h:112
Definition: args.h:200
Definition: response.h:103
Definition: request-builder.h:24
Definition: response.h:25
Definition: response.h:116
Definition: args.h:233
Definition: args.h:117
Definition: args.h:125