Class: ActiveStorageEncryption::EncryptedMirrorService::MirrorJobWithEncryption

Inherits:
ActiveStorage::MirrorJob
  • Object
show all
Defined in:
lib/active_storage_encryption/encrypted_mirror_service.rb

Instance Method Summary collapse

Instance Method Details

#encryption_key_from_token(encryption_key_token) ⇒ Object



14
15
16
17
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 14

def encryption_key_from_token(encryption_key_token)
  decrypted_token = ActiveStorageEncryption.token_encryptor.decrypt_and_verify(encryption_key_token, purpose: :mirror)
  Base64.decode64(decrypted_token.fetch("encryption_key"))
end

#lookup_service(name) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 19

def lookup_service(name)
  # This should be the name in the config, NOT the class name
  service = ActiveStorage::Blob.services.fetch(name) { ActiveStorage::Blob.service }
  raise ArgumentError, "#{service.name} is not providing file encryption" unless service.try(:encrypted?)
  service
end

#perform(key, checksum:, service_name:, encryption_key_token:) ⇒ Object



9
10
11
12
# File 'lib/active_storage_encryption/encrypted_mirror_service.rb', line 9

def perform(key, checksum:, service_name:, encryption_key_token:)
  service = lookup_service(service_name)
  service.try(:mirror_with_encryption, key, checksum: checksum, encryption_key: encryption_key_from_token(encryption_key_token))
end