Class: Roro::Crypto::Obfuscator

Inherits:
Object
  • Object
show all
Includes:
FileReflection
Defined in:
lib/roro/crypto/obfuscator.rb

Instance Method Summary collapse

Methods included from FileReflection

#gather_environments, #get_key, #source_files

Constructor Details

#initializeObfuscator

Returns a new instance of Obfuscator.



5
6
7
8
9
# File 'lib/roro/crypto/obfuscator.rb', line 5

def initialize
  @writer = FileWriter.new
  @cipher = Cipher.new
  @mise   = Roro::CLI.mise
end

Instance Method Details

#obfuscate(environments = [], directory = @mise, extension = '.env') ⇒ Object



16
17
18
19
20
21
22
# File 'lib/roro/crypto/obfuscator.rb', line 16

def obfuscate(environments = [], directory = @mise, extension = '.env')
  environments = gather_environments(directory, extension) if environments.empty?
  environments.each do |environment|
    obfuscatable = source_files(directory, "#{environment}*#{extension}")
    obfuscatable.each { |file| obfuscate_file(file, get_key(environment))}
  end
end

#obfuscate_file(file, key) ⇒ Object



11
12
13
14
# File 'lib/roro/crypto/obfuscator.rb', line 11

def obfuscate_file(file, key)
  encrypted_content = @cipher.encrypt(File.read(file), key)
  @writer.write_to_file(file + '.enc', encrypted_content)
end