Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update consul_config resource #219

Merged
merged 3 commits into from
Sep 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libraries/consul_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ConsulConfig < Chef::Resource
attribute(:ports, kind_of: [Hash, Mash])
attribute(:protocol, kind_of: String)
attribute(:recursor, kind_of: String)
attribute(:recursors, kind_of: Array)
attribute(:retry_interval, kind_of: Integer)
attribute(:server, equal_to: [true, false], default: true)
attribute(:server_name, kind_of: String)
Expand All @@ -88,12 +89,12 @@ class ConsulConfig < Chef::Resource
# Transforms the resource into a JSON format which matches the
# Consul service's configuration format.
def to_json
for_keeps = %i{acl_datacenter acl_default_policy acl_down_policy acl_master_token acl_token acl_ttl addresses advertise_addr advertise_addr_wan bind_addr bootstrap bootstrap_expect check_update_interval client_addr data_dir datacenter disable_anonymous_signature disable_remote_exec disable_update_check dns_config domain enable_debug enable_syslog encrypt leave_on_terminate log_level node_name ports protocol recurser retry_interval server server_name skip_leave_on_interrupt start_join statsd_addr statsite_addr syslog_facility ui_dir verify_incoming verify_outgoing verify_server_hostname watches}
for_keeps = %i{acl_datacenter acl_default_policy acl_down_policy acl_master_token acl_token acl_ttl addresses advertise_addr advertise_addr_wan bind_addr bootstrap bootstrap_expect check_update_interval client_addr data_dir datacenter disable_anonymous_signature disable_remote_exec disable_update_check dns_config domain enable_debug enable_syslog encrypt leave_on_terminate log_level node_name ports protocol recursor recursors retry_interval server server_name skip_leave_on_interrupt start_join statsd_addr statsite_addr syslog_facility ui_dir verify_incoming verify_outgoing verify_server_hostname watches}
for_keeps << %i{ca_file cert_file key_file} if tls?
config = to_hash.keep_if do |k, _|
for_keeps.include?(k.to_sym)
end.merge(options)
JSON.pretty_generate(config, quirks_mode: true)
JSON.pretty_generate(Hash[config.sort], quirks_mode: true)
end

def tls?
Expand Down
6 changes: 3 additions & 3 deletions test/spec/libraries/consul_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
recipe do
consul_config '/etc/consul/default.json' do
options do
recurser 'foo'
recursor 'foo'
end
end
end

it { is_expected.to render_file('/etc/consul/default.json').with_content(<<-EOH.chomp) }
{
"recursor": "foo",
"verify_incoming": false,
"verify_outgoing": false,
"recurser": "foo"
"verify_outgoing": false
}
EOH
end
Expand Down