lib/fastly/client.rb in fastly-1.2.0 vs lib/fastly/client.rb in fastly-1.2.1

- old
+ new

@@ -3,20 +3,28 @@ require 'net/http' # also requires uri class Fastly # The UserAgent to communicate with the API class Client #:nodoc: all + ROOT_CA = File.join("../../cacert.pem", __FILE__) attr_accessor :http, :api_key, :user, :password, :cookie, :customer def initialize(opts) @api_key = opts.fetch(:api_key, nil) @user = opts.fetch(:user, nil) @password = opts.fetch(:password, nil) @customer = opts.fetch(:customer, nil) + certificate_store = opts.fetch(:certificate_store, ROOT_CA) + base = opts.fetch(:base_url, 'https://api.fastly.com') uri = URI.parse(base) - @http = Net::HTTP.start(uri.host, uri.port, use_ssl: true) + ssl = uri.is_a? URI::HTTPS # detect if we should pass `use_ssl` + @http = Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) + + http.ca_path = certificate_store + http.verify_mode = OpenSSL::SSL::VERIFY_PEER + http.verify_depth = 5 return self unless fully_authed? # If full auth creds (user/pass) then log in and set a cookie resp = http.post('/login', make_params(user: user, password: password))