Mercurial > hg > orthanc-object-storage
annotate Common/StoragePlugin.cpp @ 78:d7295e8678d7
renames
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 14 Oct 2022 11:00:18 +0200 |
parents | 80792bb9600e |
children | 431ab61b5760 |
rev | line source |
---|---|
1 | 1 /** |
2 * Cloud storage plugins for Orthanc | |
37
f55b2afdf53d
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
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 | |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
19 |
1 | 20 #if GOOGLE_STORAGE_PLUGIN==1 |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
21 # include "../Google/GoogleStoragePlugin.h" |
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
22 # define StoragePluginFactory GoogleStoragePluginFactory |
1 | 23 #elif AZURE_STORAGE_PLUGIN==1 |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
24 # include "../Azure/AzureBlobStoragePlugin.h" |
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
25 # define StoragePluginFactory AzureBlobStoragePluginFactory |
1 | 26 #elif AWS_STORAGE_PLUGIN==1 |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
27 # include "../Aws/AwsS3StoragePlugin.h" |
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
28 # define StoragePluginFactory AwsS3StoragePluginFactory |
1 | 29 #else |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
30 # pragma message(error "define a plugin") |
1 | 31 #endif |
32 | |
33 #include <string.h> | |
34 #include <stdio.h> | |
35 #include <string> | |
36 | |
37 #include <iostream> | |
15 | 38 #include <boost/filesystem.hpp> |
39 #include <boost/filesystem/fstream.hpp> | |
40 | |
1 | 41 #include "../Common/EncryptionHelpers.h" |
42 #include "../Common/EncryptionConfigurator.h" | |
78 | 43 #include "../Common/FileSystemStorage.h" |
35
8a7a5defd5d0
upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
44 |
8a7a5defd5d0
upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
45 #include <Logging.h> |
15 | 46 #include <SystemToolbox.h> |
1 | 47 |
78 | 48 static std::unique_ptr<IStorage> primaryStorage; |
49 static std::unique_ptr<IStorage> secondaryStorage; | |
1 | 50 |
51 static std::unique_ptr<EncryptionHelpers> crypto; | |
52 static bool cryptoEnabled = false; | |
15 | 53 static std::string fileSystemRootPath; |
20 | 54 static std::string objectsRootPath; |
77 | 55 static std::string hybridModeNameForLogs = ""; |
56 | |
57 typedef enum | |
58 { | |
59 HybridMode_WriteToFileSystem, // write to disk, try to read first from disk and then, from object-storage | |
60 HybridMode_WriteToObjectStorage, // write to object storage, try to read first from object storage and then, from disk | |
61 HybridMode_Disabled // read and write only from/to object-storage | |
62 } HybridMode; | |
63 | |
64 static HybridMode hybridMode = HybridMode_Disabled; | |
65 | |
66 static bool IsReadFromDisk() | |
67 { | |
68 return hybridMode != HybridMode_Disabled; | |
69 } | |
70 | |
71 static bool IsHybridModeEnabled() | |
72 { | |
73 return hybridMode != HybridMode_Disabled; | |
74 } | |
75 | |
76 typedef void LogErrorFunction(const std::string& message); | |
77 | |
1 | 78 |
79 | |
80 static OrthancPluginErrorCode StorageCreate(const char* uuid, | |
81 const void* content, | |
82 int64_t size, | |
83 OrthancPluginContentType type) | |
84 { | |
85 try | |
86 { | |
78 | 87 OrthancPlugins::LogInfo(primaryStorage->GetNameForLogs() + ": creating attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
88 std::unique_ptr<IStorage::IWriter> writer(primaryStorage->GetWriterForObject(uuid, type, cryptoEnabled)); | |
1 | 89 |
90 if (cryptoEnabled) | |
91 { | |
92 std::string encryptedFile; | |
93 | |
94 try | |
95 { | |
96 crypto->Encrypt(encryptedFile, (const char*)content, size); | |
97 } | |
98 catch (EncryptionException& ex) | |
99 { | |
78 | 100 OrthancPlugins::LogError(primaryStorage->GetNameForLogs() + ": error while encrypting object " + std::string(uuid) + ": " + ex.what()); |
1 | 101 return OrthancPluginErrorCode_StorageAreaPlugin; |
102 } | |
103 | |
104 writer->Write(encryptedFile.data(), encryptedFile.size()); | |
105 } | |
106 else | |
107 { | |
108 writer->Write(reinterpret_cast<const char*>(content), size); | |
109 } | |
110 } | |
111 catch (StoragePluginException& ex) | |
112 { | |
78 | 113 OrthancPlugins::LogError(primaryStorage->GetNameForLogs() + ": error while creating object " + std::string(uuid) + ": " + ex.what()); |
1 | 114 return OrthancPluginErrorCode_StorageAreaPlugin; |
115 } | |
116 | |
117 return OrthancPluginErrorCode_Success; | |
118 } | |
119 | |
120 | |
78 | 121 static OrthancPluginErrorCode StorageReadRange(IStorage* storage, |
77 | 122 LogErrorFunction logErrorFunction, |
123 OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the range. The memory buffer is allocated and freed by Orthanc. The length of the range of interest corresponds to the size of this buffer. | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
124 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
125 OrthancPluginContentType type, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
126 uint64_t rangeStart) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
127 { |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
128 assert(!cryptoEnabled); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
129 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
130 try |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
131 { |
78 | 132 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": reading range of attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
77 | 133 |
78 | 134 std::unique_ptr<IStorage::IReader> reader(storage->GetReaderForObject(uuid, type, cryptoEnabled)); |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
135 reader->ReadRange(reinterpret_cast<char*>(target->data), target->size, rangeStart); |
77 | 136 |
137 return OrthancPluginErrorCode_Success; | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
138 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
139 catch (StoragePluginException& ex) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
140 { |
77 | 141 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + std::string(ex.what())); |
142 return OrthancPluginErrorCode_StorageAreaPlugin; | |
143 } | |
144 } | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
145 |
77 | 146 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the range. The memory buffer is allocated and freed by Orthanc. The length of the range of interest corresponds to the size of this buffer. |
147 const char* uuid, | |
148 OrthancPluginContentType type, | |
149 uint64_t rangeStart) | |
150 { | |
78 | 151 OrthancPluginErrorCode res = StorageReadRange(primaryStorage.get(), |
77 | 152 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try |
153 target, | |
154 uuid, | |
155 type, | |
156 rangeStart); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
157 |
77 | 158 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) |
159 { | |
78 | 160 res = StorageReadRange(secondaryStorage.get(), |
77 | 161 OrthancPlugins::LogError, // log errors as errors on second try |
162 target, | |
163 uuid, | |
164 type, | |
165 rangeStart); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
166 } |
77 | 167 return res; |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
168 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
169 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
170 |
77 | 171 |
78 | 172 static OrthancPluginErrorCode StorageReadWhole(IStorage* storage, |
77 | 173 LogErrorFunction logErrorFunction, |
174 OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the file. It must be allocated by the plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it. | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
175 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
176 OrthancPluginContentType type) |
1 | 177 { |
178 try | |
179 { | |
78 | 180 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": reading whole attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
181 std::unique_ptr<IStorage::IReader> reader(storage->GetReaderForObject(uuid, type, cryptoEnabled)); | |
1 | 182 |
183 size_t fileSize = reader->GetSize(); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
184 size_t size; |
1 | 185 |
186 if (cryptoEnabled) | |
187 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
188 size = fileSize - crypto->OVERHEAD_SIZE; |
1 | 189 } |
190 else | |
191 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
192 size = fileSize; |
1 | 193 } |
194 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
195 if (size <= 0) |
1 | 196 { |
78 | 197 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", size of file is too small: " + boost::lexical_cast<std::string>(fileSize) + " bytes"); |
1 | 198 return OrthancPluginErrorCode_StorageAreaPlugin; |
199 } | |
200 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
201 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, size) != OrthancPluginErrorCode_Success) |
1 | 202 { |
78 | 203 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", cannot allocate memory of size " + boost::lexical_cast<std::string>(size) + " bytes"); |
1 | 204 return OrthancPluginErrorCode_StorageAreaPlugin; |
205 } | |
206 | |
207 if (cryptoEnabled) | |
208 { | |
209 std::vector<char> encrypted(fileSize); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
210 reader->ReadWhole(encrypted.data(), fileSize); |
1 | 211 |
212 try | |
213 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
214 crypto->Decrypt(reinterpret_cast<char*>(target->data), encrypted.data(), fileSize); |
1 | 215 } |
216 catch (EncryptionException& ex) | |
217 { | |
78 | 218 logErrorFunction(storage->GetNameForLogs() + ": error while decrypting object " + std::string(uuid) + ": " + ex.what()); |
1 | 219 return OrthancPluginErrorCode_StorageAreaPlugin; |
220 } | |
221 } | |
222 else | |
223 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
224 reader->ReadWhole(reinterpret_cast<char*>(target->data), fileSize); |
1 | 225 } |
226 } | |
227 catch (StoragePluginException& ex) | |
228 { | |
78 | 229 logErrorFunction(storage->GetNameForLogs() + ": error while decrypting object " + std::string(uuid) + ": " + ex.what()); |
77 | 230 return OrthancPluginErrorCode_StorageAreaPlugin; |
1 | 231 } |
232 | |
233 return OrthancPluginErrorCode_Success; | |
234 } | |
235 | |
77 | 236 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the file. It must be allocated by the plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it. |
237 const char* uuid, | |
238 OrthancPluginContentType type) | |
239 { | |
78 | 240 OrthancPluginErrorCode res = StorageReadWhole(primaryStorage.get(), |
77 | 241 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try |
242 target, | |
243 uuid, | |
244 type); | |
245 | |
246 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) | |
247 { | |
78 | 248 res = StorageReadWhole(secondaryStorage.get(), |
77 | 249 OrthancPlugins::LogError, // log errors as errors on second try |
250 target, | |
251 uuid, | |
252 type); | |
253 } | |
254 return res; | |
255 } | |
256 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
257 static OrthancPluginErrorCode StorageReadWholeLegacy(void** content, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
258 int64_t* size, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
259 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
260 OrthancPluginContentType type) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
261 { |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
262 OrthancPluginMemoryBuffer64 buffer; |
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
263 OrthancPluginErrorCode result = StorageReadWhole(&buffer, uuid, type); // will allocate OrthancPluginMemoryBuffer64 |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
264 |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
265 if (result == OrthancPluginErrorCode_Success) |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
266 { |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
267 *size = buffer.size; |
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
268 *content = buffer.data; // orthanc will free the buffer (we don't have to delete it ourselves) |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
269 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
270 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
271 return result; |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
272 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
273 |
1 | 274 |
78 | 275 static OrthancPluginErrorCode StorageRemove(IStorage* storage, |
77 | 276 LogErrorFunction logErrorFunction, |
277 const char* uuid, | |
1 | 278 OrthancPluginContentType type) |
279 { | |
280 try | |
281 { | |
78 | 282 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": deleting attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
283 storage->DeleteObject(uuid, type, cryptoEnabled); | |
284 if ((storage == primaryStorage.get()) && IsHybridModeEnabled()) | |
77 | 285 { |
286 // not 100% sure the file has been deleted, try the secondary plugin | |
287 return OrthancPluginErrorCode_StorageAreaPlugin; | |
288 } | |
289 | |
290 return OrthancPluginErrorCode_Success; | |
1 | 291 } |
292 catch (StoragePluginException& ex) | |
293 { | |
77 | 294 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + std::string(ex.what())); |
295 return OrthancPluginErrorCode_StorageAreaPlugin; | |
296 } | |
297 } | |
15 | 298 |
77 | 299 static OrthancPluginErrorCode StorageRemove(const char* uuid, |
300 OrthancPluginContentType type) | |
301 { | |
78 | 302 OrthancPluginErrorCode res = StorageRemove(primaryStorage.get(), |
77 | 303 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try |
304 uuid, | |
305 type); | |
15 | 306 |
77 | 307 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) |
308 { | |
78 | 309 res = StorageRemove(secondaryStorage.get(), |
77 | 310 OrthancPlugins::LogError, // log errors as errors on second try |
311 uuid, | |
312 type); | |
1 | 313 } |
77 | 314 return res; |
1 | 315 } |
316 | |
317 | |
318 extern "C" | |
319 { | |
320 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
321 { | |
322 OrthancPlugins::SetGlobalContext(context); | |
323 | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
324 Orthanc::InitializeFramework("", false); |
15 | 325 Orthanc::Logging::InitializePluginContext(context); |
326 | |
1 | 327 OrthancPlugins::OrthancConfiguration orthancConfig; |
328 | |
329 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is initializing"); | |
330 | |
331 /* Check the version of the Orthanc core */ | |
332 if (OrthancPluginCheckVersion(context) == 0) | |
333 { | |
334 char info[1024]; | |
335 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
336 context->orthancVersion, | |
337 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
338 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
339 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
340 OrthancPlugins::LogError(info); | |
341 return -1; | |
342 } | |
343 | |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
344 try |
8 | 345 { |
77 | 346 const char* pluginSectionName = StoragePluginFactory::GetConfigurationSectionName(); |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
347 static const char* const ENCRYPTION_SECTION = "StorageEncryption"; |
20 | 348 |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
349 if (orthancConfig.IsSection(pluginSectionName)) |
15 | 350 { |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
351 OrthancPlugins::OrthancConfiguration pluginSection; |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
352 orthancConfig.GetSection(pluginSection, pluginSectionName); |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
353 |
77 | 354 bool migrationFromFileSystemEnabled = pluginSection.GetBooleanValue("MigrationFromFileSystemEnabled", false); |
355 std::string hybridModeString = pluginSection.GetStringValue("HybridMode", "Disabled"); | |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
356 |
77 | 357 if (migrationFromFileSystemEnabled && hybridModeString == "Disabled") |
358 { | |
359 hybridMode = HybridMode_WriteToObjectStorage; | |
360 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": 'MigrationFromFileSystemEnabled' configuration is deprecated, use 'HybridMode': 'WriteToObjectStorage' instead"); | |
361 } | |
362 else if (hybridModeString == "WriteToObjectStorage") | |
363 { | |
364 hybridMode = HybridMode_WriteToObjectStorage; | |
365 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": WriteToObjectStorage HybridMode is enabled: writing to object-storage, try reading first from object-storage and, then, from file system"); | |
366 } | |
367 else if (hybridModeString == "WriteToFileSystem") | |
368 { | |
369 hybridMode = HybridMode_WriteToFileSystem; | |
370 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": WriteToFileSystem HybridMode is enabled: writing to file system, try reading first from file system and, then, from object-storage"); | |
371 } | |
372 else | |
373 { | |
374 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode is disabled enabled: writing to object-storage and reading only from object-storage"); | |
375 } | |
376 | |
377 if (IsReadFromDisk()) | |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
378 { |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
379 fileSystemRootPath = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorageNotDefined"); |
77 | 380 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode: reading from file system is enabled, source: " + fileSystemRootPath); |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
381 } |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
382 |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
383 objectsRootPath = pluginSection.GetStringValue("RootPath", std::string()); |
33 | 384 |
385 if (objectsRootPath.size() >= 1 && objectsRootPath[0] == '/') | |
386 { | |
387 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": The RootPath shall not start with a '/': " + objectsRootPath); | |
388 return -1; | |
389 } | |
15 | 390 |
77 | 391 std::string objecstStoragePluginName = StoragePluginFactory::GetStoragePluginName(); |
392 if (hybridMode == HybridMode_WriteToFileSystem) | |
393 { | |
394 objecstStoragePluginName += " (Secondary: object-storage)"; | |
395 } | |
396 else if (hybridMode == HybridMode_WriteToObjectStorage) | |
397 { | |
398 objecstStoragePluginName += " (Primary: object-storage)"; | |
399 } | |
400 | |
78 | 401 std::unique_ptr<IStorage> objectStoragePlugin(StoragePluginFactory::CreateStorage(objecstStoragePluginName, orthancConfig)); |
77 | 402 |
403 if (objectStoragePlugin.get() == nullptr) | |
404 { | |
405 return -1; | |
406 } | |
407 | |
408 objectStoragePlugin->SetRootPath(objectsRootPath); | |
409 | |
78 | 410 std::unique_ptr<IStorage> fileSystemStoragePlugin; |
77 | 411 if (IsHybridModeEnabled()) |
412 { | |
413 bool fsync = orthancConfig.GetBooleanValue("SyncStorageArea", true); | |
414 | |
415 std::string filesystemStoragePluginName = StoragePluginFactory::GetStoragePluginName(); | |
416 if (hybridMode == HybridMode_WriteToFileSystem) | |
417 { | |
418 filesystemStoragePluginName += " (Primary: file-system)"; | |
419 } | |
420 else if (hybridMode == HybridMode_WriteToObjectStorage) | |
421 { | |
422 filesystemStoragePluginName += " (Secondary: file-system)"; | |
423 } | |
424 | |
425 fileSystemStoragePlugin.reset(new FileSystemStoragePlugin(filesystemStoragePluginName, fileSystemRootPath, fsync)); | |
426 } | |
427 | |
428 if (hybridMode == HybridMode_Disabled || hybridMode == HybridMode_WriteToObjectStorage) | |
429 { | |
78 | 430 primaryStorage.reset(objectStoragePlugin.release()); |
77 | 431 |
432 if (hybridMode == HybridMode_WriteToObjectStorage) | |
433 { | |
78 | 434 secondaryStorage.reset(fileSystemStoragePlugin.release()); |
77 | 435 } |
436 } | |
437 else if (hybridMode == HybridMode_WriteToFileSystem) | |
438 { | |
78 | 439 primaryStorage.reset(fileSystemStoragePlugin.release()); |
440 secondaryStorage.reset(objectStoragePlugin.release()); | |
77 | 441 } |
15 | 442 |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
443 if (pluginSection.IsSection(ENCRYPTION_SECTION)) |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
444 { |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
445 OrthancPlugins::OrthancConfiguration cryptoSection; |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
446 pluginSection.GetSection(cryptoSection, ENCRYPTION_SECTION); |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
447 |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
448 crypto.reset(EncryptionConfigurator::CreateEncryptionHelpers(cryptoSection)); |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
449 cryptoEnabled = crypto.get() != nullptr; |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
450 } |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
451 |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
452 if (cryptoEnabled) |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
453 { |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
454 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is enabled"); |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
455 } |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
456 else |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
457 { |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
458 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is disabled"); |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
459 } |
77 | 460 |
461 | |
15 | 462 } |
463 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
464 if (cryptoEnabled) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
465 { |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
466 // with encrypted file, we do not want to support ReadRange. Therefore, we register the old interface |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
467 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageReadWholeLegacy, StorageRemove); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
468 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
469 else |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
470 { |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
471 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
472 } |
1 | 473 } |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
474 catch (Orthanc::OrthancException& e) |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
475 { |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
476 LOG(ERROR) << "Exception while creating the object storage plugin: " << e.What(); |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
477 return -1; |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
478 } |
1 | 479 |
480 return 0; | |
481 } | |
482 | |
483 | |
484 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
485 { | |
486 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is finalizing"); | |
78 | 487 primaryStorage.reset(); |
488 secondaryStorage.reset(); | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
489 Orthanc::FinalizeFramework(); |
1 | 490 } |
491 | |
492 | |
493 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
494 { | |
495 return StoragePluginFactory::GetStoragePluginName(); | |
496 } | |
497 | |
498 | |
499 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
500 { | |
501 return PLUGIN_VERSION; | |
502 } | |
503 } | |
504 |