diff --git a/Gemfile b/Gemfile index 5ac30d7b..9e4c6434 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,8 @@ group :development do end group :test do - gem "json" + gem "json", '~> 1.8.3' + gem "json_pure", '~> 1.8.3' # Pin for 1.8.7 compatibility for now gem "rake", '< 11.0.0' gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0' diff --git a/Gemfile.lock b/Gemfile.lock index 6d747c35..034d207d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -302,7 +302,7 @@ DEPENDENCIES beaker-rspec (>= 5.1.0) hiera hiera-puppet-helper - json + json (~> 1.8.3) pry puppet (~> 3.7.0) puppet-blacksmith @@ -317,4 +317,4 @@ DEPENDENCIES vagrant-wrapper BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/lib/puppet/provider/consul_acl/default.rb b/lib/puppet/provider/consul_acl/default.rb index 9197ff24..6c7fcf11 100644 --- a/lib/puppet/provider/consul_acl/default.rb +++ b/lib/puppet/provider/consul_acl/default.rb @@ -11,6 +11,7 @@ def self.prefetch(resources) Puppet.debug("prefetching for #{name}") port = resource[:port] hostname = resource[:hostname] + protocol = resource[:protocol] token = resource[:acl_api_token] found_acls = list_resources(token, port, hostname).select do |acl| @@ -35,7 +36,7 @@ def self.list_resources(acl_api_token, port, hostname) # this might be configurable by searching /etc/consul.d # but would break for anyone using nonstandard paths - uri = URI("http://#{hostname}:#{port}/v1/acl") + uri = URI("#{protocol}://#{hostname}:#{port}/v1/acl") http = Net::HTTP.new(uri.host, uri.port) path=uri.request_uri + "/list?token=#{acl_api_token}" @@ -69,7 +70,7 @@ def self.list_resources(acl_api_token, port, hostname) end def put_acl(method,body) - uri = URI("http://#{@resource[:hostname]}:#{@resource[:port]}/v1/acl") + uri = URI("#{@resource[:protocol]}://#{@resource[:hostname]}:#{@resource[:port]}/v1/acl") http = Net::HTTP.new(uri.host, uri.port) acl_api_token = @resource[:acl_api_token] path = uri.request_uri + "/#{method}?token=#{acl_api_token}" diff --git a/lib/puppet/type/consul_acl.rb b/lib/puppet/type/consul_acl.rb index 509407fd..3720e52d 100644 --- a/lib/puppet/type/consul_acl.rb +++ b/lib/puppet/type/consul_acl.rb @@ -38,6 +38,12 @@ desc 'ID of token' end + newproperty(:protocol) do + desc 'consul protocol' + newvalues('http', 'https') + defaultto 'http' + end + newparam(:port) do desc 'consul port' defaultto 8500 diff --git a/spec/unit/puppet/type/consul_acl_spec.rb b/spec/unit/puppet/type/consul_acl_spec.rb index e74e1a20..c3c4322c 100644 --- a/spec/unit/puppet/type/consul_acl_spec.rb +++ b/spec/unit/puppet/type/consul_acl_spec.rb @@ -46,5 +46,9 @@ it 'should accept a hash of rules' do expect(@acl[:rules]).to eq(samplerules) end + + it 'should default to http' do + expect(@acl[:protocol]).to eq(:http) + end end end