Permalink
Browse files

Added ability to specify default options in the YAML file, including

being able to turn off SSL verification (since it can be problematic
on certain machines).
  • Loading branch information...
1 parent 3fea7fa commit 828bc091ea69c2470046162e9f06679c6f3a65f7 @kanevski committed Feb 9, 2012
Showing with 13 additions and 7 deletions.
  1. +12 −6 bin/papertrail
  2. +1 −1 lib/papertrail/search_client.rb
View
@@ -33,15 +33,13 @@ class PapertrailSearch
opts.separator usage
end.parse!
- credentials = open(options[:configfile]) do |f|
+ configfile_options = open(options[:configfile]) do |f|
YAML.load(f)
end
+ configfile_options = symbolize_keys(configfile_options)
+ options.merge!(configfile_options)
- if credentials['token']
- client = Papertrail::SearchClient.new(:token => credentials['token'])
- else
- client = Papertrail::SearchClient.new(:username => credentials['username'], :password => credentials['password'])
- end
+ client = Papertrail::SearchClient.new(options)
search_and_print(client)
@@ -73,6 +71,14 @@ class PapertrailSearch
file_path
end
+ def symbolize_keys(hash)
+ new_hash = {}
+ hash.each_key do |key|
+ new_hash[(key.to_sym rescue key) || key] = hash[key]
+ end
+ new_hash
+ end
+
def usage
<<EOF
@@ -6,7 +6,7 @@
module Papertrail
class SearchClient
def initialize(options)
- ssl_options = { :verify => OpenSSL::SSL::VERIFY_PEER }
+ ssl_options = { :verify => options.fetch(:verify_ssl) { OpenSSL::SSL::VERIFY_PEER } }
# Make Ubuntu OpenSSL work
#

0 comments on commit 828bc09

Please sign in to comment.