Sha256: f65e2ef5df190ccaea3f0e931712d3bfa3be24e6b73dc11d54d242558cd0b6e6
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
module SuperTopSecret class Injector def self.generate_config(app_file, secret_file) app_hash = YAML.load(File.read(app_file)) secret_hash = YAML.load(File.read(secret_file)) injected_hash = create_new_hash(app_hash, secret_hash) write_new_hash_to_file(injected_hash) end private def self.create_new_hash(app_hash, secret_hash) injected_hash = app_hash.dup app_hash.each do |key, val| if val.is_a?(Hash) # Nested val.each do |nested_key, nested_val| nested_val = secret_hash[key][nested_val] if secret_field?(nested_val) injected_hash[key][nested_key] = nested_val end else val = secret_hash[val] if secret_field?(val) injected_hash[key] = val end end return injected_hash end def self.secret_field?(val) val.include?("53CR3T_") end def self.write_new_hash_to_file(injected_hash) File.open("config/application.yml", "w+"){|f| f.write(injected_hash.to_yaml)} end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
super_top_secret-1.0.1 | lib/super_top_secret/injector.rb |