Class: ProxyAPI::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_api/resource.rb

Direct Known Subclasses

BMC, DHCP, DNS, Features, Puppet, Puppetca, TFTP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Resource


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/proxy_api/resource.rb', line 6

def initialize(args)
  raise("Must provide a protocol and host when initialising a smart-proxy connection") unless (url =~ /^http/)

  # Each request is limited to 60 seconds
  @connect_params = {:timeout => 60, :open_timeout => 10, :headers => { :accept => :json },
                    :user => args[:user], :password => args[:password]}

  # We authenticate only if we are using SSL
  if url.match(/^https/i)
    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
    ) unless Rails.env == "test"
  end
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url


4
5
6
# File 'lib/proxy_api/resource.rb', line 4

def url
  @url
end