ruby-jss 1.2.6 → 1.4.1

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 (250) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +189 -1
  3. data/README.md +1 -1
  4. data/bin/cgrouper +1 -1
  5. data/bin/jamfHelperBackgrounder +1 -1
  6. data/bin/netseg-update +1 -1
  7. data/data/ruby-jss.conf.example +1 -1
  8. data/lib/jamf.rb +1 -1
  9. data/lib/jamf/api/abstract_classes/advanced_search.rb +1 -1
  10. data/lib/jamf/api/abstract_classes/collection_resource.rb +17 -9
  11. data/lib/jamf/api/abstract_classes/generic_reference.rb +1 -1
  12. data/lib/jamf/api/abstract_classes/json_object.rb +2 -2
  13. data/lib/jamf/api/abstract_classes/prestage.rb +2 -2
  14. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +1 -1
  15. data/lib/jamf/api/abstract_classes/resource.rb +1 -1
  16. data/lib/jamf/api/abstract_classes/singleton_resource.rb +1 -1
  17. data/lib/jamf/api/attribute_classes/ip_address.rb +1 -1
  18. data/lib/jamf/api/attribute_classes/timestamp.rb +1 -1
  19. data/lib/jamf/api/connection.rb +9 -5
  20. data/lib/jamf/api/connection/api_error.rb +1 -1
  21. data/lib/jamf/api/connection/api_error_styleguide.rb +1 -1
  22. data/lib/jamf/api/connection/token.rb +22 -2
  23. data/lib/jamf/api/json_objects/account_prefs.rb +1 -1
  24. data/lib/jamf/api/json_objects/android_details.rb +1 -1
  25. data/lib/jamf/api/json_objects/appletv_details.rb +1 -1
  26. data/lib/jamf/api/json_objects/attachment.rb +1 -1
  27. data/lib/jamf/api/json_objects/cellular_network.rb +1 -1
  28. data/lib/jamf/api/json_objects/change_log_entry.rb +1 -1
  29. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +1 -1
  30. data/lib/jamf/api/json_objects/country.rb +1 -1
  31. data/lib/jamf/api/json_objects/criterion.rb +1 -1
  32. data/lib/jamf/api/json_objects/device_enrollment_device.rb +1 -1
  33. data/lib/jamf/api/json_objects/device_enrollment_sync_status.rb +1 -1
  34. data/lib/jamf/api/json_objects/extension_attribute_value.rb +1 -1
  35. data/lib/jamf/api/json_objects/installed_application.rb +1 -1
  36. data/lib/jamf/api/json_objects/installed_certificate.rb +1 -1
  37. data/lib/jamf/api/json_objects/installed_configuration_profile.rb +1 -1
  38. data/lib/jamf/api/json_objects/installed_ebook.rb +1 -1
  39. data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +1 -1
  40. data/lib/jamf/api/json_objects/inventory_preload_extension_attribute.rb +1 -1
  41. data/lib/jamf/api/json_objects/ios_details.rb +1 -1
  42. data/lib/jamf/api/json_objects/location.rb +1 -1
  43. data/lib/jamf/api/json_objects/md_prestage_name.rb +1 -1
  44. data/lib/jamf/api/json_objects/md_prestage_names.rb +1 -1
  45. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +1 -1
  46. data/lib/jamf/api/json_objects/mobile_device_details.rb +1 -1
  47. data/lib/jamf/api/json_objects/mobile_device_security.rb +1 -1
  48. data/lib/jamf/api/json_objects/prestage_assignment.rb +1 -1
  49. data/lib/jamf/api/json_objects/prestage_location.rb +1 -1
  50. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +1 -1
  51. data/lib/jamf/api/json_objects/prestage_scope.rb +1 -1
  52. data/lib/jamf/api/json_objects/prestage_sync_status.rb +1 -1
  53. data/lib/jamf/api/json_objects/purchasing_data.rb +1 -1
  54. data/lib/jamf/api/mixins/abstract.rb +1 -1
  55. data/lib/jamf/api/mixins/bulk_deletable.rb +1 -1
  56. data/lib/jamf/api/mixins/change_log.rb +1 -1
  57. data/lib/jamf/api/mixins/extendable.rb +1 -1
  58. data/lib/jamf/api/mixins/immutable.rb +1 -1
  59. data/lib/jamf/api/mixins/locatable.rb +1 -1
  60. data/lib/jamf/api/mixins/lockable.rb +1 -1
  61. data/lib/jamf/api/mixins/referable.rb +1 -1
  62. data/lib/jamf/api/mixins/searchable.rb +1 -1
  63. data/lib/jamf/api/mixins/uncreatable.rb +1 -1
  64. data/lib/jamf/api/mixins/undeletable.rb +1 -1
  65. data/lib/jamf/api/resources/collection_resources/account.rb +1 -1
  66. data/lib/jamf/api/resources/collection_resources/advanced_mobile_device_search.rb +1 -1
  67. data/lib/jamf/api/resources/collection_resources/advanced_user_search.rb +1 -1
  68. data/lib/jamf/api/resources/collection_resources/building.rb +1 -1
  69. data/lib/jamf/api/resources/collection_resources/category.rb +1 -1
  70. data/lib/jamf/api/resources/collection_resources/computer.rb +1 -1
  71. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +1 -1
  72. data/lib/jamf/api/resources/collection_resources/department.rb +2 -2
  73. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +4 -4
  74. data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +1 -1
  75. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +1 -1
  76. data/lib/jamf/api/resources/collection_resources/mobile_device.rb +1 -1
  77. data/lib/jamf/api/resources/collection_resources/mobile_device_prestage.rb +1 -1
  78. data/lib/jamf/api/resources/collection_resources/script.rb +1 -1
  79. data/lib/jamf/api/resources/collection_resources/site.rb +1 -1
  80. data/lib/jamf/api/resources/collection_resources/time_zone.rb +1 -1
  81. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +1 -1
  82. data/lib/jamf/api/resources/singleton_resources/authorization.rb +1 -1
  83. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +1 -1
  84. data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +1 -1
  85. data/lib/jamf/client.rb +1 -1
  86. data/lib/jamf/client/jamf_binary.rb +1 -1
  87. data/lib/jamf/client/jamf_helper.rb +1 -1
  88. data/lib/jamf/client/management_action.rb +1 -1
  89. data/lib/jamf/compatibility.rb +1 -1
  90. data/lib/jamf/composer.rb +1 -1
  91. data/lib/jamf/configuration.rb +8 -10
  92. data/lib/jamf/exceptions.rb +1 -1
  93. data/lib/jamf/ruby_extensions.rb +2 -1
  94. data/lib/jamf/ruby_extensions/array.rb +2 -2
  95. data/lib/jamf/ruby_extensions/array/predicates.rb +1 -1
  96. data/lib/jamf/ruby_extensions/array/utils.rb +4 -4
  97. data/lib/jamf/ruby_extensions/dig.rb +52 -0
  98. data/lib/jamf/ruby_extensions/filetest.rb +1 -1
  99. data/lib/jamf/ruby_extensions/filetest/predicates.rb +1 -1
  100. data/lib/jamf/ruby_extensions/hash.rb +1 -1
  101. data/lib/jamf/ruby_extensions/hash/backports.rb +2 -2
  102. data/lib/jamf/ruby_extensions/ipaddr.rb +1 -1
  103. data/lib/jamf/ruby_extensions/ipaddr/utils.rb +1 -1
  104. data/lib/jamf/ruby_extensions/object.rb +1 -1
  105. data/lib/jamf/ruby_extensions/object/predicates.rb +1 -1
  106. data/lib/jamf/ruby_extensions/pathname.rb +1 -1
  107. data/lib/jamf/ruby_extensions/pathname/predicates.rb +1 -1
  108. data/lib/jamf/ruby_extensions/pathname/utils.rb +1 -1
  109. data/lib/jamf/ruby_extensions/string.rb +1 -1
  110. data/lib/jamf/ruby_extensions/string/backports.rb +1 -1
  111. data/lib/jamf/ruby_extensions/string/conversions.rb +1 -1
  112. data/lib/jamf/ruby_extensions/string/predicates.rb +14 -4
  113. data/lib/jamf/utility.rb +1 -1
  114. data/lib/jamf/validate.rb +1 -1
  115. data/lib/jamf/version.rb +2 -2
  116. data/lib/jpapi.rb +1 -1
  117. data/lib/jss-api.rb +1 -1
  118. data/lib/jss.rb +3 -1
  119. data/lib/jss/api_connection.rb +3 -30
  120. data/lib/jss/api_object.rb +23 -4
  121. data/lib/jss/api_object/account.rb +1 -1
  122. data/lib/jss/api_object/advanced_search.rb +28 -27
  123. data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +1 -1
  124. data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +1 -1
  125. data/lib/jss/api_object/advanced_search/advanced_user_search.rb +1 -1
  126. data/lib/jss/api_object/app_store_country_codes.rb +298 -0
  127. data/lib/jss/api_object/building.rb +1 -1
  128. data/lib/jss/api_object/categorizable.rb +1 -1
  129. data/lib/jss/api_object/category.rb +1 -1
  130. data/lib/jss/api_object/computer.rb +12 -6
  131. data/lib/jss/api_object/computer/application_installs.rb +1 -1
  132. data/lib/jss/api_object/computer_invitation.rb +1 -1
  133. data/lib/jss/api_object/configuration_profile.rb +4 -2
  134. data/lib/jss/api_object/configuration_profile/mobile_device_configuration_profile.rb +1 -1
  135. data/lib/jss/api_object/configuration_profile/osx_configuration_profile.rb +1 -1
  136. data/lib/jss/api_object/creatable.rb +1 -1
  137. data/lib/jss/api_object/criteriable.rb +1 -1
  138. data/lib/jss/api_object/criteriable/criteria.rb +1 -1
  139. data/lib/jss/api_object/criteriable/criterion.rb +1 -1
  140. data/lib/jss/api_object/department.rb +1 -1
  141. data/lib/jss/api_object/directory_binding.rb +273 -0
  142. data/lib/jss/api_object/directory_binding_type.rb +90 -0
  143. data/lib/jss/api_object/directory_binding_type/active_directory.rb +502 -0
  144. data/lib/jss/api_object/directory_binding_type/admitmac.rb +525 -0
  145. data/lib/jss/api_object/directory_binding_type/centrify.rb +212 -0
  146. data/lib/jss/api_object/directory_binding_type/open_directory.rb +178 -0
  147. data/lib/jss/api_object/directory_binding_type/powerbroker_identity_services.rb +73 -0
  148. data/lib/jss/api_object/disk_encryption_configurations.rb +114 -0
  149. data/lib/jss/api_object/distribution_point.rb +96 -36
  150. data/lib/jss/api_object/dock_item.rb +137 -0
  151. data/lib/jss/api_object/ebook.rb +2 -3
  152. data/lib/jss/api_object/extendable.rb +67 -28
  153. data/lib/jss/api_object/extension_attribute.rb +5 -4
  154. data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +1 -1
  155. data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +1 -1
  156. data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +1 -1
  157. data/lib/jss/api_object/group.rb +1 -1
  158. data/lib/jss/api_object/group/computer_group.rb +1 -1
  159. data/lib/jss/api_object/group/mobile_device_group.rb +1 -1
  160. data/lib/jss/api_object/group/user_group.rb +1 -1
  161. data/lib/jss/api_object/ibeacon.rb +1 -1
  162. data/lib/jss/api_object/ldap_server.rb +1 -1
  163. data/lib/jss/api_object/locatable.rb +1 -1
  164. data/lib/jss/api_object/mac_application.rb +108 -9
  165. data/lib/jss/api_object/management_history.rb +1 -1
  166. data/lib/jss/api_object/management_history/audit_event.rb +1 -1
  167. data/lib/jss/api_object/management_history/casper_imaging_log.rb +1 -1
  168. data/lib/jss/api_object/management_history/casper_remote_log.rb +1 -1
  169. data/lib/jss/api_object/management_history/computer_usage_log.rb +1 -1
  170. data/lib/jss/api_object/management_history/ebook.rb +1 -1
  171. data/lib/jss/api_object/management_history/hashlike.rb +1 -1
  172. data/lib/jss/api_object/management_history/mac_app_store_app.rb +1 -1
  173. data/lib/jss/api_object/management_history/mdm_command.rb +1 -1
  174. data/lib/jss/api_object/management_history/mobile_device_app.rb +1 -1
  175. data/lib/jss/api_object/management_history/policy_log.rb +1 -1
  176. data/lib/jss/api_object/management_history/screen_sharing_log.rb +1 -1
  177. data/lib/jss/api_object/management_history/user_location_change.rb +1 -1
  178. data/lib/jss/api_object/matchable.rb +1 -1
  179. data/lib/jss/api_object/mdm.rb +1 -1
  180. data/lib/jss/api_object/mobile_device.rb +12 -6
  181. data/lib/jss/api_object/mobile_device_application.rb +13 -1
  182. data/lib/jss/api_object/netboot_server.rb +1 -1
  183. data/lib/jss/api_object/network_segment.rb +153 -59
  184. data/lib/jss/api_object/package.rb +106 -41
  185. data/lib/jss/api_object/patch_policy.rb +1 -1
  186. data/lib/jss/api_object/patch_source.rb +1 -1
  187. data/lib/jss/api_object/patch_source/patch_external_source.rb +1 -1
  188. data/lib/jss/api_object/patch_source/patch_internal_source.rb +1 -1
  189. data/lib/jss/api_object/patch_title.rb +1 -1
  190. data/lib/jss/api_object/patch_title/version.rb +1 -1
  191. data/lib/jss/api_object/peripheral.rb +1 -1
  192. data/lib/jss/api_object/peripheral_type.rb +1 -1
  193. data/lib/jss/api_object/policy.rb +492 -8
  194. data/lib/jss/api_object/printer.rb +440 -0
  195. data/lib/jss/api_object/purchasable.rb +1 -1
  196. data/lib/jss/api_object/removable_macaddr.rb +1 -1
  197. data/lib/jss/api_object/restricted_software.rb +1 -1
  198. data/lib/jss/api_object/scopable.rb +1 -1
  199. data/lib/jss/api_object/scopable/scope.rb +387 -72
  200. data/lib/jss/api_object/script.rb +1 -1
  201. data/lib/jss/api_object/self_servable.rb +24 -16
  202. data/lib/jss/api_object/self_servable/icon.rb +1 -1
  203. data/lib/jss/api_object/sitable.rb +1 -1
  204. data/lib/jss/api_object/site.rb +1 -1
  205. data/lib/jss/api_object/software_update_server.rb +1 -1
  206. data/lib/jss/api_object/updatable.rb +1 -1
  207. data/lib/jss/api_object/uploadable.rb +2 -2
  208. data/lib/jss/api_object/user.rb +43 -2
  209. data/lib/jss/api_object/vpp_account.rb +209 -0
  210. data/lib/jss/api_object/vppable.rb +170 -14
  211. data/lib/jss/api_object/webhook.rb +1 -1
  212. data/lib/jss/client.rb +1 -1
  213. data/lib/jss/client/jamf_binary.rb +1 -1
  214. data/lib/jss/client/jamf_helper.rb +1 -1
  215. data/lib/jss/client/management_action.rb +1 -1
  216. data/lib/jss/compatibility.rb +1 -1
  217. data/lib/jss/composer.rb +2 -2
  218. data/lib/jss/configuration.rb +1 -1
  219. data/lib/jss/db_connection.rb +1 -1
  220. data/lib/jss/exceptions.rb +1 -1
  221. data/lib/jss/ruby_extensions.rb +1 -1
  222. data/lib/jss/ruby_extensions/array.rb +1 -1
  223. data/lib/jss/ruby_extensions/filetest.rb +1 -1
  224. data/lib/jss/ruby_extensions/hash.rb +1 -1
  225. data/lib/jss/ruby_extensions/ipaddr.rb +1 -1
  226. data/lib/jss/ruby_extensions/pathname.rb +1 -1
  227. data/lib/jss/ruby_extensions/string.rb +1 -1
  228. data/lib/jss/ruby_extensions/string/backports.rb +1 -1
  229. data/lib/jss/ruby_extensions/string/conversions.rb +1 -1
  230. data/lib/jss/ruby_extensions/string/predicates.rb +14 -4
  231. data/lib/jss/ruby_extensions/time.rb +1 -1
  232. data/lib/jss/server.rb +1 -1
  233. data/lib/jss/utility.rb +9 -23
  234. data/lib/jss/validate.rb +54 -11
  235. data/lib/jss/version.rb +2 -2
  236. data/lib/jss/xml_workaround.rb +1 -1
  237. data/lib/ruby-jss.rb +1 -1
  238. data/test/bin/runtests +1 -1
  239. data/test/lib/testhelper.rb +1 -1
  240. data/test/lib/testhelper/auth.rb +1 -1
  241. data/test/lib/testhelper/patch_mgmt.rb +1 -1
  242. data/test/specs/api_connection_spec.rb +1 -1
  243. data/test/specs/patch01_source_spec.rb +1 -1
  244. data/test/specs/patch02_internal_source_spec.rb +1 -1
  245. data/test/specs/patch03_external_source_spec.rb +1 -1
  246. data/test/specs/patch04_titles_spec.rb +1 -1
  247. data/test/specs/patch05_policies_spec.rb +1 -1
  248. data/test/specs/patch06_cleanup_spec.rb +1 -1
  249. data/test/specs/policy_spec.rb +1 -1
  250. metadata +15 -2
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- ### Copyright 2019 Pixar
1
+ ### Copyright 2020 Pixar
2
2
 
