ruby-paloalto-client 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/lib/palo_alto/client/version.rb +1 -1
- data/lib/palo_alto/models/zone.rb +22 -0
- data/lib/palo_alto/v6/api.rb +2 -0
- data/lib/palo_alto/v6/zone_api.rb +46 -0
- data/spec/fixtures/blank_zones.xml +6 -0
- data/spec/fixtures/zones.xml +18 -0
- data/spec/lib/palo-alto/models/zone_spec.rb +23 -0
- data/spec/lib/palo-alto/v6/zone_api_spec.rb +54 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e02a369bdffd33aae3c9e09ed5c7c12144085507
|
4
|
+
data.tar.gz: ef555e5807be0c37aff0141bbf8b9ad0543d83a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5813efa8c094d8f3e5f3f84ed002163bffa23b57b3ac594560875ad5fe2678895ad5289049754de220855b3e7d07c19f6ee515f2dd8e76cb074f496d8e5e5b54
|
7
|
+
data.tar.gz: ee5e1550103d91610627bd32e7e8cd8c139e8731af6e91b4d6927b015fe4a5b29d02e223b2def1acc5fe426d3da71e39dbe74288f274cb42248314d2832db9a3
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PaloAlto
|
2
|
+
module Models
|
3
|
+
class Zone
|
4
|
+
attr_accessor :name
|
5
|
+
|
6
|
+
# Create and returns a new PaloAlto::Models::Zone instance with the given parameters
|
7
|
+
#
|
8
|
+
# == Attributes
|
9
|
+
#
|
10
|
+
# * +name+ - Name of the zone
|
11
|
+
#
|
12
|
+
# == Example
|
13
|
+
#
|
14
|
+
# PaloAlto::Models::Zone.new name: 'ingress'
|
15
|
+
def initialize(name:)
|
16
|
+
self.name = name
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/palo_alto/v6/api.rb
CHANGED
@@ -5,6 +5,7 @@ require "palo_alto/v6/address_group_api"
|
|
5
5
|
require "palo_alto/v6/log_api"
|
6
6
|
require "palo_alto/v6/security_rule_api"
|
7
7
|
require "palo_alto/v6/commit_api"
|
8
|
+
require "palo_alto/v6/zone_api"
|
8
9
|
|
9
10
|
module PaloAlto
|
10
11
|
module V6
|
@@ -17,6 +18,7 @@ module PaloAlto
|
|
17
18
|
include PaloAlto::V6::LogApi
|
18
19
|
include PaloAlto::V6::SecurityRuleApi
|
19
20
|
include PaloAlto::V6::CommitApi
|
21
|
+
include PaloAlto::V6::ZoneApi
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "palo_alto/models/zone"
|
2
|
+
|
3
|
+
module PaloAlto
|
4
|
+
module V6
|
5
|
+
module ZoneApi
|
6
|
+
# Parse out the zones from a response to query for zones
|
7
|
+
#
|
8
|
+
# == Returns
|
9
|
+
#
|
10
|
+
# * +Array+ - Array of Models::Zone instances
|
11
|
+
#
|
12
|
+
# == Raises
|
13
|
+
#
|
14
|
+
# * +Exception+ - Raises an exception if the request is unsuccessful
|
15
|
+
def zones
|
16
|
+
zone_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/zone" }
|
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/zone/entry').each do |zone|
|
36
|
+
zone_list << PaloAlto::Models::Zone.new(name: zone.xpath('@name').to_s)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
raise "Error in response XML: #{data.inspect}"
|
40
|
+
end
|
41
|
+
|
42
|
+
zone_list
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<response status="success">
|
2
|
+
<result>
|
3
|
+
<zone>
|
4
|
+
<entry name="inside">
|
5
|
+
<network>
|
6
|
+
<virtual-wire/>
|
7
|
+
</network>
|
8
|
+
</entry>
|
9
|
+
<entry name="outside">
|
10
|
+
<network>
|
11
|
+
<layer3>
|
12
|
+
<member>ethernet1/3</member>
|
13
|
+
</layer3>
|
14
|
+
</network>
|
15
|
+
</entry>
|
16
|
+
</zone>
|
17
|
+
</result>
|
18
|
+
</response>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "palo_alto/models/zone"
|
2
|
+
|
3
|
+
describe "PaloAlto::Models::Zone" do
|
4
|
+
let(:name) { "ingress" }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@zone = PaloAlto::Models::Zone.new(name: name)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a name attribute" do
|
11
|
+
expect(@zone).to respond_to(:name)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".initialize" do
|
15
|
+
it "returns a PaloAlto::Models::Zone instance" do
|
16
|
+
expect(@zone).to be_instance_of(PaloAlto::Models::Zone)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "assigns name" do
|
20
|
+
expect(@zone.name).to eq(name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "palo_alto/v6/zone_api"
|
2
|
+
require "palo_alto/helpers/rest"
|
3
|
+
|
4
|
+
describe "PaloAlto::V6::ZoneApi" do
|
5
|
+
# dummy class to demonstrate functionality
|
6
|
+
class DummyClass
|
7
|
+
extend PaloAlto::V6::ZoneApi
|
8
|
+
|
9
|
+
def self.endpoint
|
10
|
+
"https://some.host:80/api/"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.auth_key
|
14
|
+
"OIGHOEIHT()*#Y"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".zones" do
|
19
|
+
let(:zone_xml) { File.open(fixture_file("zones.xml")).read }
|
20
|
+
let(:blank_zone_xml) { File.open(fixture_file("blank_zones.xml")).read }
|
21
|
+
|
22
|
+
describe "when zones exist" do
|
23
|
+
before do
|
24
|
+
expect(PaloAlto::Helpers::Rest).to receive(:make_request).and_return(zone_xml)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "parses the XML response into the required format" do
|
28
|
+
expect(DummyClass.zones).to be_instance_of(Array)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when no zones exist" do
|
33
|
+
before do
|
34
|
+
expect(PaloAlto::Helpers::Rest).to receive(:make_request).and_return(blank_zone_xml)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns an empty array" do
|
38
|
+
expect(DummyClass.zones).to eq([])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "when errors occur" do
|
43
|
+
it "raises an exception if an error occurred obtaining XML" do
|
44
|
+
expect(PaloAlto::Helpers::Rest).to receive(:make_request).and_raise(Exception)
|
45
|
+
expect{ DummyClass.zones }.to raise_exception
|
46
|
+
end
|
47
|
+
|
48
|
+
it "raises an exception if an error occurred reported in the XML" do
|
49
|
+
expect(PaloAlto::Helpers::Rest).to receive(:make_request).and_return(File.open(fixture_file("failure.xml")).read)
|
50
|
+
expect{ DummyClass.zones }.to raise_exception
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-paloalto-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Karimi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: crack
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- lib/palo_alto/models/system_log_entry.rb
|
150
150
|
- lib/palo_alto/models/traffic_log_entry.rb
|
151
151
|
- lib/palo_alto/models/virtual_system.rb
|
152
|
+
- lib/palo_alto/models/zone.rb
|
152
153
|
- lib/palo_alto/v6/address_api.rb
|
153
154
|
- lib/palo_alto/v6/address_group_api.rb
|
154
155
|
- lib/palo_alto/v6/api.rb
|
@@ -157,6 +158,7 @@ files:
|
|
157
158
|
- lib/palo_alto/v6/log_api.rb
|
158
159
|
- lib/palo_alto/v6/security_rule_api.rb
|
159
160
|
- lib/palo_alto/v6/virtual_system_api.rb
|
161
|
+
- lib/palo_alto/v6/zone_api.rb
|
160
162
|
- ruby-paloalto-client.gemspec
|
161
163
|
- spec/fixtures/address_group_missing_description.xml
|
162
164
|
- spec/fixtures/address_groups.xml
|
@@ -166,6 +168,7 @@ files:
|
|
166
168
|
- spec/fixtures/blank_devices.xml
|
167
169
|
- spec/fixtures/blank_traffic_logs.xml
|
168
170
|
- spec/fixtures/blank_virtual_systems.xml
|
171
|
+
- spec/fixtures/blank_zones.xml
|
169
172
|
- spec/fixtures/commit_complete.xml
|
170
173
|
- spec/fixtures/commit_in_progress.xml
|
171
174
|
- spec/fixtures/devices.xml
|
@@ -188,6 +191,7 @@ files:
|
|
188
191
|
- spec/fixtures/unsupported_log_attribute.xml
|
189
192
|
- spec/fixtures/unsupported_logs.xml
|
190
193
|
- spec/fixtures/virtual_systems.xml
|
194
|
+
- spec/fixtures/zones.xml
|
191
195
|
- spec/lib/palo-alto/client_spec.rb
|
192
196
|
- spec/lib/palo-alto/common/base_api_spec.rb
|
193
197
|
- spec/lib/palo-alto/helpers/rest_spec.rb
|
@@ -199,6 +203,7 @@ files:
|
|
199
203
|
- spec/lib/palo-alto/models/system_log_entry_spec.rb
|
200
204
|
- spec/lib/palo-alto/models/traffic_log_entry_spec.rb
|
201
205
|
- spec/lib/palo-alto/models/virtual_system_spec.rb
|
206
|
+
- spec/lib/palo-alto/models/zone_spec.rb
|
202
207
|
- spec/lib/palo-alto/v6/address_api_spec.rb
|
203
208
|
- spec/lib/palo-alto/v6/address_group_api_spec.rb
|
204
209
|
- spec/lib/palo-alto/v6/api_spec.rb
|
@@ -207,6 +212,7 @@ files:
|
|
207
212
|
- spec/lib/palo-alto/v6/log_api_spec.rb
|
208
213
|
- spec/lib/palo-alto/v6/security_rule_api_spec.rb
|
209
214
|
- spec/lib/palo-alto/v6/virtual_system_api_spec.rb
|
215
|
+
- spec/lib/palo-alto/v6/zone_api_spec.rb
|
210
216
|
- spec/spec_helper.rb
|
211
217
|
homepage: ''
|
212
218
|
licenses:
|
@@ -241,6 +247,7 @@ test_files:
|
|
241
247
|
- spec/fixtures/blank_devices.xml
|
242
248
|
- spec/fixtures/blank_traffic_logs.xml
|
243
249
|
- spec/fixtures/blank_virtual_systems.xml
|
250
|
+
- spec/fixtures/blank_zones.xml
|
244
251
|
- spec/fixtures/commit_complete.xml
|
245
252
|
- spec/fixtures/commit_in_progress.xml
|
246
253
|
- spec/fixtures/devices.xml
|
@@ -263,6 +270,7 @@ test_files:
|
|
263
270
|
- spec/fixtures/unsupported_log_attribute.xml
|
264
271
|
- spec/fixtures/unsupported_logs.xml
|
265
272
|
- spec/fixtures/virtual_systems.xml
|
273
|
+
- spec/fixtures/zones.xml
|
266
274
|
- spec/lib/palo-alto/client_spec.rb
|
267
275
|
- spec/lib/palo-alto/common/base_api_spec.rb
|
268
276
|
- spec/lib/palo-alto/helpers/rest_spec.rb
|
@@ -274,6 +282,7 @@ test_files:
|
|
274
282
|
- spec/lib/palo-alto/models/system_log_entry_spec.rb
|
275
283
|
- spec/lib/palo-alto/models/traffic_log_entry_spec.rb
|
276
284
|
- spec/lib/palo-alto/models/virtual_system_spec.rb
|
285
|
+
- spec/lib/palo-alto/models/zone_spec.rb
|
277
286
|
- spec/lib/palo-alto/v6/address_api_spec.rb
|
278
287
|
- spec/lib/palo-alto/v6/address_group_api_spec.rb
|
279
288
|
- spec/lib/palo-alto/v6/api_spec.rb
|
@@ -282,4 +291,5 @@ test_files:
|
|
282
291
|
- spec/lib/palo-alto/v6/log_api_spec.rb
|
283
292
|
- spec/lib/palo-alto/v6/security_rule_api_spec.rb
|
284
293
|
- spec/lib/palo-alto/v6/virtual_system_api_spec.rb
|
294
|
+
- spec/lib/palo-alto/v6/zone_api_spec.rb
|
285
295
|
- spec/spec_helper.rb
|