diff Aws/AwsS3StoragePlugin.cpp @ 70:16e419fe80c5

Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
author Alain Mazy <am@osimis.io>
date Mon, 06 Sep 2021 14:21:56 +0200
parents 58a03fce4897
children a25b4140e7e4
line wrap: on
line diff
--- a/Aws/AwsS3StoragePlugin.cpp	Fri Jul 09 15:40:07 2021 +0200
+++ b/Aws/AwsS3StoragePlugin.cpp	Mon Sep 06 14:21:56 2021 +0200
@@ -120,35 +120,6 @@
 
   }
 
-  size_t _GetSize(const std::string& path)
-  {
-    Aws::S3::Model::ListObjectsRequest listObjectRequest;
-    listObjectRequest.SetBucket(bucketName_.c_str());
-    listObjectRequest.SetPrefix(path.c_str());
-
-    auto result = client_.ListObjects(listObjectRequest);
-
-    if (result.IsSuccess())
-    {
-      Aws::Vector<Aws::S3::Model::Object> objectList =
-          result.GetResult().GetContents();
-
-      if (objectList.size() == 1)
-      {
-        return objectList[0].GetSize();
-      }
-      else if (objectList.size() > 1)
-      {
-        throw StoragePluginException(std::string("error while reading file ") + path + ": multiple objet with same name !");
-      }
-      throw StoragePluginException(std::string("error while reading file ") + path + ": object not found !");
-    }
-    else
-    {
-      throw StoragePluginException(std::string("error while reading file ") + path + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str());
-    }
-  }
-
   virtual size_t GetSize()
   {
     std::string firstExceptionMessage;
@@ -181,6 +152,38 @@
     _Read(data, size, fromOffset, true);
   }
 
+private:
+
+  size_t _GetSize(const std::string& path)
+  {
+    Aws::S3::Model::ListObjectsRequest listObjectRequest;
+    listObjectRequest.SetBucket(bucketName_.c_str());
+    listObjectRequest.SetPrefix(path.c_str());
+
+    auto result = client_.ListObjects(listObjectRequest);
+
+    if (result.IsSuccess())
+    {
+      Aws::Vector<Aws::S3::Model::Object> objectList =
+          result.GetResult().GetContents();
+
+      if (objectList.size() == 1)
+      {
+        return objectList[0].GetSize();
+      }
+      else if (objectList.size() > 1)
+      {
+        throw StoragePluginException(std::string("error while reading file ") + path + ": multiple objet with same name !");
+      }
+      throw StoragePluginException(std::string("error while reading file ") + path + ": object not found !");
+    }
+    else
+    {
+      throw StoragePluginException(std::string("error while reading file ") + path + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str());
+    }
+  }
+
+
   void _Read(char* data, size_t size, size_t fromOffset, bool useRange)
   {
     std::string firstExceptionMessage;
@@ -271,6 +274,7 @@
   Aws::InitAPI(*sdkOptions_);
 
   bool enableLegacyStorageStructure;
+  bool storageContainsUnknownFiles;
 
   if (!orthancConfig.IsSection(PLUGIN_SECTION))
   {
@@ -281,7 +285,7 @@
   OrthancPlugins::OrthancConfiguration pluginSection;
   orthancConfig.GetSection(pluginSection, PLUGIN_SECTION);
 
-  if (!BaseStoragePlugin::ReadCommonConfiguration(enableLegacyStorageStructure, pluginSection))
+  if (!BaseStoragePlugin::ReadCommonConfiguration(enableLegacyStorageStructure, storageContainsUnknownFiles, pluginSection))
   {
     return nullptr;
   }
@@ -307,7 +311,6 @@
   const unsigned int connectTimeout = pluginSection.GetUnsignedIntegerValue("ConnectTimeout", 30);
   const unsigned int requestTimeout = pluginSection.GetUnsignedIntegerValue("RequestTimeout", 1200);
   const bool virtualAddressing = pluginSection.GetBooleanValue("VirtualAddressing", true);
-  const bool storageContainsUnknownFiles = pluginSection.GetBooleanValue("EnableLegacyUnknownFiles", false);
   const std::string caFile = orthancConfig.GetStringValue("HttpsCACertificates", "");
   
   try