Mercurial > hg > orthanc-object-storage
annotate Aws/AwsS3StoragePlugin.cpp @ 84:8a9207933297
MoveStorageJob serialization
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 21 Oct 2022 14:14:27 +0200 |
parents | d7295e8678d7 |
children | 1bc055199cd2 |
rev | line source |
---|---|
1 | 1 /** |
2 * Cloud storage plugins for Orthanc | |
37
f55b2afdf53d
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
3 * Copyright (C) 2020-2021 Osimis S.A., Belgium |
1 | 4 * |
5 * This program is free software: you can redistribute it and/or | |
6 * modify it under the terms of the GNU Affero General Public License | |
7 * as published by the Free Software Foundation, either version 3 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Affero General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Affero General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 **/ | |
18 | |
19 #include "AwsS3StoragePlugin.h" | |
20 | |
21 #include <aws/core/Aws.h> | |
22 #include <aws/s3/S3Client.h> | |
23 #include <aws/s3/model/PutObjectRequest.h> | |
24 #include <aws/s3/model/GetObjectRequest.h> | |
25 #include <aws/s3/model/ListObjectsRequest.h> | |
26 #include <aws/s3/model/DeleteObjectRequest.h> | |
27 #include <aws/core/auth/AWSCredentialsProvider.h> | |
28 #include <aws/core/utils/memory/stl/AWSStringStream.h> | |
74
a25b4140e7e4
AWS: added the content MD5 in the request when writing
Alain Mazy <am@osimis.io>
parents:
70
diff
changeset
|
29 #include <aws/core/utils/HashingUtils.h> |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
30 #include <aws/crt/Api.h> |
1 | 31 |
32 #include <boost/lexical_cast.hpp> | |
33 #include <iostream> | |
34 #include <fstream> | |
35 | |
36 const char* ALLOCATION_TAG = "OrthancS3"; | |
37 | |
78 | 38 class AwsS3StoragePlugin : public BaseStorage |
1 | 39 { |
40 public: | |
41 | |
42 Aws::S3::S3Client client_; | |
43 std::string bucketName_; | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
44 bool storageContainsUnknownFiles_; |
1 | 45 |
46 public: | |
47 | |
77 | 48 AwsS3StoragePlugin(const std::string& nameForLogs, const Aws::S3::S3Client& client, const std::string& bucketName, bool enableLegacyStorageStructure, bool storageContainsUnknownFiles); |
1 | 49 |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
50 virtual ~AwsS3StoragePlugin(); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
51 |
1 | 52 virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); |
53 virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); | |
54 virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); | |
55 }; | |
56 | |
57 | |
78 | 58 class Writer : public IStorage::IWriter |
1 | 59 { |
60 std::string path_; | |
61 Aws::S3::S3Client client_; | |
62 std::string bucketName_; | |
63 | |
64 public: | |
65 Writer(const Aws::S3::S3Client& client, const std::string& bucketName, const std::string& path) | |
66 : path_(path), | |
67 client_(client), | |
68 bucketName_(bucketName) | |
69 { | |
70 } | |
71 | |
72 virtual ~Writer() | |
73 { | |
74 } | |
75 | |
76 virtual void Write(const char* data, size_t size) | |
77 { | |
78 Aws::S3::Model::PutObjectRequest putObjectRequest; | |
79 | |
80 putObjectRequest.SetBucket(bucketName_.c_str()); | |
81 putObjectRequest.SetKey(path_.c_str()); | |
82 | |
83 std::shared_ptr<Aws::StringStream> stream = Aws::MakeShared<Aws::StringStream>(ALLOCATION_TAG, std::ios_base::in | std::ios_base::binary); | |
84 | |
85 stream->rdbuf()->pubsetbuf(const_cast<char*>(data), size); | |
86 stream->rdbuf()->pubseekpos(size); | |
87 stream->seekg(0); | |
88 | |
89 putObjectRequest.SetBody(stream); | |
74
a25b4140e7e4
AWS: added the content MD5 in the request when writing
Alain Mazy <am@osimis.io>
parents:
70
diff
changeset
|
90 putObjectRequest.SetContentMD5(Aws::Utils::HashingUtils::Base64Encode(Aws::Utils::HashingUtils::CalculateMD5(*stream))); |
1 | 91 |
92 auto result = client_.PutObject(putObjectRequest); | |
93 | |
94 if (!result.IsSuccess()) | |
95 { | |
62 | 96 throw StoragePluginException(std::string("error while writing file ") + path_ + ": response code = " + boost::lexical_cast<std::string>((int)result.GetError().GetResponseCode()) + " " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
1 | 97 } |
98 } | |
99 }; | |
100 | |
101 | |
78 | 102 class Reader : public IStorage::IReader |
1 | 103 { |
104 Aws::S3::S3Client client_; | |
105 std::string bucketName_; | |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
106 std::list<std::string> paths_; |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
107 std::string uuid_; |
1 | 108 |
109 public: | |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
110 Reader(const Aws::S3::S3Client& client, const std::string& bucketName, const std::list<std::string>& paths, const char* uuid) |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
111 : client_(client), |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
112 bucketName_(bucketName), |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
113 paths_(paths), |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
114 uuid_(uuid) |
1 | 115 { |
116 } | |
117 | |
118 virtual ~Reader() | |
119 { | |
120 | |
121 } | |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
122 |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
123 virtual size_t GetSize() |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
124 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
125 std::string firstExceptionMessage; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
126 |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
127 for (auto& path: paths_) |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
128 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
129 try |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
130 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
131 return _GetSize(path); |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
132 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
133 catch (StoragePluginException& ex) |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
134 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
135 if (firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
136 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
137 firstExceptionMessage = ex.what(); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
138 } |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
139 //ignore to retry |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
140 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
141 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
142 throw StoragePluginException(firstExceptionMessage); |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
143 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
144 |
41 | 145 virtual void ReadWhole(char* data, size_t size) |
146 { | |
147 _Read(data, size, 0, false); | |
148 } | |
149 | |
150 virtual void ReadRange(char* data, size_t size, size_t fromOffset) | |
151 { | |
152 _Read(data, size, fromOffset, true); | |
153 } | |
154 | |
70
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
155 private: |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
156 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
157 size_t _GetSize(const std::string& path) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
158 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
159 Aws::S3::Model::ListObjectsRequest listObjectRequest; |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
160 listObjectRequest.SetBucket(bucketName_.c_str()); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
161 listObjectRequest.SetPrefix(path.c_str()); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
162 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
163 auto result = client_.ListObjects(listObjectRequest); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
164 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
165 if (result.IsSuccess()) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
166 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
167 Aws::Vector<Aws::S3::Model::Object> objectList = |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
168 result.GetResult().GetContents(); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
169 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
170 if (objectList.size() == 1) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
171 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
172 return objectList[0].GetSize(); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
173 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
174 else if (objectList.size() > 1) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
175 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
176 throw StoragePluginException(std::string("error while reading file ") + path + ": multiple objet with same name !"); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
177 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
178 throw StoragePluginException(std::string("error while reading file ") + path + ": object not found !"); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
179 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
180 else |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
181 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
182 throw StoragePluginException(std::string("error while reading file ") + path + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
183 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
184 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
185 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
186 |
41 | 187 void _Read(char* data, size_t size, size_t fromOffset, bool useRange) |
1 | 188 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
189 std::string firstExceptionMessage; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
190 |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
191 for (auto& path: paths_) |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
192 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
193 try |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
194 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
195 return __Read(path, data, size, fromOffset, useRange); |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
196 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
197 catch (StoragePluginException& ex) |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
198 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
199 if (firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
200 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
201 firstExceptionMessage = ex.what(); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
202 } |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
203 //ignore to retry |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
204 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
205 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
206 throw StoragePluginException(firstExceptionMessage); |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
207 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
208 |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
209 void __Read(const std::string& path, char* data, size_t size, size_t fromOffset, bool useRange) |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
210 { |
1 | 211 Aws::S3::Model::GetObjectRequest getObjectRequest; |
212 getObjectRequest.SetBucket(bucketName_.c_str()); | |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
213 getObjectRequest.SetKey(path.c_str()); |
1 | 214 |
41 | 215 if (useRange) |
216 { | |
217 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests | |
218 std::string range = std::string("bytes=") + boost::lexical_cast<std::string>(fromOffset) + "-" + boost::lexical_cast<std::string>(fromOffset + size -1); | |
219 getObjectRequest.SetRange(range.c_str()); | |
220 } | |
221 | |
1 | 222 getObjectRequest.SetResponseStreamFactory( |
223 [data, size]() | |
224 { | |
225 std::unique_ptr<Aws::StringStream> | |
226 istream(Aws::New<Aws::StringStream>(ALLOCATION_TAG)); | |
227 | |
228 istream->rdbuf()->pubsetbuf(static_cast<char*>(data), | |
229 size); | |
230 | |
231 return istream.release(); | |
232 }); | |
233 | |
234 // Get the object | |
235 auto result = client_.GetObject(getObjectRequest); | |
236 if (result.IsSuccess()) | |
237 { | |
238 } | |
239 else | |
240 { | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
241 throw StoragePluginException(std::string("error while reading file ") + path + ": response code = " + boost::lexical_cast<std::string>((int)result.GetError().GetResponseCode()) + " " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
1 | 242 } |
243 } | |
244 | |
245 }; | |
246 | |
247 | |
248 | |
41 | 249 |
250 | |
1 | 251 const char* AwsS3StoragePluginFactory::GetStoragePluginName() |
252 { | |
253 return "AWS S3 Storage"; | |
254 } | |
255 | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
256 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
257 static std::unique_ptr<Aws::Crt::ApiHandle> api_; |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
258 static std::unique_ptr<Aws::SDKOptions> sdkOptions_; |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
259 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
260 |
78 | 261 IStorage* AwsS3StoragePluginFactory::CreateStorage(const std::string& nameForLogs, const OrthancPlugins::OrthancConfiguration& orthancConfig) |
1 | 262 { |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
263 if (sdkOptions_.get() != NULL) |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
264 { |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
265 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, "Cannot initialize twice"); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
266 } |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
267 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
268 api_.reset(new Aws::Crt::ApiHandle); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
269 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
270 sdkOptions_.reset(new Aws::SDKOptions); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
271 sdkOptions_->cryptoOptions.initAndCleanupOpenSSL = false; // Done by the Orthanc framework |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
272 sdkOptions_->httpOptions.initAndCleanupCurl = false; // Done by the Orthanc framework |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
273 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
274 Aws::InitAPI(*sdkOptions_); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
275 |
15 | 276 bool enableLegacyStorageStructure; |
70
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
277 bool storageContainsUnknownFiles; |
15 | 278 |
77 | 279 if (!orthancConfig.IsSection(GetConfigurationSectionName())) |
1 | 280 { |
281 OrthancPlugins::LogWarning(std::string(GetStoragePluginName()) + " plugin, section missing. Plugin is not enabled."); | |
282 return nullptr; | |
283 } | |
284 | |
285 OrthancPlugins::OrthancConfiguration pluginSection; | |
77 | 286 orthancConfig.GetSection(pluginSection, GetConfigurationSectionName()); |
1 | 287 |
78 | 288 if (!BaseStorage::ReadCommonConfiguration(enableLegacyStorageStructure, storageContainsUnknownFiles, pluginSection)) |
15 | 289 { |
290 return nullptr; | |
291 } | |
292 | |
1 | 293 std::string bucketName; |
294 std::string region; | |
295 std::string accessKey; | |
296 std::string secretKey; | |
297 | |
298 if (!pluginSection.LookupStringValue(bucketName, "BucketName")) | |
299 { | |
300 OrthancPlugins::LogError("AwsS3Storage/BucketName configuration missing. Unable to initialize plugin"); | |
301 return nullptr; | |
302 } | |
303 | |
304 if (!pluginSection.LookupStringValue(region, "Region")) | |
305 { | |
306 OrthancPlugins::LogError("AwsS3Storage/Region configuration missing. Unable to initialize plugin"); | |
307 return nullptr; | |
308 } | |
309 | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
310 const std::string endpoint = pluginSection.GetStringValue("Endpoint", ""); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
311 const unsigned int connectTimeout = pluginSection.GetUnsignedIntegerValue("ConnectTimeout", 30); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
312 const unsigned int requestTimeout = pluginSection.GetUnsignedIntegerValue("RequestTimeout", 1200); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
313 const bool virtualAddressing = pluginSection.GetBooleanValue("VirtualAddressing", true); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
314 const std::string caFile = orthancConfig.GetStringValue("HttpsCACertificates", ""); |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
315 |
1 | 316 try |
317 { | |
318 Aws::SDKOptions options; | |
319 Aws::InitAPI(options); | |
320 | |
321 Aws::Client::ClientConfiguration configuration; | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
322 |
1 | 323 configuration.region = region.c_str(); |
6
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
324 configuration.scheme = Aws::Http::Scheme::HTTPS; |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
325 configuration.connectTimeoutMs = connectTimeout * 1000; |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
326 configuration.requestTimeoutMs = requestTimeout * 1000; |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
327 configuration.httpRequestTimeoutMs = requestTimeout * 1000; |
6
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
328 |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
329 if (!endpoint.empty()) |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
330 { |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
331 configuration.endpointOverride = endpoint.c_str(); |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
332 } |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
333 |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
334 if (!caFile.empty()) |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
335 { |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
336 configuration.caFile = caFile; |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
337 } |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
338 |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
339 if (pluginSection.LookupStringValue(accessKey, "AccessKey") && pluginSection.LookupStringValue(secretKey, "SecretKey")) |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
340 { |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
341 OrthancPlugins::LogInfo("AWS S3 Storage: using credentials from the configuration file"); |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
342 Aws::Auth::AWSCredentials credentials(accessKey.c_str(), secretKey.c_str()); |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
343 |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
344 Aws::S3::S3Client client(credentials, configuration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, virtualAddressing); |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
345 |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
346 OrthancPlugins::LogInfo("AWS S3 storage initialized"); |
1 | 347 |
77 | 348 return new AwsS3StoragePlugin(nameForLogs, client, bucketName, enableLegacyStorageStructure, storageContainsUnknownFiles); |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
349 } |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
350 else |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
351 { |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
352 // when using default credentials, credentials are not checked at startup but only the first time you try to access the bucket ! |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
353 OrthancPlugins::LogInfo("AWS S3 Storage: using default credentials provider"); |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
354 Aws::S3::S3Client client(configuration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, virtualAddressing); |
1 | 355 |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
356 OrthancPlugins::LogInfo("AWS S3 storage initialized"); |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
357 |
77 | 358 return new AwsS3StoragePlugin(nameForLogs, client, bucketName, enableLegacyStorageStructure, storageContainsUnknownFiles); |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
359 } |
1 | 360 } |
361 catch (const std::exception& e) | |
362 { | |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
363 OrthancPlugins::LogError(std::string("AWS S3 Storage plugin: failed to initialize plugin: ") + e.what()); |
1 | 364 return nullptr; |
365 } | |
366 | |
367 } | |
368 | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
369 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
370 AwsS3StoragePlugin::~AwsS3StoragePlugin() |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
371 { |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
372 assert(sdkOptions_.get() != NULL); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
373 Aws::ShutdownAPI(*sdkOptions_); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
374 api_.reset(); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
375 } |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
376 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
377 |
77 | 378 AwsS3StoragePlugin::AwsS3StoragePlugin(const std::string& nameForLogs, const Aws::S3::S3Client& client, const std::string& bucketName, bool enableLegacyStorageStructure, bool storageContainsUnknownFiles) |
78 | 379 : BaseStorage(nameForLogs, enableLegacyStorageStructure), |
15 | 380 client_(client), |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
381 bucketName_(bucketName), |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
382 storageContainsUnknownFiles_(storageContainsUnknownFiles) |
1 | 383 { |
384 } | |
385 | |
78 | 386 IStorage::IWriter* AwsS3StoragePlugin::GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) |
1 | 387 { |
388 return new Writer(client_, bucketName_, GetPath(uuid, type, encryptionEnabled)); | |
389 } | |
390 | |
78 | 391 IStorage::IReader* AwsS3StoragePlugin::GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) |
1 | 392 { |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
393 std::list<std::string> paths; |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
394 paths.push_back(GetPath(uuid, type, encryptionEnabled, false)); |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
395 if (storageContainsUnknownFiles_) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
396 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
397 paths.push_back(GetPath(uuid, type, encryptionEnabled, true)); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
398 } |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
399 |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
400 return new Reader(client_, bucketName_, paths, uuid); |
1 | 401 } |
402 | |
403 void AwsS3StoragePlugin::DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) | |
404 { | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
405 std::string firstExceptionMessage; |
1 | 406 |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
407 std::list<std::string> paths; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
408 paths.push_back(GetPath(uuid, type, encryptionEnabled, false)); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
409 if (storageContainsUnknownFiles_) |
1 | 410 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
411 paths.push_back(GetPath(uuid, type, encryptionEnabled, true)); |
1 | 412 } |
413 | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
414 // DeleteObject succeeds even if the file does not exist -> we need to try to delete every path |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
415 for (auto& path: paths) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
416 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
417 Aws::S3::Model::DeleteObjectRequest deleteObjectRequest; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
418 deleteObjectRequest.SetBucket(bucketName_.c_str()); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
419 deleteObjectRequest.SetKey(path.c_str()); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
420 |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
421 auto result = client_.DeleteObject(deleteObjectRequest); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
422 |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
423 if (!result.IsSuccess() && firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
424 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
425 firstExceptionMessage = std::string("error while deleting file ") + path + ": response code = " + boost::lexical_cast<std::string>((int)result.GetError().GetResponseCode()) + " " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str(); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
426 } |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
427 } |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
428 |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
429 if (!firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
430 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
431 throw StoragePluginException(firstExceptionMessage); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
432 } |
1 | 433 } |