Skip to content

Instantly share code, notes, and snippets.

@itsprdp
Last active January 18, 2016 15:40
Show Gist options
  • Save itsprdp/4da27604dcee1edcd18b to your computer and use it in GitHub Desktop.
Save itsprdp/4da27604dcee1edcd18b to your computer and use it in GitHub Desktop.
Convert your .env file data to JSON key with values encoded to base64
#!/usr/bin/env ruby
# Encode .env file values to base64 and create json key values
require 'base64'
require 'yaml'
if ARGV[0]
env = {}
file = File.new(ARGV[0], "r")
exit unless file
data = file.read
env_vars = data.split("\n")
env_vars.each do |env_var|
next unless env_var.include?('export')
export_key, ival = env_var.split("=") if env_var
key = export_key.split("export ").last.gsub("_", "-").downcase if export_key
val = (ival)? Base64.strict_encode64(ival) : nil
env[key] = %Q("#{val}")
end
env.each {|k,v| puts "#{k}: #{v}" }
else
puts "Please pass the .env file path.\n Eg: ruby kuberenv.rb config/.env.staging\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment