Class: Decidim::Voca::AppDecryptBackupFile
- Inherits:
-
Object
- Object
- Decidim::Voca::AppDecryptBackupFile
- Defined in:
- lib/decidim/voca/backup/app_decrypt_backup_file.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
Instance Method Summary collapse
- #decrypt! ⇒ Object
-
#initialize(file_enc) ⇒ AppDecryptBackupFile
constructor
A new instance of AppDecryptBackupFile.
-
#logger ⇒ Object
Define logger for the class.
- #setup_decipher! ⇒ Object
Constructor Details
#initialize(file_enc) ⇒ AppDecryptBackupFile
Returns a new instance of AppDecryptBackupFile.
10 11 12 13 14 |
# File 'lib/decidim/voca/backup/app_decrypt_backup_file.rb', line 10 def initialize(file_enc) logger.info "⚙️ starts decrypt file" raise ArgumentError, "encrypted file cannot be nil" if file_enc.nil? @file_enc = file_enc end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/decidim/voca/backup/app_decrypt_backup_file.rb', line 8 def file_path @file_path end |
Instance Method Details
#decrypt! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/decidim/voca/backup/app_decrypt_backup_file.rb', line 16 def decrypt! setup_decipher! file_name = File.basename(@file_enc, ".enc") @file_path = File.join(File.dirname(@file_enc), file_name) File.open(@file_path, "w:BINARY") do |decrypted_file| File.open(@file_enc, "r:BINARY") do |encrypted_file| data = encrypted_file.read decrypted_data = @decipher.update(data) + @decipher.final decrypted_file.write(decrypted_data) end end raise Error, "decrypted file not created" unless File.exists?(@file_path) rescue Exception => e logger.error e. raise e end |
#logger ⇒ Object
Define logger for the class.
45 46 47 |
# File 'lib/decidim/voca/backup/app_decrypt_backup_file.rb', line 45 def logger @logger ||= Rails.logger end |
#setup_decipher! ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/decidim/voca/backup/app_decrypt_backup_file.rb', line 34 def setup_decipher! @decipher ||= OpenSSL::Cipher::AES.new(256, :CBC).decrypt @decipher.key = Base64.decode64(ENV.fetch("BACKUP_CIPHER_KEY")) @decipher.iv = Base64.decode64(ENV.fetch("BACKUP_CIPHER_IV")) rescue Exception => e logger.error e. raise e end |