3
3
  ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -1,4 +1,4 @@
1
- # Copyright 2019 Pixar
1
+ # Copyright 2020 Pixar
2
2
 
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "Apache License")
@@ -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',
@@ -174,7 +180,9 @@ module JSS
174
180
  change_pw: 'specified',
175
181
  generate_pw: 'random',
176
182
  enable_fv2: 'fileVaultEnable',
177
- disable_fv2: 'fileVaultDisable'
183
+ disable_fv2: 'fileVaultDisable',
184
+ reset_random: 'resetRandom',
185
+ reset_pw: 'reset'
178
186
  }.freeze
179
187
 
180
188
  PACKAGE_ACTIONS = {
@@ -191,6 +199,12 @@ module JSS
191
199
  after: 'After'
192
200
  }.freeze
193
201
 
202
+ DISK_ENCRYPTION_ACTIONS = {
203
+ apply: "apply",
204
+ remediate: "remediate",
205
+ none: "none"
206
+ }
207
+
194
208
  PRINTER_ACTIONS = {
195
209
  map: 'install',
196
210
  unmap: 'uninstall'
@@ -541,6 +555,7 @@ module JSS
541
555
 
542
556
  # @return [String] the message shown the user at policy end
543
557
  attr_reader :user_message_finish
558
+ alias user_message_end user_message_finish
544
559
 
545
560
  # @return [Hash]
546
561
  #
@@ -604,7 +619,6 @@ module JSS
604
619
 
605
620
  if @in_jss
606
621
  gen = @init_data[:general]
607
- @frequency = gen[:frequency]
608
622
  @target_drive = gen[:target_drive]
609
623
  @offline = gen[:offline]
610
624
  @enabled = gen[:enabled]
@@ -620,6 +634,10 @@ module JSS
620
634
  trigger_enrollment_complete: gen[:trigger_enrollment_complete],
621
635
  trigger_other: gen[:trigger_other]
622
636
  }
