comparison Common/StoragePlugin.cpp @ 95:33790e0000bb

Plugins are now disabled if their section is missing in the configuration file.
author Alain Mazy <am@osimis.io>
date Mon, 19 Dec 2022 09:58:23 +0100
parents 1bc055199cd2
children 91aeaecf7100
comparison
equal deleted inserted replaced
94:1bc055199cd2 95:33790e0000bb
545 try 545 try
546 { 546 {
547 const char* pluginSectionName = StoragePluginFactory::GetConfigurationSectionName(); 547 const char* pluginSectionName = StoragePluginFactory::GetConfigurationSectionName();
548 static const char* const ENCRYPTION_SECTION = "StorageEncryption"; 548 static const char* const ENCRYPTION_SECTION = "StorageEncryption";
549 549
550 if (orthancConfig.IsSection(pluginSectionName)) 550 if (!orthancConfig.IsSection(pluginSectionName))
551 { 551 {
552 OrthancPlugins::OrthancConfiguration pluginSection; 552 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": no \"" + pluginSectionName + "\" section found in configuration, plugin is disabled");
553 orthancConfig.GetSection(pluginSection, pluginSectionName); 553 return 0;
554 554 }
555 bool migrationFromFileSystemEnabled = pluginSection.GetBooleanValue("MigrationFromFileSystemEnabled", false); 555
556 std::string hybridModeString = pluginSection.GetStringValue("HybridMode", "Disabled"); 556 OrthancPlugins::OrthancConfiguration pluginSection;
557 557 orthancConfig.GetSection(pluginSection, pluginSectionName);
558 if (migrationFromFileSystemEnabled && hybridModeString == "Disabled") 558
559 { 559 bool migrationFromFileSystemEnabled = pluginSection.GetBooleanValue("MigrationFromFileSystemEnabled", false);
560 hybridMode = HybridMode_WriteToObjectStorage; 560 std::string hybridModeString = pluginSection.GetStringValue("HybridMode", "Disabled");
561 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": 'MigrationFromFileSystemEnabled' configuration is deprecated, use 'HybridMode': 'WriteToObjectStorage' instead"); 561
562 } 562 if (migrationFromFileSystemEnabled && hybridModeString == "Disabled")
563 else if (hybridModeString == "WriteToObjectStorage") 563 {
564 { 564 hybridMode = HybridMode_WriteToObjectStorage;
565 hybridMode = HybridMode_WriteToObjectStorage; 565 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": 'MigrationFromFileSystemEnabled' configuration is deprecated, use 'HybridMode': 'WriteToObjectStorage' instead");
566 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"); 566 }
567 } 567 else if (hybridModeString == "WriteToObjectStorage")
568 else if (hybridModeString == "WriteToFileSystem") 568 {
569 { 569 hybridMode = HybridMode_WriteToObjectStorage;
570 hybridMode = HybridMode_WriteToFileSystem; 570 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");
571 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"); 571 }
572 } 572 else if (hybridModeString == "WriteToFileSystem")
573 else 573 {
574 { 574 hybridMode = HybridMode_WriteToFileSystem;
575 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode is disabled: writing to object-storage and reading only from object-storage"); 575 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");
576 } 576 }
577 577 else
578 if (IsReadFromDisk()) 578 {
579 { 579 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode is disabled: writing to object-storage and reading only from object-storage");
580 fileSystemRootPath = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorageNotDefined"); 580 }
581 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode: reading from file system is enabled, source: " + fileSystemRootPath); 581
582 } 582 if (IsReadFromDisk())
583 583 {
584 objectsRootPath = pluginSection.GetStringValue("RootPath", std::string()); 584 fileSystemRootPath = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorageNotDefined");
585 585 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode: reading from file system is enabled, source: " + fileSystemRootPath);
586 if (objectsRootPath.size() >= 1 && objectsRootPath[0] == '/') 586 }
587 { 587
588 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": The RootPath shall not start with a '/': " + objectsRootPath); 588 objectsRootPath = pluginSection.GetStringValue("RootPath", std::string());
589 return -1; 589
590 } 590 if (objectsRootPath.size() >= 1 && objectsRootPath[0] == '/')
591 591 {
592 std::string objecstStoragePluginName = StoragePluginFactory::GetStoragePluginName(); 592 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": The RootPath shall not start with a '/': " + objectsRootPath);
593 return -1;
594 }
595
596 std::string objecstStoragePluginName = StoragePluginFactory::GetStoragePluginName();
597 if (hybridMode == HybridMode_WriteToFileSystem)
598 {
599 objecstStoragePluginName += " (Secondary: object-storage)";
600 }
601 else if (hybridMode == HybridMode_WriteToObjectStorage)
602 {
603 objecstStoragePluginName += " (Primary: object-storage)";
604 }
605
606 std::unique_ptr<IStorage> objectStoragePlugin(StoragePluginFactory::CreateStorage(objecstStoragePluginName, orthancConfig));
607
608 if (objectStoragePlugin.get() == nullptr)
609 {
610 return -1;
611 }
612
613 objectStoragePlugin->SetRootPath(objectsRootPath);
614
615 std::unique_ptr<IStorage> fileSystemStoragePlugin;
616 if (IsHybridModeEnabled())
617 {
618 bool fsync = orthancConfig.GetBooleanValue("SyncStorageArea", true);
619
620 std::string filesystemStoragePluginName = StoragePluginFactory::GetStoragePluginName();
593 if (hybridMode == HybridMode_WriteToFileSystem) 621 if (hybridMode == HybridMode_WriteToFileSystem)
594 { 622 {
595 objecstStoragePluginName += " (Secondary: object-storage)"; 623 filesystemStoragePluginName += " (Primary: file-system)";
596 } 624 }
597 else if (hybridMode == HybridMode_WriteToObjectStorage) 625 else if (hybridMode == HybridMode_WriteToObjectStorage)
598 { 626 {
599 objecstStoragePluginName += " (Primary: object-storage)"; 627 filesystemStoragePluginName += " (Secondary: file-system)";
600 } 628 }
601 629
602 std::unique_ptr<IStorage> objectStoragePlugin(StoragePluginFactory::CreateStorage(objecstStoragePluginName, orthancConfig)); 630 fileSystemStoragePlugin.reset(new FileSystemStoragePlugin(filesystemStoragePluginName, fileSystemRootPath, fsync));
603 631 }
604 if (objectStoragePlugin.get() == nullptr) 632
633 if (hybridMode == HybridMode_Disabled || hybridMode == HybridMode_WriteToObjectStorage)
634 {
635 primaryStorage.reset(objectStoragePlugin.release());
636
637 if (hybridMode == HybridMode_WriteToObjectStorage)
605 { 638 {
606 return -1; 639 secondaryStorage.reset(fileSystemStoragePlugin.release());
607 } 640 }
608 641 }
609 objectStoragePlugin->SetRootPath(objectsRootPath); 642 else if (hybridMode == HybridMode_WriteToFileSystem)
610 643 {
611 std::unique_ptr<IStorage> fileSystemStoragePlugin; 644 primaryStorage.reset(fileSystemStoragePlugin.release());
612 if (IsHybridModeEnabled()) 645 secondaryStorage.reset(objectStoragePlugin.release());
613 { 646 }
614 bool fsync = orthancConfig.GetBooleanValue("SyncStorageArea", true); 647
615 648 if (pluginSection.IsSection(ENCRYPTION_SECTION))
616 std::string filesystemStoragePluginName = StoragePluginFactory::GetStoragePluginName(); 649 {
617 if (hybridMode == HybridMode_WriteToFileSystem) 650 OrthancPlugins::OrthancConfiguration cryptoSection;
618 { 651 pluginSection.GetSection(cryptoSection, ENCRYPTION_SECTION);
619 filesystemStoragePluginName += " (Primary: file-system)"; 652
620 } 653 crypto.reset(EncryptionConfigurator::CreateEncryptionHelpers(cryptoSection));
621 else if (hybridMode == HybridMode_WriteToObjectStorage) 654 cryptoEnabled = crypto.get() != nullptr;
622 {
623 filesystemStoragePluginName += " (Secondary: file-system)";
624 }
625
626 fileSystemStoragePlugin.reset(new FileSystemStoragePlugin(filesystemStoragePluginName, fileSystemRootPath, fsync));
627 }
628
629 if (hybridMode == HybridMode_Disabled || hybridMode == HybridMode_WriteToObjectStorage)
630 {
631 primaryStorage.reset(objectStoragePlugin.release());
632
633 if (hybridMode == HybridMode_WriteToObjectStorage)
634 {
635 secondaryStorage.reset(fileSystemStoragePlugin.release());
636 }
637 }
638 else if (hybridMode == HybridMode_WriteToFileSystem)
639 {
640 primaryStorage.reset(fileSystemStoragePlugin.release());
641 secondaryStorage.reset(objectStoragePlugin.release());
642 }
643
644 if (pluginSection.IsSection(ENCRYPTION_SECTION))
645 {
646 OrthancPlugins::OrthancConfiguration cryptoSection;
647 pluginSection.GetSection(cryptoSection, ENCRYPTION_SECTION);
648
649 crypto.reset(EncryptionConfigurator::CreateEncryptionHelpers(cryptoSection));
650 cryptoEnabled = crypto.get() != nullptr;
651 }
652
653 if (cryptoEnabled)
654 {
655 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is enabled");
656 }
657 else
658 {
659 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is disabled");
660 }
661
662
663 if (IsHybridModeEnabled())
664 {
665 OrthancPlugins::RegisterRestCallback<MoveStorage>("/move-storage", true);
666 OrthancPluginRegisterJobsUnserializer(context, JobUnserializer);
667 }
668
669 } 655 }
670 656
671 if (cryptoEnabled) 657 if (cryptoEnabled)
672 { 658 {
673 // with encrypted file, we do not want to support ReadRange. Therefore, we register the old interface 659 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is enabled");
660 }
661 else
662 {
663 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is disabled");
664 }
665
666
667 if (IsHybridModeEnabled())
668 {
669 OrthancPlugins::RegisterRestCallback<MoveStorage>("/move-storage", true);
670 OrthancPluginRegisterJobsUnserializer(context, JobUnserializer);
671 }
672
673 if (cryptoEnabled)
674 {
675 // with encrypted file, we can not support ReadRange. Therefore, we register the old interface
674 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageReadWholeLegacy, StorageRemove); 676 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageReadWholeLegacy, StorageRemove);
675 } 677 }
676 else 678 else
677 { 679 {
678 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove); 680 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove);