Last active
August 29, 2015 14:01
-
-
Save vanstee/0a4caa246af4fd7f64f1 to your computer and use it in GitHub Desktop.
Import heroku env vars into confy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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