Class: ForemanDiscovery::NodeAPI::NodeResource
- Inherits:
-
Object
- Object
- ForemanDiscovery::NodeAPI::NodeResource
- Defined in:
- app/services/foreman_discovery/node_api/node_resource.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(args) ⇒ NodeResource
constructor
A new instance of NodeResource.
- #is_proxy? ⇒ Boolean
- #port ⇒ Object
- #root_path ⇒ Object
- #scheme ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(args) ⇒ NodeResource
Returns a new instance of NodeResource.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/foreman_discovery/node_api/node_resource.rb', line 3 def initialize(args) raise ArgumentError, _("Options must be hash") unless args.is_a?(Hash) raise ArgumentError, _("Option 'url' must be provided") unless args[:url] @args = args @connect_params = { :headers => { :accept => :json }, :timeout => 20, # tighter timeout, discovery performs up to two calls per request } if url.match(/^https/i) && Rails.env != "test" if is_proxy? logger.debug "Connecting to proxy, setting up SSL client cert" cert = Setting[:ssl_certificate] ca_cert = Setting[:ssl_ca_file] hostprivkey = Setting[:ssl_priv_key] @connect_params.merge!( :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read(cert)), :ssl_client_key => OpenSSL::PKey::RSA.new(File.read(hostprivkey)), :ssl_ca_file => ca_cert, :verify_ssl => OpenSSL::SSL::VERIFY_PEER ) else logger.debug "Connecting without proxy, not using SSL client cert" @connect_params.merge!( :verify_ssl => OpenSSL::SSL::VERIFY_NONE ) end end end |
Instance Method Details
#is_proxy? ⇒ Boolean
56 57 58 |
# File 'app/services/foreman_discovery/node_api/node_resource.rb', line 56 def is_proxy? root_path.starts_with?('/discovery') end |
#port ⇒ Object
44 45 46 47 48 |
# File 'app/services/foreman_discovery/node_api/node_resource.rb', line 44 def port URI.parse(url).port rescue Exception => e raise ArgumentError, _("Option 'url' must be valid URI: %s") % e end |
#root_path ⇒ Object
50 51 52 53 54 |
# File 'app/services/foreman_discovery/node_api/node_resource.rb', line 50 def root_path URI.parse(url).path rescue Exception => e raise ArgumentError, _("Option 'url' must be valid URI: %s") % e end |
#scheme ⇒ Object
38 39 40 41 42 |
# File 'app/services/foreman_discovery/node_api/node_resource.rb', line 38 def scheme URI.parse(url).scheme rescue Exception => e raise ArgumentError, _("Option 'url' must be valid URI: %s") % e end |
#url ⇒ Object
34 35 36 |
# File 'app/services/foreman_discovery/node_api/node_resource.rb', line 34 def url @args[:url] end |