ruby-jss 1.3.3 → 1.6.0b1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-jss might be problematic. Click here for more details.

Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +142 -0
  3. data/THANKS.md +3 -2
  4. data/lib/jamf.rb +18 -17
  5. data/lib/jamf/api/base_classes/collection_resource.rb +613 -0
  6. data/lib/jamf/api/{abstract_classes → base_classes}/json_object.rb +109 -101
  7. data/lib/jamf/api/{abstract_classes → base_classes}/prestage.rb +55 -30
  8. data/lib/jamf/api/{abstract_classes → base_classes}/resource.rb +10 -6
  9. data/lib/jamf/api/{abstract_classes → base_classes}/singleton_resource.rb +4 -3
  10. data/lib/jamf/api/connection.rb +13 -9
  11. data/lib/jamf/api/connection/api_error.rb +8 -8
  12. data/lib/jamf/api/connection/token.rb +36 -15
  13. data/lib/jamf/api/json_objects/device_enrollment_device.rb +14 -7
  14. data/lib/jamf/api/json_objects/{location.rb → device_enrollment_device_sync_state.rb} +27 -41
  15. data/lib/jamf/api/json_objects/device_enrollment_sync_status.rb +1 -1
  16. data/lib/jamf/api/json_objects/{attachment.rb → locale.rb} +14 -23
  17. data/lib/jamf/api/json_objects/md_prestage_name.rb +1 -1
  18. data/lib/jamf/api/json_objects/md_prestage_names.rb +2 -2
  19. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +50 -1
  20. data/lib/jamf/api/json_objects/prestage_assignment.rb +2 -2
  21. data/lib/jamf/api/json_objects/prestage_location.rb +3 -3
  22. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +7 -7
  23. data/lib/jamf/api/json_objects/prestage_scope.rb +1 -1
  24. data/lib/jamf/api/{resources/collection_resources → json_objects}/time_zone.rb +9 -23
  25. data/lib/jamf/api/mixins/{abstract.rb → base_class.rb} +34 -16
  26. data/lib/jamf/api/mixins/bulk_deletable.rb +27 -6
  27. data/lib/jamf/api/mixins/change_log.rb +201 -51
  28. data/lib/jamf/api/{resources/collection_resources/computer.rb → mixins/filterable.rb} +19 -17
  29. data/lib/jamf/api/mixins/pageable.rb +208 -0
  30. data/lib/jamf/api/{json_objects/installed_application.rb → mixins/sortable.rb} +33 -33
  31. data/lib/jamf/api/resources/collection_resources/building.rb +16 -9
  32. data/lib/jamf/api/resources/collection_resources/category.rb +5 -4
  33. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +12 -5
  34. data/lib/jamf/api/resources/collection_resources/department.rb +1 -3
  35. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +13 -13
  36. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +11 -3
  37. data/lib/jamf/api/resources/collection_resources/mobile_device_prestage.rb +25 -23
  38. data/lib/jamf/api/resources/collection_resources/script.rb +61 -25
  39. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +15 -5
  40. data/lib/jamf/api/resources/singleton_resources/locales.rb +155 -0
  41. data/lib/jamf/api/resources/singleton_resources/time_zones.rb +213 -0
  42. data/lib/jamf/client.rb +3 -3
  43. data/lib/jamf/client/management_action.rb +2 -3
  44. data/lib/jamf/composer.rb +2 -2
  45. data/lib/jamf/utility.rb +35 -7
  46. data/lib/jamf/validate.rb +63 -24
  47. data/lib/jamf/version.rb +1 -1
  48. data/lib/jss.rb +2 -2
  49. data/lib/jss/api_connection.rb +114 -406
  50. data/lib/jss/api_object.rb +10 -20
  51. data/lib/jss/api_object/advanced_search.rb +27 -26
  52. data/lib/jss/api_object/app_store_country_codes.rb +298 -0
  53. data/lib/jss/api_object/categorizable.rb +1 -1
  54. data/lib/jss/api_object/computer.rb +13 -0
  55. data/lib/jss/api_object/configuration_profile.rb +61 -5
  56. data/lib/jss/api_object/directory_binding_type.rb +66 -60
  57. data/lib/jss/api_object/directory_binding_type/active_directory.rb +71 -34
  58. data/lib/jss/api_object/directory_binding_type/admitmac.rb +536 -467
  59. data/lib/jss/api_object/directory_binding_type/centrify.rb +21 -7
  60. data/lib/jss/api_object/directory_binding_type/open_directory.rb +4 -4
  61. data/lib/jss/api_object/distribution_point.rb +2 -2
  62. data/lib/jss/api_object/dock_item.rb +102 -96
  63. data/lib/jss/api_object/ebook.rb +1 -2
  64. data/lib/jss/api_object/extendable.rb +1 -1
  65. data/lib/jss/api_object/extension_attribute.rb +4 -3
  66. data/lib/jss/api_object/group.rb +33 -2
  67. data/lib/jss/api_object/mac_application.rb +107 -8
  68. data/lib/jss/api_object/network_segment.rb +45 -13
  69. data/lib/jss/api_object/patch_source.rb +10 -9
  70. data/lib/jss/api_object/policy.rb +267 -28
  71. data/lib/jss/api_object/printer.rb +10 -4
  72. data/lib/jss/api_object/scopable.rb +10 -15
  73. data/lib/jss/api_object/scopable/scope.rb +389 -73
  74. data/lib/jss/api_object/script.rb +242 -352
  75. data/lib/jss/api_object/self_servable.rb +17 -9
  76. data/lib/jss/api_object/uploadable.rb +1 -1
  77. data/lib/jss/api_object/user.rb +43 -2
  78. data/lib/jss/api_object/vpp_account.rb +209 -0
  79. data/lib/jss/api_object/vppable.rb +169 -13
  80. data/lib/jss/client/management_action.rb +1 -2
  81. data/lib/jss/composer.rb +2 -2
  82. data/lib/jss/exceptions.rb +3 -0
  83. data/lib/jss/server.rb +15 -0
  84. data/lib/jss/utility.rb +213 -45
  85. data/lib/jss/validate.rb +53 -10
  86. data/lib/jss/version.rb +1 -1
  87. metadata +50 -66
  88. data/lib/jamf/api/abstract_classes/advanced_search.rb +0 -86
  89. data/lib/jamf/api/abstract_classes/collection_resource.rb +0 -433
  90. data/lib/jamf/api/abstract_classes/generic_reference.rb +0 -145
  91. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +0 -126
  92. data/lib/jamf/api/json_objects/account_prefs.rb +0 -79
  93. data/lib/jamf/api/json_objects/android_details.rb +0 -139
  94. data/lib/jamf/api/json_objects/appletv_details.rb +0 -110
  95. data/lib/jamf/api/json_objects/cellular_network.rb +0 -151
  96. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +0 -67
  97. data/lib/jamf/api/json_objects/criterion.rb +0 -152
  98. data/lib/jamf/api/json_objects/extension_attribute_value.rb +0 -128
  99. data/lib/jamf/api/json_objects/installed_certificate.rb +0 -53
  100. data/lib/jamf/api/json_objects/installed_configuration_profile.rb +0 -67
  101. data/lib/jamf/api/json_objects/installed_ebook.rb +0 -58
  102. data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +0 -59
  103. data/lib/jamf/api/json_objects/ios_details.rb +0 -244
  104. data/lib/jamf/api/json_objects/mobile_device_details.rb +0 -219
  105. data/lib/jamf/api/json_objects/mobile_device_security.rb +0 -101
  106. data/lib/jamf/api/json_objects/purchasing_data.rb +0 -125
  107. data/lib/jamf/api/mixins/locatable.rb +0 -124
  108. data/lib/jamf/api/mixins/referable.rb +0 -92
  109. data/lib/jamf/api/resources/collection_resources/account.rb +0 -163
  110. data/lib/jamf/api/resources/collection_resources/advanced_mobile_device_search.rb +0 -52
  111. data/lib/jamf/api/resources/collection_resources/advanced_user_search.rb +0 -52
  112. data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +0 -45
  113. data/lib/jamf/api/resources/collection_resources/mobile_device.rb +0 -315
  114. data/lib/jamf/api/resources/collection_resources/site.rb +0 -77
  115. data/lib/jamf/api/resources/singleton_resources/authorization.rb +0 -88
  116. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +0 -139
  117. data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +0 -95
@@ -435,9 +435,10 @@ module JSS
435
435
  @starting_address <= thing.range.begin && @ending_address >= thing.range.end
436
436
  else
437
437
  thing = IPAddr.new thing.to_s
438
- range.include? thing
438
+ range.cover? thing
439
439
  end
440
440
  end
441
+ alias cover? include?
441
442
 
442
443
  ### Does this network segment equal another?
443
444
  ### equality means the ranges are equal
@@ -459,9 +460,17 @@ module JSS
459
460
  ### @return [void]
460
461
  ###
461
462
  def building=(newval)
462
- new = JSS::Building.all.select { |b| (b[:id] == newval) || (b[:name] == newval) }[0]
463
- raise JSS::MissingDataError, "No building matching '#{newval}'" unless new
464
- @building = new[:name]
463
+ new =
464
+ if newval.to_s.empty?
465
+ JSS::BLANK
466
+ else
467
+ id = JSS::Building.valid_id newval
468
+ raise JSS::MissingDataError, "No building matching '#{newval}'" unless id
469
+
470
+ JSS::Building.map_all_ids_to(:name)[id]
471
+ end
472
+
473
+ @building = new
465
474
  @need_to_update = true
466
475
  end
467
476
 
@@ -484,9 +493,16 @@ module JSS
484
493
  ### @return [void]
