PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Raven.Database/Bundles/Encryption/Plugin/EncryptionSettingsPutTrigger.cs

https://github.com/nwendel/ravendb
C# | 33 lines | 30 code | 3 blank | 0 comment | 6 complexity | add4a05d7791d0aceb8b012a9e3e80cc MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Composition;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Raven.Abstractions.Data;
  8. using Raven.Bundles.Encryption.Settings;
  9. using Raven.Database.Plugins;
  10. using Raven.Json.Linq;
  11. namespace Raven.Bundles.Encryption.Plugin
  12. {
  13. [InheritedExport(typeof(AbstractPutTrigger))]
  14. [ExportMetadata("Order", 10000)]
  15. [ExportMetadata("Bundle", "Encryption")]
  16. public class EncryptionSettingsPutTrigger : AbstractPutTrigger
  17. {
  18. public override VetoResult AllowPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
  19. {
  20. if (key == Constants.InDatabaseKeyVerificationDocumentName)
  21. {
  22. if (Database == null) // we haven't been initialized yet
  23. return VetoResult.Allowed;
  24. if (Database.Documents.Get(key, null) != null)
  25. return VetoResult.Deny("The encryption verification document already exists and cannot be overwritten.");
  26. }
  27. return VetoResult.Allowed;
  28. }
  29. }
  30. }