Skip to content

Commit

Permalink
Properly sort consul configuration
Browse files Browse the repository at this point in the history
Simple sort compare key & values. It fails for hash values.

For instance:

```
{:data_dir=>"/var/lib/consul",
 :client_addr=>"0.0.0.0",
 :ports=>{"dns"=>-1, "http"=>8500, "rpc"=>8400, "serf_lan"=>8301, "serf_wan"=>8302, "server"=>8300},
 :enable_syslog=>false,
 :retry_join=>["consul01-par.kitchen"],
 :node_name=>"ip-10-0-64-236.us-west-2.compute.internal",
 :server=>false,
 :datacenter=>"par",
 :domain=>"consul",
 :addresses=>{"http"=>"0.0.0.0"},
 :acl_datacenter=>"par",
 :disable_update_check=>true,
 :leave_on_terminate=>false,
 :advertise_addr=>"10.0.64.236",
 :encrypt=>"/AKlGGZMMSUsJLit/+etBw==",
 :verify_incoming=>false,
 :verify_outgoing=>false,
 "node_meta"=>{"rack"=>nil}}
```

will raise `ArgumentError: comparison of Array with Array failed`.

Sorting by keys is sufficient

Fix sous-chefs#410

Change-Id: Ieaf05a019c4d636ae8457046ee4e3bf8f697296a
  • Loading branch information
kamaradclimber committed Feb 8, 2017
1 parent 3cbc7ab commit 5381193
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/consul_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def to_json
config = to_hash.keep_if do |k, _|
for_keeps.include?(k.to_sym)
end.merge(options)
JSON.pretty_generate(Hash[config.sort], quirks_mode: true)
JSON.pretty_generate(Hash[config.sort_by { |k, _| k.to_s }], quirks_mode: true)
end

def tls?
Expand Down

0 comments on commit 5381193

Please sign in to comment.