ruby-paloalto-client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +152 -0
  9. data/Rakefile +2 -0
  10. data/lib/palo-alto/client/version.rb +5 -0
  11. data/lib/palo-alto/client.rb +50 -0
  12. data/lib/palo-alto/common/base-api.rb +84 -0
  13. data/lib/palo-alto/helpers/rest.rb +46 -0
  14. data/lib/palo-alto/models/address-group.rb +27 -0
  15. data/lib/palo-alto/models/address.rb +25 -0
  16. data/lib/palo-alto/models/device.rb +27 -0
  17. data/lib/palo-alto/models/rulebase.rb +24 -0
  18. data/lib/palo-alto/models/virtual-system.rb +28 -0
  19. data/lib/palo-alto/v6/address-api.rb +46 -0
  20. data/lib/palo-alto/v6/address-group-api.rb +57 -0
  21. data/lib/palo-alto/v6/api.rb +16 -0
  22. data/lib/palo-alto/v6/device-api.rb +55 -0
  23. data/lib/palo-alto/v6/virtual-system-api.rb +76 -0
  24. data/ruby-paloalto-client.gemspec +29 -0
  25. data/spec/fixtures/address_groups.xml +14 -0
  26. data/spec/fixtures/addresses.xml +14 -0
  27. data/spec/fixtures/blank_address_groups.xml +6 -0
  28. data/spec/fixtures/blank_addresses.xml +5 -0
  29. data/spec/fixtures/blank_devices.xml +4 -0
  30. data/spec/fixtures/blank_virtual_systems.xml +4 -0
  31. data/spec/fixtures/devices.xml +17 -0
  32. data/spec/fixtures/failure.xml +2 -0
  33. data/spec/fixtures/no_address_group_virtual_systems.xml +24 -0
  34. data/spec/fixtures/no_address_virtual_systems.xml +24 -0
  35. data/spec/fixtures/no_members_address_groups.xml +11 -0
  36. data/spec/fixtures/no_rulebase_virtual_systems.xml +24 -0
  37. data/spec/fixtures/no_vsys_devices.xml +13 -0
  38. data/spec/fixtures/virtual_systems.xml +32 -0
  39. data/spec/lib/palo-alto/client_spec.rb +36 -0
  40. data/spec/lib/palo-alto/common/base_api_spec.rb +121 -0
  41. data/spec/lib/palo-alto/helpers/rest_spec.rb +32 -0
  42. data/spec/lib/palo-alto/models/address_group_spec.rb +43 -0
  43. data/spec/lib/palo-alto/models/address_spec.rb +32 -0
  44. data/spec/lib/palo-alto/models/device_spec.rb +43 -0
  45. data/spec/lib/palo-alto/models/rulebase_spec.rb +23 -0
  46. data/spec/lib/palo-alto/models/virtual_system_spec.rb +53 -0
  47. data/spec/lib/palo-alto/v6/address_api_spec.rb +54 -0
  48. data/spec/lib/palo-alto/v6/address_group_api_spec.rb +79 -0
  49. data/spec/lib/palo-alto/v6/api_spec.rb +4 -0
  50. data/spec/lib/palo-alto/v6/device_api_spec.rb +78 -0
  51. data/spec/lib/palo-alto/v6/virtual_system_api_spec.rb +93 -0
  52. data/spec/spec_helper.rb +26 -0
  53. metadata +221 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bdc9c84ff0f1d1f1e1abde649da826eba4e47288
