module SecretSecrets
Constants
- VERSION
Public Class Methods
decrypt_file(write=false)
click to toggle source
# File lib/secret_secrets.rb, line 55 def self.decrypt_file(write=false) cipher = create_cipher(false) buffer = "" contents = "" File.open(encrypted_file_name, 'rb') do |input| while input.read(4096, buffer) contents << cipher.update(buffer) end contents << cipher.final File.open(unencrypted_file_name, 'wb') do |output| output.write(contents) end if write contents end end
encrypt_file(write=false)
click to toggle source
# File lib/secret_secrets.rb, line 39 def self.encrypt_file(write=false) cipher = create_cipher(true) buffer = "" contents = "" File.open(unencrypted_file_name, 'rb') do |input| while input.read(4096, buffer) contents << cipher.update(buffer) end contents << cipher.final File.open(encrypted_file_name, 'wb') do |output| output.write(contents) end if write contents end end
load_secret_secrets_into_secrets()
click to toggle source
# File lib/secret_secrets.rb, line 27 def self.load_secret_secrets_into_secrets return unless @@salt && @@passphrase && @@encrypted_file_name && @@unencrypted_file_name if File.exists?(encrypted_file_name) contents = self.decrypt_file require "erb" all_secrets = YAML.load(ERB.new(contents).result) || {} env_secrets = all_secrets[Rails.env] || {} Rails.application.secrets.merge!(env_secrets.symbolize_keys) end end
setup() { |self| ... }
click to toggle source
# File lib/secret_secrets.rb, line 22 def self.setup yield self if block_given? self.load_secret_secrets_into_secrets end
Private Class Methods
create_cipher(encrypt)
click to toggle source
# File lib/secret_secrets.rb, line 81 def self.create_cipher(encrypt) cipher = OpenSSL::Cipher::Cipher.new 'AES-128-CBC' encrypt ? cipher.encrypt : cipher.decrypt cipher.pkcs5_keyivgen @@passphrase, @@salt cipher end
encrypted_file_name()
click to toggle source
# File lib/secret_secrets.rb, line 73 def self.encrypted_file_name Rails.root.join(@@encrypted_file_name) end
unencrypted_file_name()
click to toggle source
# File lib/secret_secrets.rb, line 77 def self.unencrypted_file_name Rails.root.join(@@unencrypted_file_name) end