485
494
  ###
486
495
  def department=(newval)
487
- new = JSS::Department.all.select { |b| (b[:id] == newval) || (b[:name] == newval) }[0]
488
- raise JSS::MissingDataError, "No department matching '#{newval}' in the JSS" unless new
489
- @department = new[:name]
496
+ new =
497
+ if newval.to_s.empty?
498
+ JSS::BLANK
499
+ else
500
+ id = JSS::Department.valid_id newval
501
+ raise JSS::MissingDataError , "No department matching '#{newval}' in the JSS" unless id
502
+
503
+ JSS::Department.map_all_ids_to(:name)[id]
504
+ end
505
+ @department = new
490
506
  @need_to_update = true
491
507
  end
492
508
 
@@ -531,9 +547,17 @@ module JSS
531
547
  ### @return [void]
532
548
  ###
533
549
  def netboot_server=(newval)
534
- new = JSS::NetbootServer.all.select { |b| (b[:id] == newval) || (b[:name] == newval) }[0]
535
- raise JSS::MissingDataError, "No netboot_server matching '#{newval}' in the JSS" unless new
536
- @netboot_server = new[:name]
550
+ new =
551
+ if newval.to_s.empty?
552
+ JSS::BLANK
553
+ else
554
+ id = JSS::NetBootServer.valid_id newval
555
+ raise JSS::MissingDataError, "No netboot_server matching '#{newval}' in the JSS" unless id
556
+
557
+ JSS::NetbootServer.map_all_ids_to(:name)[id]
558
+ end
559
+
560
+ @netboot_server = new
537
561
  @need_to_update = true
538
562
  end
539
563
 
@@ -544,9 +568,17 @@ module JSS
544
568
  ### @return [void]
545
569
  ###
546
570
  def swu_server=(newval)
547
- new = JSS::SoftwareUpdateServer.all.select { |b| (b[:id] == newval) || (b[:name] == newval) }[0]
548
- raise JSS::MissingDataError, "No swu_server matching '#{newval}' in the JSS" unless new
549
- @swu_server = new[:name]
571
+ new =
572
+ if newval.to_s.empty?
573
+ JSS::BLANK
574
+ else
575
+ id = JSS::SoftwareUpdateServer.valid_id newval
576
+ raise JSS::MissingDataError, "No swu_server matching '#{newval}' in the JSS" unless id
577
+
578
+ JSS::SoftwareUpdateServer.map_all_ids_to(:name)[id]
579
+ end
580
+
581
+ @swu_server = new
550
582
  @need_to_update = true
551
583
  end
552
584
 
@@ -120,30 +120,31 @@ module JSS
120
120
 
121
121
  # Fetch either an internal or external patch source
122
122
  #
123
- # BUG: there's an API bug: fetching a non-existent ids
123
+ # BUG: there's an API bug: fetching a non-existent
124
124
  # which is why we rescue internal server errors.
125
125
  #
126
126
  # @see APIObject.fetch
127
127
  #
128
- def self.fetch(arg, api: JSS.api)
128
+ def self.fetch(searchterm = nil, **args)
129
129
  if self == JSS::PatchSource
130
130
  begin
131
- fetched = JSS::PatchInternalSource.fetch arg, api: api
132
- rescue RestClient::ResourceNotFound, RestClient::InternalServerError, JSS::NoSuchItemError
131
+ fetched = JSS::PatchInternalSource.fetch searchterm, **args
132
+ rescue
133
133
  fetched = nil
134
134
  end
135
135
  unless fetched
136
136
  begin
137
- fetched = JSS::PatchExternalSource.fetch arg, api: api
138
- rescue RestClient::ResourceNotFound, RestClient::InternalServerError, JSS::NoSuchItemError
137
+ fetched = JSS::PatchExternalSource.fetch searchterm, **args
138
+ rescue
139
139
  raise JSS::NoSuchItemError, 'No matching PatchSource found'
140
140
  end
141
141
  end
142
142
  return fetched
143
143
  end # if self == JSS::PatchSource
144
+
144
145
  begin
145
- super
146
- rescue RestClient::ResourceNotFound, RestClient::InternalServerError, JSS::NoSuchItemError
146
+ super searchterm, **args
147
+ rescue JSS::NoSuchItemError
147
148
  raise JSS::NoSuchItemError, "No matching #{self::RSRC_OBJECT_KEY} found"
148
149
  end
149
150
  end
@@ -211,7 +212,7 @@ module JSS
211
212
  begin
212
213
  # TODO: remove this and adjust parsing when jamf fixes the JSON
213
214
  raw = JSS::XMLWorkaround.data_via_xml(rsrc, AVAILABLE_TITLES_DATA_MAP, api)
214
- rescue RestClient::ResourceNotFound
215
+ rescue JSS::NoSuchItemError
215
216
  return []
216
217
  end
217
218
 
@@ -148,6 +148,12 @@ module JSS
148
148
  monthly: 'Once every month'
149
149
  }.freeze
150
150
 
151
+ RETRY_EVENTS = {
152
+ none: 'none',
153
+ checkin: 'check-in',
154
+ trigger: 'trigger'
155
+ }.freeze
156
+
151
157
  RESTART_WHEN = {
152
158
  if_pkg_requires: 'Restart if a package or update requires it',
153
159
  now: 'Restart immediately',
@@ -257,14 +263,14 @@ module JSS
257
263
  }.freeze
258
264
 
259
265
  LOG_FLUSH_INTERVAL_PERIODS = {
260
- day: 'Day',
261
- days: 'Day',
262
- week: 'Week',
263
- weeks: 'Week',
264
- month: 'Month',
265
- months: 'Month',
266
- year: 'Year',
267
- years: 'Year'
266
+ day: 'Days',
267
+ days: 'Days',
268
+ week: 'Weeks',
269
+ weeks: 'Weeks',
270
+ month: 'Months',
271
+ months: 'Months',
272
+ year: 'Years',
273
+ years: 'Years'
268
274
  }.freeze