4
+ data.tar.gz: ae3c9a3e01f7d336561c33e2754423192b6b159b
5
+ SHA512:
6
+ metadata.gz: bd186bd765e99f2398e47dded35b8d79d552691d4d002922e95c17722ba7ae6fbb7eb8a76d44b2ff313e31f70616c473cb5cae534d81d7e4e5756e6dd47fc250
7
+ data.tar.gz: 7274bf968c19fba909e672ffe1ea65a2ca38b474dfe33cfb9cbfb44feff0340d9318714c28e65d139a6af3e33bb55de8fddeeb9694cdb8cb013279b05e62a041
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.swp
16
+ *.swo
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ paloalto-client
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-paloalto-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Justin Karimi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # Ruby::PaloAlto::Client
2
+
3
+ Ruby client to interact with the PaloAlto Firewall and Panamera service
4
+ for Version 6.X of the API.
5
+
6
+ ## Background
7
+
8
+ The following is a notional JSON-based hierarchical representation of the association within the PaloAlto configuration:
9
+
10
+ ```bash
11
+ Device has_many: VirtualSystem
12
+
13
+ VirtualSystem has_many:
14
+ - Address
15
+ - AddressGroup
16
+ - Ruleset
17
+
18
+ AddressGroup has_many: Addresses
19
+ ```
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'ruby-paloalto-client'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install ruby-paloalto-client
36
+
37
+ ## Usage
38
+
39
+ ### Initialization
40
+
41
+ To interface with a PaloAlto API endpoint, start by requiring the PaloAlto library:
42
+
43
+ ```bash
44
+ require 'palo-alto/client'
45
+
46
+ => true
47
+ ```
48
+
49
+ Then, establish a connection to the PaloAlto API with which you wish to interact. For example, this
50
+ PaloAlto device is running version 6 of the API and is located at 'localhost' running on port 443 (secure), and we are connecting with the following:
51
+
52
+ - Host: localhost
53
+ - Port: 443
54
+ - Username: admin
55
+ - Password adminpass
56
+ - SSL: true
57
+ - API Version: 6
58
+
59
+ ```bash
60
+ pa_client = PaloAlto::Client.new host: "localhost",
61
+ port: "443",
62
+ username: "admin",
63
+ password: "adminpass",
64
+ ssl: true,
65
+ api_version: "6"
66
+
67
+ => #<PaloAlto::V6::Api:0x000000026d7340 @host="localhost", @port="443", @ssl=true, @username="admin", @password="adminpass", @auth_key="LUFRPT0va1dzTWZCWjhReWkx354gsUJ0T1VyeFBVRlE9cVpGWUEzNmFmeWtTQU1GcmNHVE0zeHdWRHJKUlhJYXBUMWlXdFBLVnhqND0=">
68
+ ```
69
+
70
+ Once you have your client "pa_client", you can continue to retrieve and manipulate data within the PaloAlto target device.
71
+ Note that queries against the PaloAlto target are performed once for each of the association methods:
72
+
73
+ - .devices
74
+ - .virtual_systems
75
+ - .address_groups
76
+ - .addresses
77
+
78
+ ### Devices
79
+
80
+ To obtain a list of all devices, perform the following:
81
+
82
+ ```bash
83
+ # query device directly
84
+ pa_client.devices
85
+
86
+ => [#<PaloAlto::Models::Device:0x000000021b1550 @name="localhost.localdomain", @ip="127.0.0.1", @virtual_systems=[#<PaloAlto::Models::VirtualSystem:0x000000021b0b00 @name="vsys1", @addresses=[], @address_groups=[], @rulebases=[]>]>]
87
+
88
+ # query device once, parse data in-memory
89
+ devices = pa_client.devices
90
+
91
+ device = devices[0]
92
+ device.virtual_systems
93
+
94
+ vsys = device.virtual_systems[0]
95
+ vsys.addresses
96
+ vsys.address_groups
97
+ vsys.rulesets
98
+ ```
99
+
100
+ ### Virtual Systems
101
+
102
+ To obtain a list of all virtual systems, perform the following:
103
+
104
+ ```bash
105
+ # query device directly
106
+ pa_client.virtual_systems
107
+
108
+ => [#<PaloAlto::Models::VirtualSystem:0x000000027319f8 @name="vsys1", @addresses=[#<PaloAlto::Models::Address:0x0000000272bc60 @name="pool-range", @ip="192.168.80.0/24">, #<PaloAlto::Models::Address:0x0000000272b260 @name="some-ip", @ip="2.2.2.2">], @address_groups=[#<PaloAlto::Models::AddressGroup:0x0000000272a3b0 @name="test", @description="Testing using API", @addresses=[#<PaloAlto::Models::Address:0x00000002729c08 @name="some-ip", @ip="2.2.2.2">]>], @rulebases=[#<PaloAlto::Models::Rulebase:0x00000002729208 @name="DNS">, #<PaloAlto::Models::Rulebase:0x00000002728a88 @name="Allow same network">, #<PaloAlto::Models::Rulebase:0x00000002722138 @name="Deny All">]>]
109
+
110
+ # query device once, parse data in-memory:
111
+ vsystems = pa_client.virtual_systems
112
+
113
+ vsys = vsystems[0]
114
+ vsys.addresses
115
+ vsys.address_groups
116
+
117
+ address_group = vsys.address_groups[0]
118
+ address_group.addresses
119
+ vsys.rulesets
120
+ ```
121
+
122
+ ### Addresses
123
+
124
+ To obtain a list of all addresses, perform the following:
125
+
126
+ ```bash
127
+ # query device directly
128
+ pa_client.addresses
129
+
130
+ => [#<PaloAlto::Models::Address:0x0000000268f158 @name="pool-range", @ip="192.168.80.0/24">, #<PaloAlto::Models::Address:0x0000000268e528 @name="some-ip", @ip="2.2.2.2">]
131
+
132
+ # query device once, parse data in-memory
133
+ addresses = pa_client.addresses
134
+
135
+ address = addresses[0]
136
+ ```
137
+
138
+ ### Address Groups
139
+
140
+ To obtain a list of all address groups, perform the following:
141
+
142
+ ```bash
143
+ # query device directly
144
+ pa_client.address_groups
145
+
146
+ => [#<PaloAlto::Models::AddressGroup:0x00000002661870 @name="test", @description="Testing using API", @addresses=[#<PaloAlto::Models::Address:0x00000002660f88 @name="", @ip="2.2.2.2">]>]
147
+
148
+ # query device once, parse data in-memory
149
+ address_groups = pa_client.address_groups
150
+
151
+ address_group = address_groups[0]
152
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ module PaloAlto
2
+ module Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ require "palo-alto/client/version"
2
+ require "palo-alto/common/base-api"
3
+ require "palo-alto/helpers/rest"
4
+
5
+ module PaloAlto
6
+ module Client
7
+ class << self
8
+ attr_accessor :host, :port, :ssl, :username, :password, :api_version
9
+
10
+ # Create and returns a new PaloAlto::VX::Api instance with the given parameters
11
+ #
12
+ # == Attributes
13
+ #
14
+ # * +host+ - Host where the PaloAlto device is located
15
+ # * +port+ - Port on which the PaloAlto API service is listening
16
+ # * +ssl+ - (Boolean) Whether the API interaction is over SSL
17
+ # * +username+ - Username used to authenticate against the API
18
+ # * +password+ - Password used to authenticate against the API
19
+ # * +api_version+ - Major version of the API being interacted with
20
+ #
21
+ # == Example
22
+ #
23
+ # PaloAlto::Client.new host: 'localhost.localdomain',
24
+ # port: '443',
25
+ # ssl: true,
26
+ # username: 'test_user',
27
+ # password: 'test_pass',
28
+ # api_version: '6'
29
+ def new(host:, port:, ssl: false, username:, password:, api_version:)
30
+ api = nil
31
+
32
+ # check that the API version is implemented
33
+ api_version_file = File.join(File.dirname(__FILE__), "v#{api_version}", "api.rb")
34
+ if File.exist?(api_version_file)
35
+ require api_version_file.sub('.rb', '')
36
+
37
+ api = Object.const_get("PaloAlto::V#{api_version}::Api").new(host: host,
38
+ port: port,
39
+ ssl: ssl,
40
+ username: username,
41
+ password: password)
42
+ else
43
+ raise "API version '#{api_version}' is not implemented"
44
+ end
45
+
46
+ api
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,84 @@
1
+ require "nokogiri"
2
+
3
+ module PaloAlto
4
+ module Common
5
+ class BaseApi
6
+ attr_accessor :host, :port, :ssl, :username, :password, :auth_key
7
+
8
+ # Create and returns a new PaloAlto::V6::Api instance with the given parameters
9
+ #
10
+ # == Attributes
11
+ #
12
+ # * +host+ - Host where the PaloAlto device is located
13
+ # * +port+ - Port on which the PaloAlto API service is listening
14
+ # * +ssl+ - (Boolean) Whether the API interaction is over SSL
15
+ # * +username+ - Username used to authenticate against the API
16
+ # * +password+ - Password used to authenticate against the API
17
+ #
18
+ # == Example
19
+ #
20
+ # PaloAlto::V6::Api.new host: 'localhost.localdomain',
21
+ # port: '443',
22
+ # ssl: true,
23
+ # username: 'test_user',
24
+ # password: 'test_pass'
25
+ def initialize(host:, port:, ssl: false, username:, password:)
26
+ self.host = host
27
+ self.port = port
28
+ self.ssl = ssl
29
+ self.username = username
30
+ self.password = password
31
+
32
+ # attempt to obtain the auth_key
33
+ raise "Exception attempting to obtain the auth_key" if (self.auth_key = get_auth_key).nil?
34
+
35
+ self
36
+ end
37
+
38
+ # Construct and return the API endpoint
39
+ def endpoint
40
+ "http#{('s' if self.ssl)}://#{self.host}:#{self.port}/api/"
41
+ end
42
+
43
+ # Get all the Address objects from the device
44
+ #def addresses
45
+ #end
46
+
47
+ # Get all the AddressGroup objects from the device
48
+ def address_groups
49
+ end
50
+
51
+ # Get all the Policies from the device
52
+ def policies
53
+ end
54
+
55
+ private
56
+
57
+ # Perform a query to the API endpoint for an auth_key based on the credentials provided
58
+ def get_auth_key
59
+ auth_key = nil
60
+
61
+ # establish the required options for the key request
62
+ options = {}
63
+ options[:url] = self.endpoint
64
+ options[:method] = :post
65
+ options[:payload] = { "type" => "keygen",
66
+ "user" => self.username,
67
+ "password" => self.password }
68
+
69
+ # get and parse the response for the key
70
+ http_response = PaloAlto::Helpers::Rest.make_request(options)
71
+ unless http_response.nil?
72
+ xml_data = Nokogiri::XML(http_response)
73
+ if xml_data.xpath('//response/@status').to_s == "success"
74
+ return xml_data.xpath('//response/result/key')[0].content
75
+ else
76
+ return nil
77
+ end
78
+ end
79
+
80
+ auth_key
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,46 @@
1
+ require "rest-client"
2
+
3
+ module PaloAlto
4
+ module Helpers
5
+ class Rest
6
+ # Perform an HTTP request with the respective options
7
+ #
8
+ # == Attributes
9
+ #
10
+ # * +opts+ - Hash of options to include in the request
11
+ #
12
+ # == Input Hash
13
+ #
14
+ # The input hash should contain at a minimum, the following:
15
+ #
16
+ # * +url+ - The URL to send the request to
17
+ # * +method+ - The HTTP method to execute (:get, :post, etc)
18
+ # * +payload+ - Hash of key/value pairs (parameters) to send with the request
19
+ #
20
+ # == Returns
21
+ #
22
+ # Response of the HTML request
23
+ def self.make_request(opts)
24
+ options = {}
25
+ options[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
26
+ options[:headers] = {}
27
+ options[:headers]["User-Agent"] = "ruby-keystone-client"
28
+ options[:headers]["Accept"] = "application/xml"
29
+ options[:headers]["Content-Type"] = "application/xml"
30
+
31
+ # merge in settings from method caller
32
+ options = options.merge(opts)
33
+
34
+ # provide a block to ensure the response is parseable rather than
35
+ # having RestClient throw an exception
36
+ RestClient::Request.execute(options) do |response, request, result|
37
+ if response and response.code == 200
38
+ return response.body
39
+ else
40
+ return nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ module PaloAlto
2
+ module Models
3
+ class AddressGroup
4
+ attr_accessor :name, :description, :addresses
5
+
6
+ # Create and returns a new PaloAlto::Models::AddressGroup instance with the given parameters
7
+ #
8
+ # == Attributes
9
+ #
10
+ # * +name+ - Name of the address group
11
+ # * +description+ - Description for the address group
12
+ # * +addresses+ - Array containing Model::Address instances
13
+ #
14
+ # == Example
15
+ #
16
+ # PaloAlto::Models::AddressGroup.new name: 'address-group-1',
17
+ # description: 'address-group-1-description'
18
+ def initialize(name:, description:, addresses: [])
19
+ self.name = name
20
+ self.description = description
21
+ self.addresses = addresses
22
+
23
+ self
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module PaloAlto
2
+ module Models
3
+ class Address
4
+ attr_accessor :name, :ip
5
+
6
+ # Create and returns a new PaloAlto::Models::Address instance with the given parameters
7
+ #
8
+ # == Attributes
9
+ #
10
+ # * +name+ - Name of the address
11
+ # * +ip+ - IP of the address
12
+ #
13
+ # == Example
14
+ #
15
+ # PaloAlto::Models::Address.new name: 'address-1',
16
+ # ip: '2.2.2.2'
17
+ def initialize(name:, ip:)
18
+ self.name = name
19
+ self.ip = ip
20
+
21
+ self
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module PaloAlto
2
+ module Models
3
+ class Device
4
+ attr_accessor :name, :ip, :virtual_systems
5
+
6
+ # Create and returns a new PaloAlto::Models::Device instance with the given parameters
7
+ #
8
+ # == Attributes
9
+ #
10
+ # * +name+ - Name of the device
11
+ # * +ip+ - Device IP address
12
+ # * +virtual_systems+ - Array containing Model::VirtualSystem instances
13
+ #
14
+ # == Example
15
+ #
16
+ # PaloAlto::Models::Device.new name: 'device-1',
17
+ # ip: '1.2.3.4'
18
+ def initialize(name:, ip:, virtual_systems: [])
19
+ self.name = name
20
+ self.ip = ip
21
+ self.virtual_systems = virtual_systems
22
+
23
+ self
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ module PaloAlto
2
+ module Models
3
+ # Currently, Rulebase is a stand-in for "Security"
4
+ # TODO: Add different Rulebase types (Security, NAT, etc)
5
+ class Rulebase
6
+ attr_accessor :name
7
+
8
+ # Create and returns a new PaloAlto::Models::Rulebase instance with the given parameters
9
+ #
10
+ # == Attributes
11
+ #
12
+ # * +name+ - Name of the rulebase
13
+ #
14
+ # == Example
15
+ #
16
+ # PaloAlto::Models::Rulebase.new name: 'rulebase-1'
17
+ def initialize(name:)
18
+ self.name = name
19
+
20
+ self
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module PaloAlto
2
+ module Models
3
+ class VirtualSystem
4
+ attr_accessor :name, :addresses, :address_groups, :rulebases
5
+
6
+ # Create and returns a new PaloAlto::Models::VirtualSystem instance with the given parameters
7
+ #
8
+ # == Attributes
9
+ #
10
+ # * +name+ - Name of the virtual system
11
+ # * +addresses+ - Array of Model::Address instances
12
+ # * +address_groups+ - Array of Model::AddressGroup instances
13
+ # * +rulebases+ - Array of Model::Rulebase instances
14
+ #
15
+ # == Example
16
+ #
17
+ # PaloAlto::Models::VirtualSystem.new name: 'vsys-1'
18
+ def initialize(name:, addresses: [], address_groups: [], rulebases: [])
19
+ self.name = name
20
+ self.addresses = addresses
21
+ self.address_groups = address_groups
22
+ self.rulebases = rulebases
23
+
24
+ self
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ require "palo-alto/models/address"
2
+
3
+ module PaloAlto
4
+ module V6
5
+ module AddressApi
6
+ # Parse out the addresses from a response to query for addresses
7
+ #
8
+ # == Returns
9
+ #
10
+ # * +Array+ - Array of Models::Address instances
11
+ #
12
+ # == Raises
13
+ #
14
+ # * +Exception+ - Raises an exception if the request is unsuccessful
15
+ def addresses
16
+ address_list = []
17
+
18
+ # configure options for the request
19
+ options = {}
20
+ options[:url] = self.endpoint
21
+ options[:method] = :post
22
+ options[:payload] = { type: "config",
23
+ action: "show",
24
+ key: self.auth_key,
25
+ xpath: "/config/devices/entry/vsys/entry" }
26
+
27
+ html_result = Helpers::Rest.make_request(options)
28
+
29
+ raise "Error obtaining address XML" if html_result.nil?
30
+
31
+ # parse the XML data
32
+ data = Nokogiri::XML(html_result)
33
+
34
+ if data.xpath('//response/@status').to_s == "success"
35
+ data.xpath('//response/result/entry/address/entry').each do |address|
36
+ address_list << PaloAlto::Models::Address.new(name: address.xpath('@name').to_s, ip: address.xpath('ip-netmask').first.content)
37
+ end
38
+ else
39
+ raise "Error in response XML: #{data.inspect}"
40
+ end
41
+
42
+ address_list
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,57 @@
1
+ require "palo-alto/models/address-group"
2
+ require "palo-alto/models/address"
3
+
4
+ module PaloAlto
5
+ module V6
6
+ module AddressGroupApi
7
+ # Parse out the address groups from a response to query for address groups
8
+ #
9
+ # == Returns
10
+ #
11
+ # * +Array+ - Array of Models::AddressGroup instances
12
+ #
13
+ # == Raises
14
+ #
15
+ # * +Exception+ - Raises an exception if the request is unsuccessful
16
+ def address_groups
17
+ address_group_list = []
18
+
19
+ # configure options for the request
20
+ options = {}
21
+ options[:url] = self.endpoint
22
+ options[:method] = :post
23
+ options[:payload] = { type: "config",
24
+ action: "show",
25
+ key: self.auth_key,
26
+ xpath: "/config/devices/entry/vsys/entry" }
27
+
28
+ html_result = Helpers::Rest.make_request(options)
29
+
30
+ raise "Error obtaining address group XML" if html_result.nil?
31
+
32
+ # parse the XML data
33
+ data = Nokogiri::XML(html_result)
34
+
35
+ if data.xpath('//response/@status').to_s == "success"
36
+ data.xpath('//response/result/entry/address-group/entry').each do |address_group_entry|
37
+ address_group = PaloAlto::Models::AddressGroup.new(name: address_group_entry.xpath('@name').to_s,
38
+ description: address_group_entry.xpath('description').first.content)
39
+
40
+ # get all address members for the address group
41
+ address_group_entry.xpath('*').each do |address_entry|
42
+ if (specific_address = address_entry.xpath('member')).length > 0
43
+ address_group.addresses << PaloAlto::Models::Address.new(name: specific_address[0].content, ip: "")
44
+ end
45
+ end
46
+
47
+ address_group_list << address_group
48
+ end
49
+ else
50
+ raise "Error in response XML: #{data.inspect}"
51
+ end
52
+
53
+ address_group_list
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,16 @@
1
+ require "palo-alto/v6/device-api"
2
+ require "palo-alto/v6/virtual-system-api"
3
+ require "palo-alto/v6/address-api"
4
+ require "palo-alto/v6/address-group-api"
5
+
6
+ module PaloAlto
7
+ module V6
8
+ class Api < Common::BaseApi
9
+ # include required APIs for functionality
10
+ include PaloAlto::V6::DeviceApi
11
+ include PaloAlto::V6::VirtualSystemApi
12
+ include PaloAlto::V6::AddressApi
13
+ include PaloAlto::V6::AddressGroupApi
14
+ end
15
+ end
16
+ end