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

Commit

Permalink
Added support for config file to specify target and app and only have to
Browse files Browse the repository at this point in the history
pass the chorizo command an environment. Updated readme and version.
  • Loading branch information
jclusso committed May 1, 2019
1 parent 1b6dc8b commit 61f817b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Since 0.1.3, chorizo supports decrypting values encoded with hiera-eyaml,
provided you have the necessary keys. It does this by searching for the
beginning of an encrypted value in each value string.

## Config

Since 0.1.7, chorizo supports a config file that should be placed in
`config/chorizo.yml`. An example of this file can be found [here](examples/chorizo.yml).

## Usage

```ruby
Expand Down
11 changes: 1 addition & 10 deletions bin/chorizo
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,4 @@ if opts[:target] == 'heroku' && !opts[:app]
exit 1
end

case opts[:target]
when 'cloud66'
Chorizo.new.cloud66 opts[:environment]
when 'heroku'
Chorizo.new.heroku(opts[:environment], opts[:app])
else
STDERR.puts "please specify a valid target".red
puts opts
exit 1
end
Chorizo.new.run(opts[:environment], target: opts[:target], app: opts[:app])
2 changes: 1 addition & 1 deletion chorizo.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'chorizo'
s.version = '0.1.6'
s.version = '0.1.7'
s.date = '2018-02-16'
s.summary = 'Parse and set environment variables on hosting providers'
s.description = 'Parse and set environment variables on hosting providers'
Expand Down
7 changes: 7 additions & 0 deletions examples/chorizo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
staging:
target: heroku
app: staging-app-name

production:
target: heroku
app: app-name
30 changes: 29 additions & 1 deletion lib/chorizo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Chorizo

def initialize
@host_names = %w(cloud66 heroku)
@config = YAML.load_file('./config/chorizo.yml')
end

def load_config
Expand All @@ -16,7 +17,7 @@ def load_config
@host_names.each do |host|
hosts[host] = hashes.delete(host) if hashes[host]
end
{ base: base, hosts: hosts, envs: hashes }
{ base: base, hosts: hosts, envs: hashes }
end

def build_output(env, host)
Expand Down Expand Up @@ -47,6 +48,33 @@ def build_output(env, host)
output
end

def run(env, target: nil, app: nil)
target ||= @config[env]['target']

unless target
STDERR.puts 'please specify a valid target'.red
return
end

case target
when 'cloud66'
cloud66(env)
when 'heroku'
if app && app != @config[env]['app']
STDERR.puts 'WARNING: App specified in configuration is different'.red
end

app ||= @config[env]['app']

unless app
STDERR.puts 'please specify an app for heroku'.red
return
end

heroku(env, app)
end
end

def cloud66(env)
output = build_output(env, 'cloud66')
output.each do |k,v|
Expand Down

0 comments on commit 61f817b

Please sign in to comment.