annotate Azure/AzureBlobStoragePlugin.cpp @ 148:c02a830ae308

try
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 Jun 2024 18:52:57 +0200
parents 3c7e0374f28e
children d62f52be1943
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
1 /**
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
2 * Cloud storage plugins for Orthanc
145
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 111
diff changeset
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 111
diff changeset
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 111
diff changeset
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
6 *
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
10 * the License, or (at your option) any later version.
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
11 *
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
15 * Affero General Public License for more details.
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
16 *
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
19 **/
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
20
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 48
diff changeset
21
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
22 #include "AzureBlobStoragePlugin.h"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
23
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
24 #include <azure/storage/blobs.hpp>
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
25 #include <boost/lexical_cast.hpp>
12
a203d0a4fd8f Azure: now removing spaces and CR at the end of the connectionString since it prevented the plugin to initialize.
Alain Mazy
parents: 11
diff changeset
26 #include <boost/algorithm/string.hpp>
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
27 // #include "cpprest/rawptrstream.h"
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
28 // #include "cpprest/details/basic_types.h"
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
29
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
30 // Create aliases to make the code easier to read.
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
31 namespace as = Azure::Storage::Blobs;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
32
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
33 class AzureBlobStoragePlugin : public BaseStorage
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
34 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
35 public:
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
36
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
37 as::BlobContainerClient blobClient_;
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
38 bool storageContainsUnknownFiles_;
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
39
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
40 public:
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
41
79
Alain Mazy <am@osimis.io>
parents: 78
diff changeset
42 AzureBlobStoragePlugin(const std::string& nameForLogs,
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
43 const as::BlobContainerClient& blobClient,
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
44 bool enableLegacyStorageStructure,
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
45 bool storageContainsUnknownFiles
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
46 );
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
47
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
48 virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
49 virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
50 virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
111
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 99
diff changeset
51 virtual bool HasFileExists() {return false;};
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
52 };
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
53
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
54
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
55 class Writer : public IStorage::IWriter
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
56 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
57 std::string path_;
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
58 as::BlobContainerClient client_;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
59
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
60 public:
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
61 Writer(const std::string& path, const as::BlobContainerClient& client)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
62 : path_(path),
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
63 client_(client)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
64 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
65 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
66
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
67 virtual ~Writer()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
68 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
69 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
70
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
71 virtual void Write(const char* data, size_t size)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
72 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
73 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
74 {
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
75 as::BlockBlobClient blobClient = client_.GetBlockBlobClient(path_);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
76 blobClient.UploadFrom(reinterpret_cast<const uint8_t*>(data), size);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
77 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
78 catch (std::exception& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
79 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
80 throw StoragePluginException("AzureBlobStorage: error writing file " + std::string(path_) + ": " + ex.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
81 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
82 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
83 };
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
84
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
85
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
86 class Reader : public IStorage::IReader
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
87 {
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
88 std::string path_;
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
89 as::BlobContainerClient client_;
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
90 int64_t size_;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
91
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
92 public:
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
93 Reader(const std::list<std::string>& paths, const as::BlobContainerClient& client)
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
94 : client_(client)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
95 {
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
96 std::string firstExceptionMessage;
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
97
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
98 for (auto& path: paths)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
99 {
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
100 try
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
101 {
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
102 as::BlockBlobClient blobClient = client_.GetBlockBlobClient(path);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
103 auto properties = blobClient.GetProperties().Value;
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
104 size_ = properties.BlobSize;
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
105 path_ = path;
71
Alain Mazy <am@osimis.io>
parents: 70
diff changeset
106 return;
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
107 }
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
108 catch (std::exception& ex)
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
109 {
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
110 if (firstExceptionMessage.empty())
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
111 {
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
112 firstExceptionMessage = "AzureBlobStorage: error opening file for reading " + std::string(path) + ": " + ex.what();
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
113 }
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
114 //ignore to retry
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
115 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
116 }
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
117 throw StoragePluginException(firstExceptionMessage);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
118 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
119
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
120 virtual ~Reader()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
121 {
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
122 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
123
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
124 virtual size_t GetSize()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
125 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
126 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
127 {
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
128 return static_cast<size_t>(size_);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
129 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
130 catch (std::exception& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
131 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
132 throw StoragePluginException("AzureBlobStorage: error while reading file " + std::string(path_) + ": " + ex.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
133 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
134 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
135
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
136 virtual void ReadWhole(char* data, size_t size)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
137 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
138 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
139 {
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
140 as::BlockBlobClient blobClient = client_.GetBlockBlobClient(path_);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
141 blobClient.DownloadTo(reinterpret_cast<uint8_t*>(data), static_cast<int64_t>(size));
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
142 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
143 catch (std::exception& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
144 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
145 throw StoragePluginException("AzureBlobStorage: error while reading file " + std::string(path_) + ": " + ex.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
146 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
147 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
148
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
149 virtual void ReadRange(char* data, size_t size, size_t fromOffset)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
150 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
151 try
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
152 {
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
153 as::BlockBlobClient blobClient = client_.GetBlockBlobClient(path_);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
154 as::DownloadBlobToOptions options;
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
155 options.Range = Azure::Core::Http::HttpRange();
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
156 options.Range.Value().Length = static_cast<int64_t>(size);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
157 options.Range.Value().Offset = static_cast<int64_t>(fromOffset);
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
158
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
159 blobClient.DownloadTo(reinterpret_cast<uint8_t*>(data), static_cast<int64_t>(size), options);
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
160 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
161 catch (std::exception& ex)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
162 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
163 throw StoragePluginException("AzureBlobStorage: error while reading partial file " + std::string(path_) + ": " + ex.what());
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
164 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
165 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
166 };
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
167
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
168
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
169
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
170 const char* AzureBlobStoragePluginFactory::GetStoragePluginName()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
171 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
172 return "Azure Blob Storage";
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
173 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
174
94
1bc055199cd2 Added a description for all plugins
Alain Mazy <am@osimis.io>
parents: 92
diff changeset
175 const char* AzureBlobStoragePluginFactory::GetStorageDescription()
1bc055199cd2 Added a description for all plugins
Alain Mazy <am@osimis.io>
parents: 92
diff changeset
176 {
1bc055199cd2 Added a description for all plugins
Alain Mazy <am@osimis.io>
parents: 92
diff changeset
177 return "Stores the Orthanc storage area in Azure Blob";
1bc055199cd2 Added a description for all plugins
Alain Mazy <am@osimis.io>
parents: 92
diff changeset
178 }
1bc055199cd2 Added a description for all plugins
Alain Mazy <am@osimis.io>
parents: 92
diff changeset
179
1bc055199cd2 Added a description for all plugins
Alain Mazy <am@osimis.io>
parents: 92
diff changeset
180
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
181 // bool IsSasTokenAccountLevel(utility::string_t sasToken)
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
182 // {
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
183 // // Use cpprestsdk's utility::string_t here since the expected argument is the return value of
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
184 // // as::storage_credentials::sas_token(), which is type utility::string_t (which is a std::wstring on Windows and a std::string on Linux)
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
185 // size_t newIdx = 0;
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
186 // size_t prevIdx = 0;
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
187 // while ((newIdx = sasToken.find('&', prevIdx)) != utility::string_t::npos)
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
188 // {
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
189 // utility::string_t kvpair = sasToken.substr(prevIdx, newIdx - prevIdx);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
190 // prevIdx = newIdx + 1; // start next time from char after '&'
46
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
191
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
192 // size_t equalsIdx = kvpair.find('=');
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
193 // utility::string_t key = kvpair.substr(0, equalsIdx);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
194 // #ifdef WIN32
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
195 // const wchar_t* srt = L"srt";
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
196 // #else
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
197 // const char* srt = "srt";
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
198 // #endif
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
199 // if (key == srt) // only account SAS has this parameter
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
200 // return true;
89
62752402edbb azure build for Windows platform
Alain Mazy <alain@mazy.be>
parents: 81
diff changeset
201
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
202 // }
46
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
203
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
204 // return false;
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
205 // }
46
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
206
79
Alain Mazy <am@osimis.io>
parents: 78
diff changeset
207 IStorage* AzureBlobStoragePluginFactory::CreateStorage(const std::string& nameForLogs, const OrthancPlugins::OrthancConfiguration& orthancConfig)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
208 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
209 std::string connectionString;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
210 std::string containerName;
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 12
diff changeset
211 bool enableLegacyStorageStructure;
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
212 bool storageContainsUnknownFiles;
46
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
213 bool createContainerIfNotExists;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
214
81
Alain Mazy <am@osimis.io>
parents: 80
diff changeset
215 if (orthancConfig.IsSection(GetConfigurationSectionName()))
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
216 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
217 OrthancPlugins::OrthancConfiguration pluginSection;
81
Alain Mazy <am@osimis.io>
parents: 80
diff changeset
218 orthancConfig.GetSection(pluginSection, GetConfigurationSectionName());
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
219
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
220 if (!BaseStorage::ReadCommonConfiguration(enableLegacyStorageStructure, storageContainsUnknownFiles, pluginSection))
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 12
diff changeset
221 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 12
diff changeset
222 return nullptr;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 12
diff changeset
223 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 12
diff changeset
224
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
225 if (!pluginSection.LookupStringValue(connectionString, "ConnectionString"))
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
226 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
227 OrthancPlugins::LogError("AzureBlobStorage/ConnectionString configuration missing. Unable to initialize plugin");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
228 return nullptr;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
229 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
230
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
231 if (!pluginSection.LookupStringValue(containerName, "ContainerName"))
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
232 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
233 OrthancPlugins::LogError("AzureBlobStorage/ContainerName configuration missing. Unable to initialize plugin");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
234 return nullptr;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
235 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
236
12
a203d0a4fd8f Azure: now removing spaces and CR at the end of the connectionString since it prevented the plugin to initialize.
Alain Mazy
parents: 11
diff changeset
237 boost::trim(connectionString); // without that, if there's an EOL in the string, it fails with "provided uri is invalid"
a203d0a4fd8f Azure: now removing spaces and CR at the end of the connectionString since it prevented the plugin to initialize.
Alain Mazy
parents: 11
diff changeset
238 boost::trim(containerName);
46
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
239
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
240 createContainerIfNotExists = pluginSection.GetBooleanValue("CreateContainerIfNotExists", true);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
241 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
242 else if (orthancConfig.IsSection("BlobStorage")) // backward compatibility with the old plugin:
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
243 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
244 OrthancPlugins::LogWarning("AzureBlobStorage: you're using an old configuration format for the plugin.");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
245
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
246 OrthancPlugins::OrthancConfiguration pluginSection;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
247 orthancConfig.GetSection(pluginSection, "BlobStorage");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
248
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
249 std::string accountName;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
250 std::string accountKey;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
251
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
252 if (!pluginSection.LookupStringValue(containerName, "ContainerName"))
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
253 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
254 OrthancPlugins::LogError("BlobStorage/AccountName configuration missing. Unable to initialize plugin");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
255 return nullptr;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
256 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
257
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
258 if (!pluginSection.LookupStringValue(accountName, "AccountName"))
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
259 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
260 OrthancPlugins::LogError("BlobStorage/AccountName configuration missing. Unable to initialize plugin");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
261 return nullptr;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
262 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
263
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
264 if (!pluginSection.LookupStringValue(accountKey, "AccountKey"))
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
265 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
266 OrthancPlugins::LogError("BlobStorage/ContainerName configuration missing. Unable to initialize plugin");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
267 return nullptr;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
268 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
269
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
270 std::ostringstream connectionStringBuilder;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
271 connectionStringBuilder << "DefaultEndpointsProtocol=https;AccountName=" << accountName << ";AccountKey=" << accountKey;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
272 connectionString = connectionStringBuilder.str();
46
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
273
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
274 createContainerIfNotExists = pluginSection.GetBooleanValue("CreateContainerIfNotExists", true);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
275 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
276 else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
277 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
278 OrthancPlugins::LogWarning(std::string(GetStoragePluginName()) + " plugin, section missing. Plugin is not enabled.");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
279 return nullptr;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
280 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
281
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
282 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
283 {
11
1b85dc5eb372 more logs for azure plugin
Alain Mazy
parents: 1
diff changeset
284 OrthancPlugins::LogInfo("Connecting to Azure storage ...");
1b85dc5eb372 more logs for azure plugin
Alain Mazy
parents: 1
diff changeset
285
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
286 as::BlobContainerClient client = as::BlobContainerClient::CreateFromConnectionString(connectionString, containerName);
11
1b85dc5eb372 more logs for azure plugin
Alain Mazy
parents: 1
diff changeset
287 OrthancPlugins::LogInfo("Blob client created");
1b85dc5eb372 more logs for azure plugin
Alain Mazy
parents: 1
diff changeset
288
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
289 if (createContainerIfNotExists)
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
290 {
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
291 // Note: in version up to 2.1.2, we had this code:
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
292 // // blobContainer.create_if_not_exists() throws an error if a service SAS (for a blob container)
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
293 // // was used in the connectionString.
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
294 // // Only allow the use of this function when using storage account-level credentials, whether
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
295 // // through accountName/accountKey combo or account SAS.
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
296 // if ((storageAccount.credentials().is_account_key() ||
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
297 // (storageAccount.credentials().is_sas() && IsSasTokenAccountLevel(storageAccount.credentials().sas_token())))
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
298 // && createContainerIfNotExists)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
299
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
300 auto createResult = client.CreateIfNotExists();
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
301 if (createResult.Value.Created)
46
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
302 {
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
303 OrthancPlugins::LogWarning("Blob Storage Area container has been created. **** check in the Azure console that your container is private ****");
3b8fab63313d Add "CreateContainerIfNotExists" config for Azure
Mark Poscablo <Mark.Poscablo@varian.com>
parents: 15
diff changeset
304 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
305 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
306
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
307 OrthancPlugins::LogInfo("Blob storage initialized");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
308
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
309 return new AzureBlobStoragePlugin(nameForLogs, client, enableLegacyStorageStructure, storageContainsUnknownFiles);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
310 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
311 catch (const std::exception& e)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
312 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
313 OrthancPlugins::LogError(std::string("AzureBlobStorage plugin: failed to initialize plugin: ") + e.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
314 return nullptr;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
315 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
316
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
317 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
318
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
319 AzureBlobStoragePlugin::AzureBlobStoragePlugin(const std::string& nameForLogs, const as::BlobContainerClient& blobClient, bool enableLegacyStorageStructure, bool storageContainsUnknownFiles)
79
Alain Mazy <am@osimis.io>
parents: 78
diff changeset
320 : BaseStorage(nameForLogs, enableLegacyStorageStructure),
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 12
diff changeset
321 blobClient_(blobClient),
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
322 storageContainsUnknownFiles_(storageContainsUnknownFiles)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
323 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
324
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
325 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
326
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
327 IStorage::IWriter* AzureBlobStoragePlugin::GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
328 {
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
329 return new Writer(GetPath(uuid, type, encryptionEnabled), blobClient_);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
330 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
331
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
332 IStorage::IReader* AzureBlobStoragePlugin::GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
333 {
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
334 std::list<std::string> paths;
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
335 paths.push_back(GetPath(uuid, type, encryptionEnabled, false));
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
336 if (storageContainsUnknownFiles_)
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
337 {
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
338 paths.push_back(GetPath(uuid, type, encryptionEnabled, true));
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
339 }
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
340
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
341 return new Reader(paths, blobClient_);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
342 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
343
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
344 void AzureBlobStoragePlugin::DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
345 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
346 std::string path = GetPath(uuid, type, encryptionEnabled);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
347
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
348 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
349 {
99
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
350 as::BlockBlobClient blobClient = blobClient_.GetBlockBlobClient(path);
f4e05641c108 rewrote using the latest azure C++ sdk
Alain Mazy <am@osimis.io>
parents: 94
diff changeset
351 blobClient.Delete();
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
352 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
353 catch (std::exception& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
354 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
355 throw StoragePluginException("AzureBlobStorage: error while deleting file " + std::string(path) + ": " + ex.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
356 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
357 }