palo_alto 0.1.9 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75f890f237714b8ab90594551c7a7ae27ad896b0d98f8fa95753c45402534893
4
- data.tar.gz: 0be5164b8a2ce37a63c17c6e1a3b17234f90a0fadbf7bd6a2e12c87efded1927
3
+ metadata.gz: 7442c2cf207b59a2ac451b8f2fe35e7333f5486b8fa8b124887df6dbec5f7501
4
+ data.tar.gz: b27f957f7e15285d6755d95136f3e8bacdb45ffa03bbcba9ee5274b5f9d651fd
5
5
  SHA512:
6
- metadata.gz: 40e2437add174f53ccaefa2176b49ce5c4cb600c6cac2f1815bccbb039eac5c63eec25f0836630d1cfbe3a84b83a660ee7ec40ff9112c048879dd12496a6b321
7
- data.tar.gz: fd6b3ca8f123ce3c28d4b60dd0ca02bc5d8ea489705ee7851ed79e9deeb08bde7de45bbf1bebf54aaa816bc605658e3eaad9befaedad3a770cebf75070ab39a4
6
+ metadata.gz: 9dafa319006719982ec6b910c0262c32f19e13019b7f90bb8ed93b3b2d0ece98ac5913b55d40357239860f800f6d3bc66961fdb85a14fd46d0fddadc3acdfd5b
7
+ data.tar.gz: 26418cfc13c83588cc1349060d55fb9adf716f2d18a1a6ef96b7466a12e00f0d1c21043fcc7de42964515a2d386d32ac3fb316cc171ff2f77a4202bd9c6eb010
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaloAlto
4
- VERSION = '0.1.9'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/palo_alto.rb CHANGED
@@ -99,7 +99,15 @@ module PaloAlto
99
99
 
100
100
  thread[:http].start unless thread[:http].started?
101
101
 
102
- response = thread[:http].post('/api/', URI.encode_www_form(options[:payload]), options[:headers])
102
+ payload = options[:payload]
103
+ response = if payload.values.any? { |value| [IO, StringIO].any? { |t| value.is_a?(t) } }
104
+ payload.values.select { |value| [IO, StringIO].any? { |t| value.is_a?(t) } }.each(&:rewind)
105
+ post_req = Net::HTTP::Post.new('/api/', options[:headers])
106
+ post_req.set_form payload.map { |k, v| [k.to_s, v] }, 'multipart/form-data'
107
+ thread[:http].request(post_req)
108
+ else
109
+ thread[:http].post('/api/', URI.encode_www_form(payload), options[:headers])
110
+ end
103
111
 
104
112
  case response.code
105
113
  when '200'
@@ -189,13 +197,14 @@ module PaloAlto
189
197
  begin
190
198
  Helpers::Rest.execute(payload, headers: { 'X-PAN-KEY': auth_key })
191
199
  rescue TemporaryException => e
192
- dont_continue_at = [
200
+ dont_retry_at = [
193
201
  'Partial revert is not allowed. Full system commit must be completed.',
194
202
  'Config for scope ',
195
203
  'Config is not currently locked for scope ',
196
- 'Commit lock is not currently held by'
204
+ 'Commit lock is not currently held by',
205
+ 'You already own a config lock for scope '
197
206
  ]
198
- if retried || dont_continue_at.any? { |x| e.message.start_with?(x) }
207
+ if retried || dont_retry_at.any? { |x| e.message.start_with?(x) }
199
208
  raise e
200
209
  else
201
210
  warn "Got error #{e.inspect}; retrying" if XML.debug.include?(:warnings)
@@ -266,14 +275,12 @@ module PaloAlto
266
275
  # will execute block if given and unlock afterwards. returns false if lock could not be aquired
267
276
  def lock(area:, comment: nil, type: nil, location: nil)
268
277
  if block_given?
269
- if lock(area: area, comment: comment, type: type, location: location)
270
- begin
271
- return yield
272
- ensure
273
- unlock(area: area, type: type, location: location)
274
- end
275
- else
276
- return false
278
+ return false unless lock(area: area, comment: comment, type: type, location: location)
279
+
280
+ begin
281
+ return yield
282
+ ensure
283
+ unlock(area: area, type: type, location: location)
277
284
  end
278
285
  end
279
286
 
@@ -309,8 +316,16 @@ module PaloAlto
309
316
  end
310
317
 
311
318
  def check_for_changes(usernames: [XML.username])
312
- result = Op.new.execute({ show: { config: { list: { 'change-summary': { partial: { admin: usernames } } } } } })
313
- result.xpath('response/result/summary/device-group/member').map(&:inner_text)
319
+ cmd = if usernames
320
+ { show: { config: { list: { 'change-summary': { partial: { admin: usernames } } } } } }
321
+ else
322
+ { show: { config: { list: 'change-summary' } } }
323
+ end
324
+ result = Op.new.execute(cmd)
325
+ {
326
+ device_groups: result.xpath('response/result/summary/device-group/member').map(&:inner_text),
327
+ templates: result.xpath('response/result/summary/template/member').map(&:inner_text)
328
+ }
314
329
  end
315
330
 
316
331
  def wait_for_job_completion(job_id, wait: 5, timeout: 300)
@@ -363,8 +378,6 @@ module PaloAlto
363
378
  # attempt to obtain the auth_key
364
379
  # raise 'Exception attempting to obtain the auth_key' if (self.class.auth_key = get_auth_key).nil?
365
380
  self.class.get_auth_key
366
-
367
- self
368
381
  end
369
382
 
370
383
  # Perform a query to the API endpoint for an auth_key based on the credentials provided
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: palo_alto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Roesner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-21 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri