client.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef _MINIO_S3_CLIENT_H
  16. #define _MINIO_S3_CLIENT_H
  17. #include "args.h"
  18. #include "baseclient.h"
  19. #include "config.h"
  20. #include "request.h"
  21. #include "response.h"
  22. #include <fstream>
  23. namespace minio {
  24. namespace s3 {
  25. class Client;
  26. class ListObjectsResult {
  27. private:
  28. Client* client_ = NULL;
  29. ListObjectsArgs args_;
  30. bool failed_ = false;
  31. ListObjectsResponse resp_;
  32. std::list<Item>::iterator itr_;
  33. void Populate();
  34. public:
  35. ListObjectsResult(error::Error err);
  36. ListObjectsResult(Client* client, ListObjectsArgs args);
  37. Item& operator*() const { return *itr_; }
  38. operator bool() const { return itr_ != resp_.contents.end(); }
  39. ListObjectsResult& operator++() {
  40. itr_++;
  41. if (!failed_ && itr_ == resp_.contents.end() && resp_.is_truncated) {
  42. Populate();
  43. }
  44. return *this;
  45. }
  46. ListObjectsResult operator++(int) {
  47. ListObjectsResult curr = *this;
  48. ++(*this);
  49. return curr;
  50. }
  51. }; // class ListObjectsResult
  52. class RemoveObjectsResult {
  53. private:
  54. Client* client_ = NULL;
  55. RemoveObjectsArgs args_;
  56. bool done_ = false;
  57. RemoveObjectsResponse resp_;
  58. std::list<DeleteError>::iterator itr_;
  59. void Populate();
  60. public:
  61. RemoveObjectsResult(error::Error err);
  62. RemoveObjectsResult(Client* client, RemoveObjectsArgs args);
  63. DeleteError& operator*() const { return *itr_; }
  64. operator bool() const { return itr_ != resp_.errors.end(); }
  65. RemoveObjectsResult& operator++() {
  66. itr_++;
  67. if (!done_ && itr_ == resp_.errors.end()) {
  68. Populate();
  69. }
  70. return *this;
  71. }
  72. RemoveObjectsResult operator++(int) {
  73. RemoveObjectsResult curr = *this;
  74. ++(*this);
  75. return curr;
  76. }
  77. }; // class RemoveObjectsResult
  78. /**
  79. * Simple Storage Service (aka S3) client to perform bucket and object
  80. * operations.
  81. */
  82. class Client : public BaseClient {
  83. protected:
  84. StatObjectResponse CalculatePartCount(size_t& part_count,
  85. std::list<ComposeSource> sources);
  86. ComposeObjectResponse ComposeObject(ComposeObjectArgs args,
  87. std::string& upload_id);
  88. PutObjectResponse PutObject(PutObjectArgs& args, std::string& upload_id,
  89. char* buf);
  90. public:
  91. Client(BaseUrl& base_url, creds::Provider* provider = NULL);
  92. ComposeObjectResponse ComposeObject(ComposeObjectArgs args);
  93. CopyObjectResponse CopyObject(CopyObjectArgs args);
  94. DownloadObjectResponse DownloadObject(DownloadObjectArgs args);
  95. ListObjectsResult ListObjects(ListObjectsArgs args);
  96. PutObjectResponse PutObject(PutObjectArgs args);
  97. UploadObjectResponse UploadObject(UploadObjectArgs args);
  98. RemoveObjectsResult RemoveObjects(RemoveObjectsArgs args);
  99. }; // class Client
  100. } // namespace s3
  101. } // namespace minio
  102. #endif // #ifndef __MINIO_S3_CLIENT_H