637
+ @frequency = gen[:frequency]
638
+ @retry_event = gen[:retry_event]
639
+ @retry_attempts = gen[:retry_attempts]
640
+ @notify_failed_retries = gen[:notify_on_each_failed_retry]
623
641
 
624
642
  dtl = gen[:date_time_limitations]
625
643
 
@@ -670,6 +688,7 @@ module JSS
670
688
  @disk_encryption = @init_data[:disk_encryption]
671
689
 
672
690
  @printers = @init_data[:printers]
691
+ @printers.shift
673
692
 
674
693
  # Not in jss yet
675
694
  end
@@ -735,8 +754,93 @@ module JSS
735
754
  # @return [void]
736
755
  #
737
756
  def frequency=(freq)
738
- raise JSS::InvalidDataError, "New frequency must be one of :#{FREQUENCIES.keys.join ', :'}" unless FREQUENCIES.key?(freq)
739
- @frequency = FREQUENCIES[freq]
757
+ raise JSS::InvalidDataError, "New frequency must be one of :#{FREQUENCIES.keys.join ', :'}" unless FREQUENCIES.key?(freq) || FREQUENCIES.value?(freq)
758
+
759
+ freq = freq.is_a?(Symbol) ? FREQUENCIES[freq] : freq
760
+ return if freq == @frequency
761
+
762
+ @frequency = freq
763
+ @need_to_update = true
764
+ end
765
+
766
+ # @return [String] The event that causes a policy retry
767
+ def retry_event
768
+ return RETRY_EVENTS[:none] unless FREQUENCIES[:once_per_computer] == @frequency
769
+
770
+ @retry_event
771
+ end
772
+
773
+ # Set the event that causes a retry if the policy fails.
774
+ # One of the ways to turn off policy retry is to set this to :none
775
+ # The other is to set the retry_attempts to 0
776
+ #
777
+ # @param [Symbol, String] A key or value from RETRY_EVENTS
778
+ # @return [void]
779
+ #
780
+ def retry_event=(evt)
781
+ validate_retry_opt
782
+ raise JSS::InvalidDataError, "Retry event must be one of :#{RETRY_EVENTS.keys.join ', :'}" unless RETRY_EVENTS.key?(evt) || RETRY_EVENTS.value?(evt)
783
+
784
+ evt = evt.is_a?(Symbol) ? RETRY_EVENTS[evt] : evt
785
+ return if evt == @retry_event
786
+
787
+ # if the event is not 'none' and attempts is <= 0,
788
+ # set events to 1, or the API won't accept it
789
+ unless evt == RETRY_EVENTS[:none]
790
+ @retry_attempts = 1 unless @retry_attempts.positive?
791
+ end
792
+
793
+ @retry_event = evt
794
+ @need_to_update = true
795
+ end
796
+
797
+ # @return [Integer] How many times wil the policy be retried if it fails.
798
+ # -1 means no retries, otherwise, an integer from 1 to 10
799
+ def retry_attempts
800
+ return 0 unless FREQUENCIES[:once_per_computer] == @frequency
801
+
802
+ @retry_attempts
803
+ end
804
+
805
+ # Set the number of times to retry if the policy fails.
806
+ # One of the ways to turn off policy retry is to set this to 0 or -1
807
+ # The other is to set retry_event to :none
808
+ #
809
+ # @param [Integer] From -1 to 10
810
+ # @return [void]
811
+ #
812
+ def retry_attempts=(int)
813
+ validate_retry_opt
814
+ raise JSS::InvalidDataError, 'Retry attempts must be an integer from 0-10' unless int.is_a?(Integer) && (-1..10).include?(int)
815
+
816
+ # if zero or -1, turn off retries
817
+ if int <= 0
818
+ @retry_event = RETRY_EVENTS[:none]
819
+ int = -1
820
+ end
821
+ return if @retry_attempts == int
822
+
823
+ @retry_attempts = int
824
+ @need_to_update = true
825
+ end
826
+
827
+ # @return [Boolean] Should admins be notified of failed retry attempts
828
+ def notify_failed_retries?
829
+ return false unless FREQUENCIES[:once_per_computer] == @frequency
830
+
831
+ @notify_failed_retries
832
+ end
833
+ alias notify_failed_retries notify_failed_retries?
834
+ alias notify_on_each_failed_retry notify_failed_retries?
835
+
836
+ # @param bool[Boolean] Should admins be notified of failed retry attempts
837
+ # @return [void]
838
+ def notify_failed_retries=(bool)
839
+ validate_retry_opt
840
+ bool = JSS::Validate.boolean bool
841
+ return if @notify_failed_retries == bool
842
+
843
+ @notify_failed_retries = bool
740
844
  @need_to_update = true
