Module: Berkshelf::RidleyCompatAPI
- Included in:
- RidleyCompat, RidleyCompatJSON, RidleyCompatSimple
- Defined in:
- lib/berkshelf/ridley_compat.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #get(url) ⇒ Object
- #initialize(**opts) ⇒ Object
-
#server_url ⇒ Object
for compat with Ridley::Connection.
Class Method Details
.included(klass) ⇒ Object
62 63 64 |
# File 'lib/berkshelf/ridley_compat.rb', line 62 def self.included(klass) klass.extend ClassMethods end |
Instance Method Details
#get(url) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/berkshelf/ridley_compat.rb', line 36 def get(url) super(url) rescue Net::HTTPExceptions => e case e.response.code when "404" raise Berkshelf::APIClient::ServiceNotFound, "service not found at: #{url}" when /^5/ raise Berkshelf::APIClient::ServiceUnavailable, "service unavailable at: #{url}" else raise Berkshelf::APIClient::BadResponse, "bad response #{e.response}" end rescue Errno::ETIMEDOUT, Timeout::Error raise Berkshelf::APIClient::TimeoutError, "Unable to connect to: #{url}" rescue Errno::EHOSTUNREACH, Errno::ECONNREFUSED => e raise Berkshelf::APIClient::ServiceUnavailable, e end |
#initialize(**opts) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/berkshelf/ridley_compat.rb', line 10 def initialize(**opts) opts = opts.dup opts[:ssl] ||= {} chef_opts = {} chef_opts[:rest_timeout] = opts[:timeout] if opts[:timeout] # opts[:open_timeout] is ignored on purpose chef_opts[:headers] = opts[:headers] if opts[:headers] chef_opts[:client_name] = opts[:client_name] if opts[:client_name] chef_opts[:signing_key_filename] = opts[:client_key] if opts[:client_key] chef_opts[:verify_api_cert] = opts[:ssl][:verify] || opts[:ssl][:verify].nil? chef_opts[:ssl_verify_mode] = chef_opts[:verify_api_cert] ? :verify_peer : :verify_none chef_opts[:ssl_ca_path] = opts[:ssl][:ca_path] if opts[:ssl][:ca_path] chef_opts[:ssl_ca_file] = opts[:ssl][:ca_file] if opts[:ssl][:ca_file] chef_opts[:ssl_client_cert] = opts[:ssl][:client_cert] if opts[:ssl][:client_cert] chef_opts[:ssl_client_key] = opts[:ssl][:client_key] if opts[:ssl][:client_key] chef_opts[:version_class] = opts[:version_class] if opts[:version_class] # chef/http/ssl_policies.rb reads only from Chef::Config and not from the opts in the constructor Chef::Config[:verify_api_cert] = chef_opts[:verify_api_cert] Chef::Config[:ssl_verify_mode] = chef_opts[:ssl_verify_mode] super(opts[:server_url].to_s, **chef_opts) end |
#server_url ⇒ Object
for compat with Ridley::Connection
32 33 34 |
# File 'lib/berkshelf/ridley_compat.rb', line 32 def server_url url end |