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

Allow usage of unauthenticated PuppetDB over SSL #14

Merged
merged 2 commits into from
Jul 26, 2017
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
6 changes: 3 additions & 3 deletions lib/puppetdb/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def initialize(settings, query_api_version = 4, command_api_version = 1)
end

@use_ssl = scheme == 'https'
if @use_ssl
unless pem && hash_includes?(pem, 'key', 'cert', 'ca_file')
if @use_ssl && pem
unless hash_includes?(pem, 'key', 'cert', 'ca_file')
error_msg = 'Configuration error: https:// specified but pem is missing or incomplete. It requires cert, key, and ca_file.'
raise error_msg
end
Expand Down Expand Up @@ -94,7 +94,7 @@ def request(endpoint, query, opts = {})

debug("#{path} #{json_query} #{opts}")

ret = self.class.get(path, query: filtered_opts)
ret = self.class.get(path, body: filtered_opts)
raise_if_error(ret)

total = ret.headers['X-Records']
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def expect_include_total(mock_query)
expect(r.use_ssl).to eq(true)
end

it 'does not tolerate lack of pem' do
it 'tolerates lack of pem' do
settings = {
server: 'https://localhost:8081'
}

-> { PuppetDB::Client.new(settings) }.should raise_error
-> { PuppetDB::Client.new(settings) }.should_not raise_error
end

it 'does not tolerate lack of key' do
Expand Down Expand Up @@ -147,7 +147,7 @@ def expect_include_total(mock_query)
mock_response.expects(:parsed_response).returns([])

PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with do |_path, opts|
opts[:query] == { 'query' => '[1,2,3]' }
opts[:body] == { 'query' => '[1,2,3]' }
end
client.request('/foo', [1, 2, 3])
end
Expand All @@ -162,7 +162,7 @@ def expect_include_total(mock_query)

PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with do |_path, opts|
opts == {
query: {
body: {
'query' => '[1,2,3]',
'limit' => 10,
'counts-filter' => '[4,5,6]',
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def expect_include_total(mock_query)
expect(r.use_ssl).to eq(true)
end

it 'does not tolerate lack of pem' do
it 'tolerates lack of pem' do
settings = {
server: 'https://localhost:8081'
}

-> { PuppetDB::Client.new(settings) }.should raise_error
-> { PuppetDB::Client.new(settings) }.should_not raise_error
end

it 'does not tolerate lack of key' do
Expand Down Expand Up @@ -147,7 +147,7 @@ def expect_include_total(mock_query)
mock_response.expects(:parsed_response).returns([])

PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with do |_path, opts|
opts[:query] == { 'query' => '[1,2,3]' }
opts[:body] == { 'query' => '[1,2,3]' }
end
client.request('/foo', [1, 2, 3])
end
Expand All @@ -162,7 +162,7 @@ def expect_include_total(mock_query)

PuppetDB::Client.expects(:get).returns(mock_response).at_least_once.with do |_path, opts|
opts == {
query: {
body: {
'query' => '[1,2,3]',
'limit' => 10,
'counts-filter' => '[4,5,6]',
Expand Down