Class: Arbor::Peakflow::Client

Inherits:
Object
  • Object
show all
Includes:
Alerts, CP5500, Managed_Object, Mitigations, Reports, Routers, TMS_Appliance, TMS_Ports, Traffic
Defined in:
lib/arbor_peakflow_ruby/client.rb

Overview

Client

The Arbor Peakflow client in charge of using Hurley to communicate with the Arbor devices.

Parameters

  • hosts, host, urls, or url: The location of the Arbor Peakflow device cluster.

  • api_key: The API key to be used when communicating with the Arbor Peakflow API.

  • ssl_verify: (Optional) Boolean value stating whether you would like to verify the SSL certificates. Defaults to false.

  • ca_path: (Optional) String value for the location of local certificates. The OPENSSLDIR can be found using the ‘openssl version -a` command then taking OPENSSLDIR and appending ’/certs’. Defaults to the path provided by ‘openssl version -d`.

  • ssl_version: (Optional) String value for the version of SSL to use. By default, this is SSLv23, which creates a TLS/SSL connection which may understand the SSLv3, TLSv1, TLSv1.1 and TLSv1.2 protocols.

Example

client = Arbor::Peakflow::Client.new host: 'http://my.arbor.device/',
                                     api_key: 'myApiKeyHere123',
                                     ssl_verify: false,
                                     ca_path: '/usr/ssl/certs',
                                     ssl_version: 'SSLv23'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Traffic

#remove_returns_and_spaces, #traffic

Methods included from TMS_Ports

#tms_ports

Methods included from TMS_Appliance

#tms_appliance

Methods included from Routers

#routers

Methods included from Reports

#configured_reports, #download_report, #queue_report, #report_results

Methods included from Mitigations

#mitigations

Methods included from Managed_Object

#managed_object

Methods included from CP5500

#cp5500

Methods included from Alerts

#alerts

Constructor Details

#initialize(arguments = {}) ⇒ Client

Returns a new instance of Client.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/arbor_peakflow_ruby/client.rb', line 46

def initialize(arguments = {})
  @hosts = arguments[:hosts] || \
           arguments[:host]  || \
           arguments[:url]   || \
           arguments[:urls]  || \
           ENV.fetch('PEAKFLOW_URL')

  @api_key ||= arguments[:api_key]

  @client = Hurley::Client.new @hosts
  ssl(arguments)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



45
46
47
# File 'lib/arbor_peakflow_ruby/client.rb', line 45

def api_key
  @api_key
end

#clientObject

Returns the value of attribute client.



44
45
46
# File 'lib/arbor_peakflow_ruby/client.rb', line 44

def client
  @client
end

#hostsObject (readonly)

Returns the value of attribute hosts.



45
46
47
# File 'lib/arbor_peakflow_ruby/client.rb', line 45

def hosts
  @hosts
end

Instance Method Details

#ssl(arguments) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/arbor_peakflow_ruby/client.rb', line 59

def ssl(arguments)
  @ssl_verify = arguments[:ssl_verify] || \
                false

  @ca_path = arguments[:ca_path]  || \
             `openssl version -d`.split(/"/)[1] + '/certs'

  @ssl_version = arguments[:ssl_version]  || \
                 'SSLv23'

  @client.ssl_options.skip_verification = !@ssl_verify
  @client.ssl_options.ca_path = @ca_path
  @client.ssl_options.version = @ssl_version
end

#url_action_filter_request(url, action, filter) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/arbor_peakflow_ruby/client.rb', line 88

def url_action_filter_request(url, action, filter)
  response = @client.get(url,
                         {}.tap do |hash|
                           hash[:api_key] = @api_key
                           hash[:action] = action unless action.nil?
                           hash[:filter] = filter unless filter.nil?
                         end)

  response
end

#url_filter_limit_format_request(url, filter, limit, format) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/arbor_peakflow_ruby/client.rb', line 74

def url_filter_limit_format_request(url, filter, limit, format)
  response = @client.get(url,
                         {}.tap do |hash|
                           hash[:api_key] = @api_key
                           hash[:format] = format unless format.nil?
                           hash[:limit] = limit unless limit.nil?
                           hash[:filter] = filter unless filter.nil?
                         end)

  response.body = JSON.parse(response.body) if format == 'json'

  response
end