269
275
 
270
276
  # the object type for this object in
@@ -281,6 +287,86 @@ module JSS
281
287
  # How is the category stored in the API data?
282
288
  CATEGORY_DATA_TYPE = Hash
283
289
 
290
+ # All valid script parameters
291
+ SCRIPT_PARAMETERS_AVAILABLE = %i[parameter4 parameter5 parameter6 parameter7 parameter8 parameter9 parameter10 parameter11].freeze
292
+
293
+ # Class Methods
294
+ ######################
295
+
296
+ # Flush logs for a given policy older than some number of days, weeks,
297
+ # months or years, possibly limited to one or more computers.
298
+ #
299
+ # With no parameters, flushes all logs for the policy for all computers.
300
+ #
301
+ # NOTE: Currently the API doesn't have a way to flush only failed policies.
302
+ #
303
+ # WARNING: Log flushing can take a long time, and the API call doesnt return
304
+ # until its finished. The connection timeout will be temporarily raised to
305
+ # 30 minutes, unless it's already higher.
306
+ #
307
+ # @param policy[Integer,String] The id or name of the policy to flush
308
+ #
309
+ # @param older_than[Integer] 0, 1, 2, 3, or 6
310
+ #
311
+ # @param period[Symbol] :days, :weeks, :months, or :years
312
+ #
313
+ # @param computers[Array<Integer,String>] Identifiers of the target computers
314
+ # either ids, names, SNs, macaddrs, or UDIDs. If omitted, flushes logs for
315
+ # all computers
316
+ #
317
+ # @param api [JSS::APIConnection] the API connection to use.
318
+ #
319
+ # @return [void]
320
+ #
321
+ def self.flush_logs(policy, older_than: 0, period: :days, computers: [], api: JSS.api)
322
+ orig_timeout = api.cnx.options.timeout
323
+ pol_id = valid_id policy
324
+ raise JSS::NoSuchItemError, "No Policy identified by '#{policy}'." unless pol_id
325
+
326
+ older_than = LOG_FLUSH_INTERVAL_INTEGERS[older_than]
327
+ raise JSS::InvalidDataError, "older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}" unless older_than
328
+
329
+ period = LOG_FLUSH_INTERVAL_PERIODS[period]
330
+ raise JSS::InvalidDataError, "period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}" unless period
331
+
332
+ computers = [computers] unless computers.is_a? Array
333
+
334
+ # log flushes can be really slow
335
+ api.timeout = 1800 unless orig_timeout && orig_timeout > 1800
336
+
337
+ return api.delete_rsrc "#{LOG_FLUSH_RSRC}/policy/id/#{pol_id}/interval/#{older_than}+#{period}" if computers.empty?
338
+
339
+ flush_logs_for_specific_computers pol_id, older_than, period, computers, api
340
+ ensure
341
+ api.timeout = orig_timeout
342
+ end
343
+
344
+ # use an XML body in a DELETE request to flush logs for
345
+ # a list of computers - used by the flush_logs class method
346
+ def self.flush_logs_for_specific_computers(pol_id, older_than, period, computers, api)
347
+ # build the xml body for a DELETE request
348
+ xml_doc = REXML::Document.new JSS::APIConnection::XML_HEADER
349
+ lf = xml_doc.add_element 'logflush'
350
+ lf.add_element('log').text = 'policy'
351
+ lf.add_element('log_id').text = pol_id.to_s
352
+ lf.add_element('interval').text = "#{older_than} #{period}"
353
+ comps_elem = lf.add_element 'computers'
354
+ computers.each do |c|
355
+ id = JSS::Computer.valid_id c
356
+ next unless id
357
+
358
+ ce = comps_elem.add_element 'computer'
359
+ ce.add_element('id').text = id.to_s
360
+ end
361
+
362
+ # Do a DELETE request with a body.
363
+ api.cnx.delete(LOG_FLUSH_RSRC) do |req|
364
+ req.headers[JSS::APIConnection::HTTP_CONTENT_TYPE_HEADER] = JSS::APIConnection::MIME_XML
365
+ req.body = xml_doc.to_s
366
+ end
367
+ end
368
+ private_class_method :flush_logs_for_specific_computers
369
+
284
370
  # Attributes
285
371
  ######################
286
372
 
@@ -613,7 +699,6 @@ module JSS
613
699
 
614
700
  if @in_jss
615
701
  gen = @init_data[:general]
616
- @frequency = gen[:frequency]
617
702
  @target_drive = gen[:target_drive]
618
703
  @offline = gen[:offline]
619
704
  @enabled = gen[:enabled]
@@ -629,6 +714,10 @@ module JSS
629
714
  trigger_enrollment_complete: gen[:trigger_enrollment_complete],
630
715
  trigger_other: gen[:trigger_other]
631
716
  }
717
+ @frequency = gen[:frequency]
718
+ @retry_event = gen[:retry_event]
719
+ @retry_attempts = gen[:retry_attempts]
720
+ @notify_failed_retries = gen[:notify_on_each_failed_retry]
632
721
 
633
722
  dtl = gen[:date_time_limitations]
634
723
 
@@ -745,8 +834,93 @@ module JSS
745
834
  # @return [void]
746
835
  #
747
836
  def frequency=(freq)
748
- raise JSS::InvalidDataError, "New frequency must be one of :#{FREQUENCIES.keys.join ', :'}" unless FREQUENCIES.key?(freq)
749
- @frequency = FREQUENCIES[freq]
837
+ raise JSS::InvalidDataError, "New frequency must be one of :#{FREQUENCIES.keys.join ', :'}" unless FREQUENCIES.key?(freq) || FREQUENCIES.value?(freq)
838
+
839
+ freq = freq.is_a?(Symbol) ? FREQUENCIES[freq] : freq
840
+ return if freq == @frequency
841
+
842
+ @frequency = freq
843
+ @need_to_update = true
844
+ end
845
+
846
+ # @return [String] The event that causes a policy retry
847
+ def retry_event
848
+ return RETRY_EVENTS[:none] unless FREQUENCIES[:once_per_computer] == @frequency
849
+
850
+ @retry_event
851
+ end
852
+
853
+ # Set the event that causes a retry if the policy fails.
854
+ # One of the ways to turn off policy retry is to set this to :none
855
+ # The other is to set the retry_attempts to 0
856
+ #
857
+ # @param [Symbol, String] A key or value from RETRY_EVENTS
858
+ # @return [void]
859
+ #
860
+ def retry_event=(evt)
861
+ validate_retry_opt
862
+ raise JSS::InvalidDataError, "Retry event must be one of :#{RETRY_EVENTS.keys.join ', :'}" unless RETRY_EVENTS.key?(evt) || RETRY_EVENTS.value?(evt)
863
+
864
+ evt = evt.is_a?(Symbol) ? RETRY_EVENTS[evt] : evt
865
+ return if evt == @retry_event
866
+
867
+ # if the event is not 'none' and attempts is <= 0,
868
+ # set events to 1, or the API won't accept it
869
+ unless evt == RETRY_EVENTS[:none]
870
+ @retry_attempts = 1 unless @retry_attempts.positive?
871
+ end
872
+
873
+ @retry_event = evt
874
+ @need_to_update = true
875
+ end
876
+
877
+ # @return [Integer] How many times wil the policy be retried if it fails.
878
+ # -1 means no retries, otherwise, an integer from 1 to 10
879
+ def retry_attempts
880
+ return 0 unless FREQUENCIES[:once_per_computer] == @frequency
881
+
882
+ @retry_attempts
883
+ end
884
+
885
+ # Set the number of times to retry if the policy fails.
886
+ # One of the ways to turn off policy retry is to set this to 0 or -1
887
+ # The other is to set retry_event to :none
888
+ #
889
+ # @param [Integer] From -1 to 10
890
+ # @return [void]
891
+ #
892
+ def retry_attempts=(int)
893
+ validate_retry_opt
894
+ raise JSS::InvalidDataError, 'Retry attempts must be an integer from 0-10' unless int.is_a?(Integer) && (-1..10).include?(int)
895
+
896
+ # if zero or -1, turn off retries
897
+ if int <= 0
898
+ @retry_event = RETRY_EVENTS[:none]
899
+ int = -1
900
+ end
901
+ return if @retry_attempts == int
902
+
903
+ @retry_attempts = int
904
+ @need_to_update = true
905
+ end
906
+
907
+ # @return [Boolean] Should admins be notified of failed retry attempts
908
+ def notify_failed_retries?
909
+ return false unless FREQUENCIES[:once_per_computer] == @frequency
910
+
911
+ @notify_failed_retries
912
+ end
913
+ alias notify_failed_retries notify_failed_retries?
914
+ alias notify_on_each_failed_retry notify_failed_retries?
915
+
916
+ # @param bool[Boolean] Should admins be notified of failed retry attempts
917
+ # @return [void]
918
+ def notify_failed_retries=(bool)
919
+ validate_retry_opt
920
+ bool = JSS::Validate.boolean bool
921
+ return if @notify_failed_retries == bool
922
+
923
+ @notify_failed_retries = bool
750
924
  @need_to_update = true
