Class: ActiveStorageEncryption::EncryptedMirrorService
- Inherits:
-
ActiveStorage::Service::MirrorService
- Object
- ActiveStorage::Service::MirrorService
- ActiveStorageEncryption::EncryptedMirrorService
- Defined in:
- lib/active_storage_encryption/encrypted_mirror_service.rb
Direct Known Subclasses
Defined Under Namespace
Classes: MirrorJobWithEncryption
Instance Method Summary collapse
- #encrypted? ⇒ Boolean
- #mirror_with_encryption(key, checksum:, encryption_key:) ⇒ Object
- #private_url_policy=(_) ⇒ Object
- #service_name ⇒ Object
- #upload(key, io, encryption_key:, checksum: nil, **options) ⇒ Object
Instance Method Details
#encrypted? ⇒ Boolean
31 32 33 |
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 31 def encrypted? true end |
#mirror_with_encryption(key, checksum:, encryption_key:) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 45 def mirror_with_encryption(key, checksum:, encryption_key:) instrument :mirror, key: key, checksum: checksum do mirrors_in_need_of_mirroring = mirrors.select { |service| !service.exist?(key) } return if mirrors_in_need_of_mirroring.empty? primary.open(key, checksum: checksum, verify: checksum.present?, encryption_key: encryption_key) do |io| mirrors_in_need_of_mirroring.each do |target| io.rewind = target.try(:encrypted?) ? {encryption_key: encryption_key} : {} target.upload(key, io, checksum: checksum, **) end end end end |
#private_url_policy=(_) ⇒ Object
27 28 29 |
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 27 def private_url_policy=(_) raise ArgumentError, "EncryptedMirrorService uses the private_url_policy of the primary" end |
#service_name ⇒ Object
59 60 61 62 63 |
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 59 def service_name # ActiveStorage::Service::DiskService => Disk # Overridden because in Rails 8 this is "self.class.name.split("::").third.remove("Service")" self.class.name.split("::").last.remove("Service") end |
#upload(key, io, encryption_key:, checksum: nil, **options) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 35 def upload(key, io, encryption_key:, checksum: nil, **) io.rewind if primary.try(:encrypted?) primary.upload(key, io, checksum: checksum, encryption_key: encryption_key, **) else primary.upload(key, io, checksum: checksum, **) end mirror_later_with_encryption(key, checksum: checksum, encryption_key: encryption_key, **) end |