741
845
  end
742
846
 
@@ -914,6 +1018,30 @@ module JSS
914
1018
  end
915
1019
  alias message= reboot_message=
916
1020
 
1021
+ # Set User Start Message
1022
+ #
1023
+ # @param user_message[String] Text of User Message
1024
+ #
1025
+ # @return [void] description of returned object
1026
+ def user_message_start=(message)
1027
+ raise JSS::InvalidDataError, 'User message must be a String' unless message.is_a? String
1028
+ @user_message_start = message
1029
+ @need_to_update = true
1030
+ end
1031
+
1032
+ # Set User Finish Message
1033
+ #
1034
+ # @param user_message[String] Text of User Message
1035
+ #
1036
+ # @return [void] description of returned object
1037
+ def user_message_end=(message)
1038
+ raise JSS::InvalidDataError, 'User message must be a String' unless message.is_a? String
1039
+ @user_message_finish = message
1040
+ @need_to_update = true
1041
+ end
1042
+
1043
+ alias user_message_finish= user_message_end=
1044
+
917
1045
  # Set Startup Disk
918
1046
  # Only Supports 'Specify Local Startup Disk' at the moment
919
1047
  #
@@ -1180,7 +1308,7 @@ module JSS
1180
1308
 
1181
1309
  # Remove a package from this policy by name or id
