MinIO C++ SDK
s3.h
1 // MinIO C++ Library for Amazon S3 Compatible Cloud Storage
2 // Copyright 2021 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 _S3_H
17 #define _S3_H
18 
19 #include <iostream>
20 #include <fstream>
21 #include <string>
22 #include <vector>
23 #include <list>
24 #include <map>
25 #include <sstream>
26 
27 #include "s3_io.h"
28 #include "s3_types.h"
29 #include "s3_headers.h"
30 
31 using namespace Minio;
32 
33 class S3Client {
34  private:
35  std::string endpoint, keyID, secret;
36  int verbosity;
37  std::list<Minio::S3::Bucket> buckets;
38 
39  std::string SignV2Request(const Minio::S3ClientIO & io, const std::string & uri, const std::string & mthd);
40 
41  void Submit(const std::string & url, const std::string & uri,
42  Http::Method method, Minio::S3ClientIO & io, S3Connection ** conn);
43 
44  static std::string ParseCreateMultipartUpload(const std::string & xml);
45  static void ParseBucketsList(std::list<Minio::S3::Bucket> & buckets, const std::string & xml);
46  static void ParseObjectsList(std::list<Minio::S3::Object> & objects, const std::string & xml);
47 
48  public:
49  S3Client(const std::string & endpoint, const std::string & kid, const std::string & sk);
50  ~S3Client();
51 
52  void SetVerbosity(int v) {verbosity = v;}
53 
54  void ListObjects(Minio::S3::Bucket & bucket, S3Connection ** conn = NULL);
55 
56  // Upload from IO stream.
57  void PutObject(const std::string & bkt, const std::string & key,
58  Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
59 
60  // Upload from local path.
61  void PutObject(const std::string & bkt, const std::string & key,
62  const std::string & localpath,
63  Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
64 
65  // Get object data (GET /key) with specific partNumber.
66  void GetObject(const std::string & bkt, const std::string & key,
67  const int & part_number,
68  Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
69 
70  // Get object data fully
71  void GetObject(const std::string & bkt, const std::string & key,
72  Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
73 
74  // Get meta-data on object (HEAD)
75  // Headers are same as for GetObject(), but no data is retrieved.
76  void StatObject(const std::string & bkt, const std::string & key,
77  Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
78 
79  // Delete object (DELETE)
80  void DeleteObject(const std::string & bkt, const std::string & key,
81  Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
82 
83  // Copy object (COPY)
84  void CopyObject(const std::string & srcbkt, const std::string & srckey,
85  const std::string & dstbkt, const std::string & dstkey, bool copyMD,
86  Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
87 
88  // List buckets (s3.amazonaws.com GET /)
89  void ListBuckets(Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
90 
91  // Make bucket (bucket.s3.amazonaws.com PUT /)
92  void MakeBucket(const std::string & bkt, Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
93 
94  // List objects (bucket.s3.amazonaws.com GET /)
95  void ListObjects(const std::string & bkt, Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
96 
97  // Remove bucket (bucket.s3.amazonaws.com DELETE /)
98  void RemoveBucket(const std::string & bkt, Minio::S3ClientIO & io, S3Connection ** reqPtr = NULL);
99 
100  // Multipart APIs
101  // Upload from io stream to a specific part number for multipart upload_id.
102  Minio::S3::CompletePart PutObject(const std::string & bkt,
103  const std::string & key,
104  const int & part_number,
105  const std::string & upload_id,
106  Minio::S3ClientIO & io,
107  S3Connection ** reqPtr = NULL);
108 
109 
110  std::string CreateMultipartUpload(const std::string & bkt,
111  const std::string & key,
112  Minio::S3ClientIO & io,
113  S3Connection ** reqPtr = NULL);
114 
115  void AbortMultipartUpload(const std::string & bkt,
116  const std::string & key,
117  const std::string & upload_id,
118  S3Connection ** reqPtr = NULL);
119 
120  void CompleteMultipartUpload(const std::string & bkt,
121  const std::string & key,
122  const std::string & upload_id,
123  const std::list<Minio::S3::CompletePart> & parts,
124  Minio::S3ClientIO & io,
125  S3Connection ** reqPtr = NULL);
126 };
127 
128 #endif /* _S3_H */
S3Client
Definition: s3.h:33
Minio::S3::Bucket
Definition: s3_types.h:42
Minio::S3ClientIO
Definition: s3_io.h:34
Minio::S3::CompletePart
Definition: s3_types.h:51