Mercurial > hg > orthanc-object-storage
comparison Google/GoogleStoragePlugin.cpp @ 15:2a02b21f0a19
migration + storage structure
author | Alain Mazy |
---|---|
date | Tue, 01 Sep 2020 13:08:49 +0200 |
parents | fc26a8fc54d5 |
children | f55b2afdf53d |
comparison
equal
deleted
inserted
replaced
14:234946ea2038 | 15:2a02b21f0a19 |
---|---|
20 | 20 |
21 #include "google/cloud/storage/client.h" | 21 #include "google/cloud/storage/client.h" |
22 | 22 |
23 // Create aliases to make the code easier to read. | 23 // Create aliases to make the code easier to read. |
24 namespace gcs = google::cloud::storage; | 24 namespace gcs = google::cloud::storage; |
25 static const char* const PLUGIN_SECTION = "GoogleCloudStorage"; | |
26 | |
27 const char* GoogleStoragePlugin::GetConfigurationSectionName() | |
28 { | |
29 return PLUGIN_SECTION; | |
30 } | |
25 | 31 |
26 class Writer : public IStoragePlugin::IWriter | 32 class Writer : public IStoragePlugin::IWriter |
27 { | 33 { |
28 std::string path_; | 34 std::string path_; |
29 gcs::Client client_; | 35 gcs::Client client_; |
123 return "Google Cloud Storage"; | 129 return "Google Cloud Storage"; |
124 } | 130 } |
125 | 131 |
126 IStoragePlugin* GoogleStoragePluginFactory::CreateStoragePlugin(const OrthancPlugins::OrthancConfiguration& orthancConfig) | 132 IStoragePlugin* GoogleStoragePluginFactory::CreateStoragePlugin(const OrthancPlugins::OrthancConfiguration& orthancConfig) |
127 { | 133 { |
128 static const char* const PLUGIN_SECTION = "GoogleCloudStorage"; | 134 bool enableLegacyStorageStructure; |
135 | |
129 if (!orthancConfig.IsSection(PLUGIN_SECTION)) | 136 if (!orthancConfig.IsSection(PLUGIN_SECTION)) |
130 { | 137 { |
131 OrthancPlugins::LogWarning(std::string(GetStoragePluginName()) + " plugin, section missing. Plugin is not enabled."); | 138 OrthancPlugins::LogWarning(std::string(GetStoragePluginName()) + " plugin, section missing. Plugin is not enabled."); |
132 return nullptr; | 139 return nullptr; |
133 } | 140 } |
134 | 141 |
135 OrthancPlugins::OrthancConfiguration pluginSection; | 142 OrthancPlugins::OrthancConfiguration pluginSection; |
136 orthancConfig.GetSection(pluginSection, PLUGIN_SECTION); | 143 orthancConfig.GetSection(pluginSection, PLUGIN_SECTION); |
144 | |
145 if (!BaseStoragePlugin::ReadCommonConfiguration(enableLegacyStorageStructure, pluginSection)) | |
146 { | |
147 return nullptr; | |
148 } | |
137 | 149 |
138 std::string pathToGoogleCredentials; | 150 std::string pathToGoogleCredentials; |
139 | 151 |
140 if (!pluginSection.LookupStringValue(pathToGoogleCredentials, "ServiceAccountFile")) | 152 if (!pluginSection.LookupStringValue(pathToGoogleCredentials, "ServiceAccountFile")) |
141 { | 153 { |
165 { | 177 { |
166 OrthancPlugins::LogError("GoogleCloudStorage plugin: unable to create client: " + mainClient.status().message()); | 178 OrthancPlugins::LogError("GoogleCloudStorage plugin: unable to create client: " + mainClient.status().message()); |
167 return nullptr; | 179 return nullptr; |
168 } | 180 } |
169 | 181 |
170 return new GoogleStoragePlugin(googleBucketName, mainClient.value()); | 182 return new GoogleStoragePlugin(googleBucketName, mainClient.value(), enableLegacyStorageStructure); |
171 } | 183 } |
172 | 184 |
173 GoogleStoragePlugin::GoogleStoragePlugin(const std::string &bucketName, google::cloud::storage::Client& mainClient) | 185 GoogleStoragePlugin::GoogleStoragePlugin(const std::string &bucketName, google::cloud::storage::Client& mainClient, bool enableLegacyStorageStructure) |
174 : bucketName_(bucketName), | 186 : BaseStoragePlugin(enableLegacyStorageStructure), |
187 bucketName_(bucketName), | |
175 mainClient_(mainClient) | 188 mainClient_(mainClient) |
176 { | 189 { |
177 | 190 |
178 } | 191 } |
179 | 192 |
199 { | 212 { |
200 throw StoragePluginException("GoogleCloudStorage: error while deleting file " + std::string(path) + ": " + deletionStatus.message()); | 213 throw StoragePluginException("GoogleCloudStorage: error while deleting file " + std::string(path) + ": " + deletionStatus.message()); |
201 } | 214 } |
202 | 215 |
203 } | 216 } |
204 | |
205 std::string GoogleStoragePlugin::GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) | |
206 { | |
207 std::string path = std::string(uuid); | |
208 | |
209 if (type == OrthancPluginContentType_Dicom) | |
210 { | |
211 path += ".dcm"; | |
212 } | |
213 else if (type == OrthancPluginContentType_DicomAsJson) | |
214 { | |
215 path += ".json"; | |
216 } | |
217 else | |
218 { | |
219 path += ".unk"; | |
220 } | |
221 | |
222 if (encryptionEnabled) | |
223 { | |
224 path += ".enc"; | |
225 } | |
226 return path; | |
227 } |