1182
1310
  #
1183
- # @param identfier [String,Integer] the name or id of the package to remove
1311
+ # @param identifier [String,Integer] the name or id of the package to remove
1184
1312
  #
1185
1313
  # @return [Array, nil] the new packages array or nil if no change
1186
1314
  #
@@ -1270,7 +1398,7 @@ module JSS
1270
1398
 
1271
1399
  # Remove a script from this policy by name or id
1272
1400
  #
1273
- # @param identfier [String,Integer] the name or id of the script to remove
1401
+ # @param identifier [String,Integer] the name or id of the script to remove
1274
1402
  #
1275
1403
  # @return [Array, nil] the new scripts array or nil if no change
1276
1404
  #
@@ -1292,6 +1420,49 @@ module JSS
1292
1420
  @directory_bindings.map { |p| p[:name] }
1293
1421
  end
1294
1422
 
1423
+ # Add a Directory Bidning to the list of directory_bindings handled by this policy.
1424
+ # If the directory binding already exists in the policy, nil is returned and
1425
+ # no changes are made.
1426
+ #
1427
+ # @param [String,Integer] identifier the name or id of the directory binding to add to this policy
1428
+ #
1429
+ # @param position [Symbol, Integer] where to add this directory binding among the list of
1430
+ # directory_bindings. Zero-based, :start and 0 are the same, as are :end and -1.
1431
+ # Defaults to :end
1432
+ #
1433
+ # @return [Array, nil] the new @directory_bindings array, nil if directory_binding was already in the policy
1434
+ #
1435
+ def add_directory_binding(identifier, **opts)
1436
+ id = validate_directory_binding_opts identifier, opts
1437
+
1438
+ return nil if @directory_bindings.map { |s| s[:id] }.include? id
1439
+
1440
+ name = JSS::DirectoryBinding.map_all_ids_to(:name, api: @api)[id]
1441
+
1442
+ directory_binding_data = {
1443
+ id: id,
1444
+ name: name
1445
+ }
1446
+
1447
+ @directory_bindings.insert opts[:position], directory_binding_data
1448
+
1449
+ @need_to_update = true
1450
+ @directory_bindings
1451
+ end
1452
+
1453
+
1454
+ # Remove a directory binding from this policy by name or id
1455
+ #
1456
+ # @param identifier [String,Integer] the name or id of the directory binding to remove
1457
+ #
1458
+ # @return [Array, nil] the new directory bindings array or nil if no change
1459
+ #
1460
+ def remove_directory_binding(identifier)
1461
+ removed = @directory_bindings.delete_if { |s| s[:id] == identifier || s[:name] == identifier }
1462
+ @need_to_update = true if removed
1463
+ removed
1464
+ end
1465
+
1295
1466
  ###### Dock items
1296
1467
 
1297
1468
  # @return [Array] the id's of the dock_items handled by the policy
@@ -1304,6 +1475,86 @@ module JSS
1304
1475
  @dock_items.map { |p| p[:name] }
1305
1476
  end
1306
1477
 
1478
+
1479
+ ###### Printers
1480
+
1481
+ # Add a specific printer object to the policy.
1482
+ #
1483
+ # @author Tyler Morgan
1484
+ #
1485
+ # @param newvalue [String,Integer] The name or the id of the printer to be added to this policy.
1486
+ #
1487
+ # @param position [Symbol, Integer] where to add this printer object among the list of printer
1488
+ # objects. Zero-based, :start and 0 are the same, as are :end and -1.
1489
+ # Defaults to :end
1490
+ #
1491
+ # @param action [Symbol] One of the PRINTER_ACTIONS symbols. What you want done with the printer object upon policy execution.
1492
+ #
1493
+ # @param make_default [TrueClass,FalseClass] Should this printer object be set to default.
1494
+ # Defaults to false
1495
+ #
1496
+ # @return [String] The new printers array or nil if the printer was already in the policy
1497
+ def add_printer(identifier, **opts)
1498
+ id = validate_printer_opts identifier, opts
1499
+
1500
+ return nil if @printers.map { |p| p[:id] }.include? id
1501
+
1502
+ name = JSS::Printer.map_all_ids_to(:name, api: @api)[id]
1503
+
1504
+ printer_data = {
1505
+ id: id,
1506
+ name: name,
1507
+ action: PRINTER_ACTIONS[opts[:action]],
1508
+ make_default: opts[:make_default]
1509
+ }
1510
+
1511
+ @printers.insert opts[:position], printer_data
1512
+
1513
+ @need_to_update = true
1514
+ @printers
1515
+ end
1516
+
1517
+
1518
+ # Remove a specific printer object from the policy.
1519
+ #
1520
+ # @author Tyler Morgan
1521
+ #
1522
+ # @param identifier [String,Integer] The name or id of the printer to be removed.
1523
+ #
1524
+ # @return [Array, nil] The new printers array or nil if no change.
1525
+ def remove_printer(identifier)
1526
+ removed = @printers.delete_if { |p| p[:id] == identifier || p[:name] == identifier }
1527
+
1528
+ @need_to_update = true
1529
+ removed
1530
+ end
1531
+
1532
+ # Add a dock item to the policy
1533
+ def add_dock_item(identifier, action)
1534
+ id = JSS::DockItem.valid_id identifier, api: @api
1535
+
1536
+ raise JSS::NoSuchItemError, "No Dock Item matches '#{identifier}'" unless id
1537
+
1538
+ raise JSS::InvalidDataError, "Action must be one of: :#{DOCK_ITEM_ACTIONS.keys.join ', :'}" unless DOCK_ITEM_ACTIONS.include? action
1539
+
1540
+ return nil if @dock_items.map { |d| d[:id] }.include? id
1541
+
1542
+ name = JSS::DockItem.map_all_ids_to(:name, api: @api)[id]
1543
+
1544
+ @dock_items << {id: id, name: name, action: DOCK_ITEM_ACTIONS[action]}
1545
+
1546
+ @need_to_update = true
1547
+ @dock_items
1548
+ end
1549
+
1550
+ # Remove a dock item from the policy
1551
+ def remove_dock_item(identifier)
1552
+ # TODO: Add validation against JSS::DockItem
1553
+ removed = @dock_items.delete_if { |d| d[:id] == identifier || d[:name] == identifier }
1554
+ @need_to_update = true if removed
1555
+ removed
1556
+ end
1557
+
1307
1558
  # @return [Array] the id's of the printers handled by the policy
1308
1559
  def printer_ids
1309
1560
  begin
@@ -1312,7 +1563,7 @@ module JSS
1312
1563
  return []
1313
1564
  end
1314
1565
  end
1315
-
1566
+
1316
1567
  # @return [Array] the names of the printers handled by the policy
1317
1568
  def printer_names
1318
1569
  begin
@@ -1322,6 +1573,130 @@ module JSS
1322
1573
  end
1323
1574
  end
1324
1575
 
1576
+
1577
+
1578
+ ###### Disk Encryption
1579
+
1580
+ # Sets the Disk Encryption application to "Remediate" and sets the remediation key type to individual.
1581
+ #
1582
+ # @author Tyler Morgan
1583
+ #
1584
+ # @return [Void]
1585
+ #
1586
+ def reissue_key()
1587
+ if @disk_encryption[:action] != DISK_ENCRYPTION_ACTIONS[:remediate]
1588
+ # Setting New Action
1589
+ hash = {
1590
+ action: DISK_ENCRYPTION_ACTIONS[:remediate],
1591
+ remediate_key_type: "Individual"
1592
+ }
1593
+
1594
+ @disk_encryption = hash
1595
+ @need_to_update = true
1596
+
1597
+ else
1598
+ # Update
1599
+ return
1600
+ end
1601
+
1602
+ end
1603
+
1604
+
1605
+ # Sets the Disk Encryption application to "Apply" and sets the correct disk encryption configuration ID using either the name or id.
1606
+ #
1607
+ # @author Tyler Morgan
1608
+ #
1609
+ # @return [Void]
1610
+ #
1611
+ def apply_encryption_configuration(identifier)
1612
+
1613
+ id = JSS::DiskEncryptionConfiguration.valid_id identifier
1614
+
1615
+ return if id.nil?
1616
+
1617
+ hash = {
1618
+ action: DISK_ENCRYPTION_ACTIONS[:apply],
1619
+ disk_encryption_configuration_id: id,
1620
+ auth_restart: false
1621
+ }
1622
+
1623
+ @disk_encryption = hash
1624
+ @need_to_update = true
1625
+ end
1626
+
1627
+
1628
+ # Removes the Disk Encryption settings associated with this specific policy.
1629
+ #
1630
+ # @author Tyler Morgan
1631
+ #
1632
+ # @return [Void]
1633
+ #
1634
+ def remove_encryption_configuration()
1635
+ hash = {
1636
+ action: DISK_ENCRYPTION_ACTIONS[:none]
1637
+ }
1638
+
1639
+ @disk_encryption = hash
1640
+ @need_to_update = true
1641
+ end
1642
+
1643
+ # Interact with management account settings
1644
+ #
1645
+ # @param action [Key] one of the MGMT_ACCOUNT_ACTIONS keys
1646
+ #
1647
+ # @return The current specified management settings.
1648
+ #
1649
+ # Reference: https://developer.jamf.com/documentation#resources-with-passwords
1650
+ #
1651
+ def set_management_account(action, **opts)
1652
+ # TODO: Add proper error handling
1653
+ raise JSS::InvalidDataError, "Action must be one of: :#{MGMT_ACCOUNT_ACTIONS.keys.join ', :'}" unless MGMT_ACCOUNT_ACTIONS.include? action
1654
+
1655
+ management_data = {}
1656
+
1657
+ if action == :change_pw || action == :reset_pw
1658
+ raise JSS::MissingDataError, ":password must be provided when changing management account password" if opts[:password].nil?
1659
+
1660
+ management_data = {
1661
+ action: MGMT_ACCOUNT_ACTIONS[action],
1662
+ managed_password: opts[:password]
1663
+ }
1664
+ elsif action == :reset_random || action == :generate_pw
1665
+ raise JSS::MissingDataError, ":password_length must be provided when setting a random password" if opts[:password_length].nil?
1666
+ raise JSS::InvalidDataError, ":password_length must be an Integer" unless opts[:password_length].is_a? Integer
1667
+
1668
+ management_data = {
1669
+ action: MGMT_ACCOUNT_ACTIONS[action],
1670
+ managed_password_length: opts[:password_length]
1671
+ }
1672
+ else
1673
+ management_data = {
1674
+ action: MGMT_ACCOUNT_ACTIONS[action]
1675
+ }
1676
+ end
1677
+
1678
+ @management_account = management_data
1679
+
1680
+ @need_to_update = true
1681
+
1682
+ @management_account
1683
+
1684
+ end
1685
+
1686
+ # Check if management password matches provided password
1687
+ #
1688
+ # @param password[String] the password that is SHA256'ed to compare to the one from the API.
1689
+ #
1690
+ # @return [Boolean] The result of the comparison of the management password and provided text.
1691
+ #
1692
+ def verify_management_password(password)
1693
+ raise JSS::InvalidDataError, "Management password must be a string." unless password.is_a? String
1694
+
1695
+ raise JSS::UnsupportedError, "'#{@management_account[:action].to_s}' does not support management passwords." unless @management_account[:action] == MGMT_ACCOUNT_ACTIONS[:change_pw] || @management_account[:action] == MGMT_ACCOUNT_ACTIONS[:reset_pw]
1696
+
1697
+ return Digest::SHA256.hexdigest(password).to_s == @management_account[:managed_password_sha256].to_s
1698
+ end
1699
+
1325
1700
  ###### Actions
1326
1701
 
1327
1702
  # Try to execute this policy on this machine.
@@ -1375,6 +1750,17 @@ module JSS
1375
1750
 
1376
1751
  private
1377
1752
 
1753
+ # raise an error if a trying to set retry options when
1754
+ # frequency is not 'once per comptuer'
1755
+ #
1756
+ # @return [void]
1757
+ #
1758
+ def validate_retry_opt
1759
+ return if FREQUENCIES[:once_per_computer] == @frequency
1760
+
1761
+ raise JSS::UnsupportedError, 'Policy retry is only available when frequency is set to :once_per_computer'
1762
+ end
1763
+
1378
1764
  # raise an error if a package being added isn't valid
1379
1765
  #
1380
1766
  # @see #add_package
@@ -1439,6 +1825,64 @@ module JSS
1439
1825
  id
1440
1826
  end
1441
1827
 
1828
+ # raise an error if the directory binding being added isn't valid
1829
+ #
1830
+ # @see #add_directory_binding
1831
+ #
1832
+ # @return [Integer, nil] the valid id for the package
1833
+ #
1834
+ def validate_directory_binding_opts(identifier, opts)
1835
+ opts[:position] ||= -1
1836
+
1837
+ opts[:position] =
1838
+ case opts[:position]
1839
+ when :start then 0
1840
+ when :end then -1
1841
+ else JSS::Validate.integer(opts[:position])
1842
+ end
1843
+
1844
+ # if the given position is past the end, set it to -1 (the end)
1845
+ opts[:position] = -1 if opts[:position] > @directory_bindings.size
1846
+
1847
+ id = JSS::DirectoryBinding.valid_id identifier, api: @api
1848
+ raise JSS::NoSuchItemError, "No directory binding matches '#{identifier}'" unless id
1849
+ id
1850
+ end
1851
+
1852
+ # Raises an error if the printer being added isn't valid, additionally checks the options and sets defaults where possible.
1853
+ #
1854
+ # @see #add_printer
1855
+ #
1856
+ # @return [Integer, nil] the valid id for the package
1857
+ #
1858
+ def validate_printer_opts(identifier, opts)
1859
+ opts[:position] ||= -1
1860
+
1861
+ opts[:position] =
1862
+ case opts[:position]
1863
+ when :start then 0
1864
+ when :end then -1
1865
+ else JSS::Validate.integer(opts[:position])
1866
+ end
1867
+
1868
+ # If the given position is past the end, set it to -1 (the end)
1869
+ opts[:position] = -1 if opts[:position] > @printers.size
1870
+
1871
+ # Checks if action to be done with the printer object is provided and valid.
1872
+ raise JSS::MissingDataError, "action must be provided, must be one of :#{PRINTER_ACTIONS.keys.join(':,')}." if opts[:action].nil?
1873
+ raise JSS::InvalidDataError, "action must be one of :#{PRINTER_ACTIONS.keys.join(',:')}." unless PRINTER_ACTIONS.keys.include? opts[:action]
1874
+
1875
+
1876
+ # Checks if the make_default option is valid, and sets the default if needed.
1877
+ raise JSS::InvalidDataError, "make_default must be either true or false." unless opts[:make_default].is_a?(TrueClass) || opts[:make_default].is_a?(FalseClass) || opts[:make_default].nil?
1878
+
1879
+ opts[:make_default] = false if opts[:make_default].nil?
1880
+
1881
+ id = JSS::Printer.valid_id identifier, api: @api
1882
+ raise JSS::NoSuchItemError, "No printer matches '#{identifier}'" unless id
1883
+ id
1884
+ end
1885
+
1442
1886
  def rest_xml
1443
1887
  doc = REXML::Document.new APIConnection::XML_HEADER
1444
1888
  obj = doc.add_element RSRC_OBJECT_KEY.to_s
@@ -1447,6 +1891,10 @@ module JSS
1447
1891
  general.add_element('name').text = @name
1448
1892
  general.add_element('enabled').text = @enabled
1449
1893
  general.add_element('frequency').text = @frequency
1894
+ general.add_element('retry_event').text = @retry_event
1895
+ general.add_element('retry_attempts').text = @retry_attempts.to_s
1896
+ general.add_element('notify_on_each_failed_retry').text = @notify_failed_retries.to_s
1897
+
1450
1898
  general.add_element('target_drive').text = @target_drive
1451
1899
  general.add_element('offline').text = @offline
1452
1900
 
@@ -1475,6 +1923,22 @@ module JSS
1475
1923
  maint.add_element('user_cache').text = @user_cache.to_s
1476
1924
  maint.add_element('verify').text = @verify_startup_disk.to_s
1477
1925
 
1926
+ acct_maint = obj.add_element 'account_maintenance'
1927
+
1928
+ mgmt_acct = acct_maint.add_element 'management_account'
1929
+ JSS.hash_to_rexml_array(@management_account).each { |x| mgmt_acct << x }
1930
+
1931
+ directory_bindings = acct_maint.add_element 'directory_bindings'
1932
+ @directory_bindings.each do |b|
1933
+ directory_binding = directory_bindings.add_element 'binding'
1934
+ dbdeets = JSS.hash_to_rexml_array b
1935
+ dbdeets.each { |d| directory_binding << d }
1936
+ end
1937
+
1938
+ user_interaction = obj.add_element 'user_interaction'
1939
+ user_interaction.add_element('message_start').text = @user_message_start.to_s
1940
+ user_interaction.add_element('message_finish').text = @user_message_finish.to_s
1941
+
1478
1942
  files_processes = obj.add_element 'files_processes'
1479
1943
  JSS.hash_to_rexml_array(@files_processes).each { |f| files_processes << f }
1480
1944
 
@@ -1493,6 +1957,26 @@ module JSS
1493
1957
  sdeets.each { |d| script << d }
1494
1958
  end
1495
1959
 
1960
+ disk_encryption = obj.add_element 'disk_encryption'
1961
+
1962
+ @disk_encryption.each do |k,v|
1963
+ disk_encryption.add_element(k.to_s).text = v.to_s
1964
+ end
1965
+
1966
+ printers = obj.add_element 'printers'
1967
+ @printers.each do |pr|
1968
+ printer = printers.add_element 'printer'
1969
+ pdeets = JSS.hash_to_rexml_array pr
1970
+ pdeets.each { |d| printer << d }
1971
+ end
1972
+
1973
+ dock_items = obj.add_element 'dock_items'
1974
+ @dock_items.each do |d|
1975
+ dock_item = dock_items.add_element 'dock_item'
1976
+ ddeets = JSS.hash_to_rexml_array d
1977
+ ddeets.each { |de| dock_item << de }
1978
+ end
1979
+
1496
1980
  add_self_service_xml doc
1497
1981
  add_site_to_xml doc
1498
1982