751
925
  end
752
926
 
@@ -1314,6 +1488,53 @@ module JSS
1314
1488
  removed
1315
1489
  end
1316
1490
 
1491
+ # Set a script parameter
1492
+ #
1493
+ # @param identifier [Integer,String] identifier the id or name of a script in this policy
1494
+ #
1495
+ # @param opts [Hash] opts the options to alter for this script
1496
+ #
1497
+ # @option [String] parameter4: the value of the 4th parameter passed to the script. this
1498
+ # overrides the same parameter in the script object itself.
1499
+ #
1500
+ # @option [String] parameter5: the value of the 5th parameter passed to the script. this
1501
+ # overrides the same parameter in the script object itself.
1502
+ #
1503
+ # @option [String] parameter6: the value of the 6th parameter passed to the script. this
1504
+ # overrides the same parameter in the script object itself.
1505
+ #
1506
+ # @option [String] parameter7: the value of the 7th parameter passed to the script. this
1507
+ # overrides the same parameter in the script object itself.
1508
+ #
1509
+ # @option [String] parameter8: the value of the 8th parameter passed to the script. this
1510
+ # overrides the same parameter in the script object itself.
1511
+ #
1512
+ # @option [String] parameter9: the value of the 9th parameter passed to the script. this
1513
+ # overrides the same parameter in the script object itself.
1514
+ #
1515
+ # @option [String] parameter10: the value of the 10th parameter passed to the script. this
1516
+ # overrides the same parameter in the script object itself.
1517
+ #
1518
+ # @option [String] parameter11: the value of the 11th parameter passed to the script. this
1519
+ # overrides the same parameter in the script object itself.
1520
+ #
1521
+ # @return [Array] the scripts array
1522
+ #
1523
+ def set_script_parameters(identifier, **opts)
1524
+ id = JSS::Script.valid_id identifier, api: @api
1525
+ raise JSS::NoSuchItemError, "No script matches '#{identifier}'" unless id
1526
+
1527
+ script_data = @scripts.select { |s| s[:id] == id }[0]
1528
+ raise JSS::InvalidDataError, "Script #{id} is not configured. Use add_script method." unless script_data
1529
+
1530
+ opts.each do |parameter, value|
1531
+ script_data[parameter] = value if SCRIPT_PARAMETERS_AVAILABLE.include? parameter
1532
+ end
1533
+
1534
+ @need_to_update = true
1535
+ @scripts
1536
+ end # end set_script_parameter
1537
+
1317
1538
  ###### Directory Bindings
1318
1539
 
1319
1540
  # @return [Array] the id's of the directory_bindings handled by the policy
