Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #110 from agrare/set_faraday_response_logger
Browse files Browse the repository at this point in the history
Set the faraday logger when creating connection
  • Loading branch information
bdunne authored Jul 3, 2018
2 parents ad842d5 + 346b6a7 commit a6f71ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/ansible_tower_client/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Connection
def initialize(options = {})
raise "Credentials are required" unless options[:username] && options[:password]
raise ":base_url is required" unless options[:base_url]
logger = options[:logger] || AnsibleTowerClient.logger

require 'faraday'
require 'faraday_middleware'
Expand All @@ -25,18 +26,20 @@ def initialize(options = {})
:url => options[:base_url],
:verify_ssl => (options[:verify_ssl] || OpenSSL::SSL::VERIFY_PEER) != OpenSSL::SSL::VERIFY_NONE,
:username => options[:username],
:password => options[:password]
:password => options[:password],
:logger => logger,
}

reset
end

def connection(url:, username:, password:, verify_ssl: false)
def connection(url:, username:, password:, verify_ssl: false, logger: nil)
Faraday.new(url, :ssl => {:verify => verify_ssl}) do |f|
f.use(FaradayMiddleware::EncodeJson)
f.use(FaradayMiddleware::FollowRedirects, :limit => 3, :standards_compliant => true)
f.request(:url_encoded)
f.response(:raise_tower_error)
f.response(:logger, logger)
f.adapter(Faraday.default_adapter)
f.basic_auth(username, password)
end
Expand Down
6 changes: 4 additions & 2 deletions spec/connection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe AnsibleTowerClient::Connection do
let(:base_options) { {:base_url => "https://example1.com", :username => "admin", :password => "smartvm", :verify_ssl => OpenSSL::SSL::VERIFY_NONE} }
let(:logger) { double }
let(:base_options) { {:base_url => "https://example1.com", :username => "admin", :password => "smartvm", :verify_ssl => OpenSSL::SSL::VERIFY_NONE, :logger => logger} }

subject { described_class.new(base_options) }

Expand All @@ -12,7 +13,8 @@
:url => "https://example1.com",
:verify_ssl => false,
:username => "admin",
:password => "smartvm"
:password => "smartvm",
:logger => logger,
)
end

Expand Down

0 comments on commit a6f71ac

Please sign in to comment.