Skip to content

Instantly share code, notes, and snippets.

@vanstee
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanstee/0a4caa246af4fd7f64f1 to your computer and use it in GitHub Desktop.
Save vanstee/0a4caa246af4fd7f64f1 to your computer and use it in GitHub Desktop.
Import heroku env vars into confy
require 'confyio'
CONFY_URL_REGEX = /https?:\/\/(?<org>.*):(?<password>.*)@api.confy.io\/orgs\/(?<org>.*)\/projects\/(?<project>.*)\/envs\/(?<env>.*)\/config/
confy_url = %x[heroku config | grep CONFY_URL].chomp.split(' ', 2).last
if confy_url.empty?
puts "Your CONFY_URL hasn't been set yet. Run `heroku addons:add confy` and try again."
exit 1
end
options = CONFY_URL_REGEX.match(confy_url)
client = Confy::Client.new({ username: options[:org], password: options[:password] }, { base: 'https://apiconfyio.herokuapp.com' })
config = client.config(options[:org], options[:project], options[:env])
config_json = config.retrieve.body
%x[heroku config | grep -v CONFY_URL].split("\n").each do |line|
next if line.start_with?('===')
key, value = line.split(' ', 2)
key.chop!
answer = ''
until ['y', 'n'].include?(answer) do
print "Import #{key} in confy config? [y/n] "
answer = gets.chomp
end
if answer == 'y'
config_json[key] = value
end
end
puts "Uploading new confy config"
config.update(config_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment