Mercurial > hg > orthanc-object-storage
diff Aws/AwsS3StoragePlugin.cpp @ 15:2a02b21f0a19
migration + storage structure
author | Alain Mazy |
---|---|
date | Tue, 01 Sep 2020 13:08:49 +0200 |
parents | 393fcf337462 |
children | e1f52b851827 8d2b29fd4de5 |
line wrap: on
line diff
--- a/Aws/AwsS3StoragePlugin.cpp Wed Aug 26 12:52:37 2020 +0200 +++ b/Aws/AwsS3StoragePlugin.cpp Tue Sep 01 13:08:49 2020 +0200 @@ -32,8 +32,9 @@ #include <fstream> const char* ALLOCATION_TAG = "OrthancS3"; +static const char* const PLUGIN_SECTION = "AwsS3Storage"; -class AwsS3StoragePlugin : public IStoragePlugin +class AwsS3StoragePlugin : public BaseStoragePlugin { public: @@ -42,13 +43,12 @@ public: - AwsS3StoragePlugin(const Aws::S3::S3Client& client, const std::string& bucketName); + AwsS3StoragePlugin(const Aws::S3::S3Client& client, const std::string& bucketName, bool enableLegacyStorageStructure); virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); -private: - virtual std::string GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); + virtual const char* GetConfigurationSectionName() {return PLUGIN_SECTION;}; }; @@ -178,7 +178,8 @@ IStoragePlugin* AwsS3StoragePluginFactory::CreateStoragePlugin(const OrthancPlugins::OrthancConfiguration& orthancConfig) { - static const char* const PLUGIN_SECTION = "AwsS3Storage"; + bool enableLegacyStorageStructure; + if (!orthancConfig.IsSection(PLUGIN_SECTION)) { OrthancPlugins::LogWarning(std::string(GetStoragePluginName()) + " plugin, section missing. Plugin is not enabled."); @@ -188,6 +189,11 @@ OrthancPlugins::OrthancConfiguration pluginSection; orthancConfig.GetSection(pluginSection, PLUGIN_SECTION); + if (!BaseStoragePlugin::ReadCommonConfiguration(enableLegacyStorageStructure, pluginSection)) + { + return nullptr; + } + std::string bucketName; std::string region; std::string accessKey; @@ -242,7 +248,7 @@ OrthancPlugins::LogInfo("AWS S3 storage initialized"); - return new AwsS3StoragePlugin(client, bucketName); + return new AwsS3StoragePlugin(client, bucketName, enableLegacyStorageStructure); } catch (const std::exception& e) { @@ -252,8 +258,9 @@ } -AwsS3StoragePlugin::AwsS3StoragePlugin(const Aws::S3::S3Client& client, const std::string& bucketName) - : client_(client), +AwsS3StoragePlugin::AwsS3StoragePlugin(const Aws::S3::S3Client& client, const std::string& bucketName, bool enableLegacyStorageStructure) + : BaseStoragePlugin(enableLegacyStorageStructure), + client_(client), bucketName_(bucketName) { @@ -285,27 +292,3 @@ } } - -std::string AwsS3StoragePlugin::GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) -{ - std::string path = std::string(uuid); - - if (type == OrthancPluginContentType_Dicom) - { - path += ".dcm"; - } - else if (type == OrthancPluginContentType_DicomAsJson) - { - path += ".json"; - } - else - { - path += ".unk"; - } - - if (encryptionEnabled) - { - path += ".enc"; - } - return path; -}