class HerokuVault::Cli
Public Instance Methods
apply(app_name)
click to toggle source
# File lib/heroku_vault/cli.rb, line 70 def apply(app_name) password = enter_password salt = enter_salt encryptor = HerokuVault::EncrypterFactory.create(password, salt) heroku = HerokuVault::HerokuCommander.new File.open(options[:file]) do |file| config_data = file.read decrypted_config = JSON.parse(config_data).map do |key, val| [key, encryptor.decrypt_and_verify(val)] end decrypted_config.each do |key, val| obj = {} obj[key] = val heroku.apply_config(app_name, obj) end end end
create_encrypted_config(app_name)
click to toggle source
# File lib/heroku_vault/cli.rb, line 53 def create_encrypted_config(app_name) password = enter_password salt = enter_salt heroku = HerokuVault::HerokuCommander.new config_data = heroku.config_all(app_name) encryptor = HerokuVault::EncrypterFactory.create(password, salt) encrypted = JSON.parse(config_data).map do |key, val| [key, encryptor.encrypt_and_sign(val)] end file_name = options[:output] output_file(file_name, JSON.parse(encrypted.to_h.to_json)) end
decrypt(file_name)
click to toggle source
# File lib/heroku_vault/cli.rb, line 26 def decrypt(file_name) config_data = open(file_name) do |io| JSON.load(io) end password = enter_password salt = enter_salt encryptor = HerokuVault::EncrypterFactory.create(password, salt) decrypted = config_data.map do |key, val| [key, encryptor.decrypt_and_verify(val)] end puts decrypted.to_h.to_json end
encrypt(file_name)
click to toggle source
# File lib/heroku_vault/cli.rb, line 9 def encrypt(file_name) password = enter_password salt = enter_salt encryptor = HerokuVault::EncrypterFactory.create(password, salt) config_data = open(file_name) do |io| JSON.load(io) end encrypted = config_data.map do |key, val| [key, encryptor.encrypt_and_sign(val)] end output_file(options[:output], JSON.parse(encrypted.to_h.to_json)) end
fetch(app_name)
click to toggle source
# File lib/heroku_vault/cli.rb, line 44 def fetch(app_name) heroku = HerokuVault::HerokuCommander.new config_data = heroku.config_all(app_name) file_name = options[:output] output_file(file_name, JSON.parse(config_data)) end
Private Instance Methods
enter_password()
click to toggle source
# File lib/heroku_vault/cli.rb, line 92 def enter_password print 'enter paswword: ' password = STDIN.noecho(&:gets) puts return password end
enter_salt()
click to toggle source
# File lib/heroku_vault/cli.rb, line 99 def enter_salt print 'enter salt: ' salt = STDIN.noecho(&:gets) puts salt end
output_file(file_name, json_hash)
click to toggle source
# File lib/heroku_vault/cli.rb, line 106 def output_file(file_name, json_hash) File.open(file_name, 'w') do |file| JSON.pretty_generate(json_hash).each_line do |line| file.puts line end end end