Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
support decryption via hiera-eyaml
Browse files Browse the repository at this point in the history
  • Loading branch information
danarnold committed Feb 16, 2018
1 parent 8688a68 commit f15a232
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chorizo
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
2.5.0
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source "https://rubygems.org"

gem 'slop', '~> 3.6'
gem 'colorize'
gem 'hiera-eyaml'

group :development do
gem 'pry'
Expand Down
20 changes: 17 additions & 3 deletions lib/chorizo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,30 @@ def build_output(env, host)

def cloud66(env)
output = build_output(env, 'cloud66')
output.each { |k,v| puts "#{k.upcase}=#{v}" }
output.each do |k,v|
value = decrypt_value(v)
puts "#{k.upcase}=#{value}"
end
end

def heroku(env, app)
output = build_output(env, 'heroku')
cmd_output = output.map do |k,v|
val = "#{v}".shellescape
"#{k}=#{val}"
value = decrypt_value(v)
escaped_value = "#{v}".shellescape
"#{k}=#{escaped_value}"
end.join(' ')
system "heroku config:set #{cmd_output} -a #{app}"
end

def decrypt_value(value)
if value =~ /^ENC\[/
Open3.popen2("eyaml", "decrypt", "-s", value) do |i, o, t|
o.read.chomp
end
else
value
end
end

end

0 comments on commit f15a232

Please sign in to comment.