diff --git a/manifests/check.pp b/manifests/check.pp index 477b87ae..2ff2257a 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -71,7 +71,7 @@ consul_validate_checks($check_hash[check]) - $escaped_id = regsubst($id,'\/','_') + $escaped_id = regsubst($id,'\/','_','G') File[$consul::config_dir] -> file { "${consul::config_dir}/check_${escaped_id}.json": ensure => $ensure, diff --git a/manifests/service.pp b/manifests/service.pp index 0288a224..c3defbc9 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -58,7 +58,8 @@ service => delete_undef_values($basic_hash) } - file { "${consul::config_dir}/service_${id}.json": + $escaped_id = regsubst($id,'\/','_','G') + file { "${consul::config_dir}/service_${escaped_id}.json": ensure => $ensure, content => consul_sorted_json($service_hash, $consul::pretty_config, $consul::pretty_config_indent), require => File[$consul::config_dir], diff --git a/spec/defines/consul_check_spec.rb b/spec/defines/consul_check_spec.rb index 86a0de45..a765e296 100644 --- a/spec/defines/consul_check_spec.rb +++ b/spec/defines/consul_check_spec.rb @@ -218,4 +218,14 @@ .with_content(/"id" *: *"aa\/bb"/) } end + describe 'with multiple / in the id' do + let(:params) {{ + 'ttl' => '30s', + 'service_id' => 'my_service', + 'id' => 'aa/bb/cc', + }} + it { should contain_file("/etc/consul/check_aa_bb_cc.json") \ + .with_content(/"id" *: *"aa\/bb\/cc"/) + } + end end diff --git a/spec/defines/consul_service_spec.rb b/spec/defines/consul_service_spec.rb index e1b3db05..9dd2e329 100644 --- a/spec/defines/consul_service_spec.rb +++ b/spec/defines/consul_service_spec.rb @@ -185,6 +185,23 @@ .with_content(/"http" *: *"localhost"/) } end + describe 'with a / in the id' do + let(:params) {{ + 'id' => 'aa/bb', + }} + it { should contain_file("/etc/consul/service_aa_bb.json") \ + .with_content(/"id" *: *"aa\/bb"/) + } + end + describe 'with multiple / in the id' do + let(:params) {{ + 'id' => 'aa/bb/cc', + }} + it { should contain_file("/etc/consul/service_aa_bb_cc.json") \ + .with_content(/"id" *: *"aa\/bb\/cc"/) + } + end + describe 'with multiple checks script and invalid http' do let(:params) {{ 'checks' => [