Class: SmartProxyDynflowCore::Callback::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_dynflow_core/callback.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.send_to_foreman_tasks(callback_info, data) ⇒ Object



14
15
16
# File 'lib/smart_proxy_dynflow_core/callback.rb', line 14

def send_to_foreman_tasks(callback_info, data)
  self.new.callback(prepare_payload(callback_info, data))
end

.ssl_optionsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smart_proxy_dynflow_core/callback.rb', line 18

def ssl_options
  return @ssl_options if defined? @ssl_options
  @ssl_options = {}
  settings = Settings.instance
  return @ssl_options unless URI.parse(settings.foreman_url).scheme == 'https'

  @ssl_options[:verify_ssl] = OpenSSL::SSL::VERIFY_PEER

  private_key_file = settings.foreman_ssl_key || settings.ssl_private_key
  if private_key_file
    private_key = File.read(private_key_file)
    @ssl_options[:ssl_client_key] = OpenSSL::PKey::RSA.new(private_key)
  end
  certificate_file = settings.foreman_ssl_cert || settings.ssl_certificate
  if certificate_file
    certificate = File.read(certificate_file)
    @ssl_options[:ssl_client_cert] = OpenSSL::X509::Certificate.new(certificate)
  end
  ca_file = settings.foreman_ssl_ca || settings.ssl_ca_file
  @ssl_options[:ssl_ca_file] = ca_file if ca_file
  @ssl_options
end

Instance Method Details

#callback(payload) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/smart_proxy_dynflow_core/callback.rb', line 49

def callback(payload)
  response = callback_resource.post(payload, :content_type => :json)
  if response.code.to_s != "200"
    raise "Failed performing callback to Foreman server: #{response.code} #{response.body}"
  end
  response
end