@@ -1621,34 +1842,37 @@ module JSS
1621
1842
  end
1622
1843
  alias execute run
1623
1844
 
1624
- # Flush all policy logs for this policy older than
1625
- # some number of days, weeks, months or years.
1845
+ # Flush logs for this policy older than
1846
+ # some number of days, weeks, months or years, possibly limited to
1847
+ # one or more computers
1848
+ #
1849
+ # With no parameters, flushes all logs for all computers
1626
1850
  #
1627
- # With no parameters, flushes all logs
1851
+ # NOTE: Currently the API doesn't have a way to flush only failed policies.
1628
1852
  #
1629
- # NOTE: Currently the API doesn't have a way to
1630
- # flush only failed policies.
1853
+ # WARNING: Log flushing can take a long time, and the API call doesnt return
1854
+ # until its finished. The connection timeout will be temporarily raised to
1855
+ # 30 minutes, unless it's already higher.
1631
1856
  #
1632
1857
  # @param older_than[Integer] 0, 1, 2, 3, or 6
1633
1858
  #
1634
1859
  # @param period[Symbol] :days, :weeks, :months, or :years
1635
1860
  #
1861
+ # @param computers[Array<Integer,String>] Identifiers of the target computers
1862
+ # either ids, names, SNs, macaddrs, or UDIDs
1863
+ #
1636
1864
  # @return [void]
1637
1865
  #
1638
- def flush_logs(older_than: 0, period: :days)
1866
+ def flush_logs(older_than: 0, period: :days, computers: [])
1639
1867
  raise JSS::NoSuchItemError, "Policy doesn't exist in the JSS. Use #create first." unless @in_jss
1640
1868
 
1641
- unless LOG_FLUSH_INTERVAL_INTEGERS.key?(older_than)
1642
- raise JSS::InvalidDataError, "older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}"
1643
- end
1644
-
1645
- unless LOG_FLUSH_INTERVAL_PERIODS.key?(period)
1646
- raise JSS::InvalidDataError, "period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}"
1647
- end
1648
-
1649
- interval = "#{LOG_FLUSH_INTERVAL_INTEGERS[older_than]}+#{LOG_FLUSH_INTERVAL_PERIODS[period]}"
1650
-
1651
- @api.delete_rsrc "#{LOG_FLUSH_RSRC}/policy/id/#{@id}/interval/#{interval}"
1869
+ JSS::Policy.flush_logs(
1870
+ @id,
1871
+ older_than: older_than,
1872
+ period: period,
1873
+ computers: computers,
1874
+ api: @api
1875
+ )
1652
1876
  end
1653
1877
 
1654
1878
  # Private Instance Methods
@@ -1656,6 +1880,17 @@ module JSS
1656
1880
 
1657
1881
  private
1658
1882
 
1883
+ # raise an error if a trying to set retry options when
1884
+ # frequency is not 'once per comptuer'
1885
+ #
1886
+ # @return [void]
1887
+ #
1888
+ def validate_retry_opt
1889
+ return if FREQUENCIES[:once_per_computer] == @frequency
1890
+
1891
+ raise JSS::UnsupportedError, 'Policy retry is only available when frequency is set to :once_per_computer'
1892
+ end
1893
+
1659
1894
  # raise an error if a package being added isn't valid
1660
1895
  #
1661
1896
  # @see #add_package
@@ -1786,6 +2021,10 @@ module JSS
1786
2021
  general.add_element('name').text = @name
1787
2022
  general.add_element('enabled').text = @enabled
1788
2023
  general.add_element('frequency').text = @frequency
2024
+ general.add_element('retry_event').text = @retry_event
2025
+ general.add_element('retry_attempts').text = @retry_attempts.to_s
2026
+ general.add_element('notify_on_each_failed_retry').text = @notify_failed_retries.to_s
2027
+
1789
2028
  general.add_element('target_drive').text = @target_drive
1790
2029
  general.add_element('offline').text = @offline
1791
2030