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
@@ -0,0 +1,114 @@
1
+ module JSS
2
+ ### Module Constants
3
+ #####################################
4
+
5
+ ### Module Variables
6
+ #####################################
7
+
8
+ ### Module Methods
9
+ #####################################
10
+
11
+ ### Classes
12
+ #####################################
13
+
14
+ ### Disk Encryption Configuration object inside JSS
15
+ ###
16
+ ### More Detailed Description if needed
17
+ class DiskEncryptionConfiguration < JSS::APIObject
18
+ ## Mix-Ins
19
+ #####################################
20
+ include JSS::Updatable
21
+
22
+ ## Class Constants
23
+ #####################################
24
+
25
+ # @note Currently "Individual and Institutional" configuration type is unsupported through the API
26
+ KEY_TYPE = {
27
+ individual: 'Individual',
28
+ institutional: 'Institutional',
29
+ individual_and_institutional: 'Individual and Institutional'
30
+ }.freeze
31
+
32
+ # @note as of 10.13 Management Account cannot be used due to the lack of a secure token.
33
+ ENABLED_USERS_TYPE = {
34
+ management: "Management Account",
35
+ current: "Current or Next User"
36
+ }.freeze
37
+
38
+ ### The base for REST resources of this class
39
+ RSRC_BASE = 'diskencryptionconfigurations'.freeze
40
+
41
+ ### the hash key used for the JSON list output of all objects in the JSS
42
+ RSRC_LIST_KEY = :disk_encryption_configurations
43
+
44
+ ### The hash key used for the JSON object output
45
+ ### It's also used in various error messages
46
+ RSRC_OBJECT_KEY = :disk_encryption_configuration
47
+
48
+ ## Attributes
49
+ #####################################
50
+ attr_reader :key_type
51
+ attr_reader :file_vault_enabled_users
52
+ attr_reader :institutional_recovery_key
53
+
54
+ ## Constructor
55
+ #####################################
56
+
57
+ ###
58
+ def initialize(args = {})
59
+ super
60
+
61
+ if self.in_jss?
62
+ @key_type = @init_data[:key_type]
63
+ @file_vault_enabled_users = @init_data[:file_vault_enabled_users]
64
+ @institutional_recovery_key = @init_data[:institutional_recovery_key]
65
+ else
66
+ raise JSS::InvalidDataError, "Currently the ability to create a Disk Encryption Configuration is not possible through ruby-jss."
67
+ end
68
+
69
+
70
+
71
+ end
72
+
73
+ ## Class Methods
74
+ #####################################
75
+
76
+ # Sets what type of account is to be enabled using the new value
77
+ #
78
+ # @author Tyler Morgan
79
+ #
80
+ # @param newvalue[Symbol] One of ENABLED_USERS_TYPE
81
+ #
82
+ # @return [Void]
83
+ #
84
+ def file_vault_enabled_users=(newvalue)
85
+ raise JSS::InvalidDataError, "file_vault_enabled_users must be one of :#{ENABLED_USERS_TYPE.keys.join(',:')}." unless ENABLED_USERS_TYPE.keys.include? newvalue
86
+
87
+ @file_vault_enabled_users = ENABLED_USERS_TYPE[newvalue]
88
+
89
+ @need_to_update = true
90
+
91
+ end
92
+
93
+ ## Private Instance Methods
94
+ #####################################
95
+
96
+ private
97
+
98
+ def rest_xml
99
+ raise JSS::UnsupportedError, "Key type of \"Individual and Institutional\" is currently unsupported via. API. So changes are unable to be saved." if @key_type == KEY_TYPE[:individual_and_institutional]
100
+ doc = REXML::Document.new
101
+ disk_encryption_configuration = doc.add_element 'disk_encryption_configuration'
102
+
103
+ disk_encryption_configuration.add_element('id').text = @id
104
+ disk_encryption_configuration.add_element('name').text = @name
105
+ disk_encryption_configuration.add_element('key_type').text = @key_type
106
+ disk_encryption_configuration.add_element('file_vault_enabled_users').text = @file_vault_enabled_users
107
+
108
+ doc.to_s
109
+
110
+
111
+
112
+ end
113
+ end
114
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2019 Pixar
1
+ # Copyright 2020 Pixar
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "Apache License")
4
4
  # with the following modification; you may not use this file except in
@@ -27,7 +27,7 @@ module JSS
27
27
  # Module Methods
28
28
  #####################################
29
29
 
30
- # A Distribution Point in the JSS
30
+ # A FileShare Distribution Point in the JSS
31
31
  #
32
32
  # As well as the normal Class and Instance methods for {APIObject} subclasses, the
33
33
  # DistributionPoint class provides more interaction with other parts of the API.
@@ -43,6 +43,11 @@ module JSS
43
43
  # and unmount it with {#unmount}. The {JSS::Package} and possibly {JSS::Script} classes use this to upload
44
44
  # items to the master.
45
45
  #
46
+ # NOTE: This class only deals with FileShare Distribution Points.
47
+ # There is no access to the Cloud Distribution Point in the classic API.
48
+ # See the .master_distribution_point and .my_distribution_point class methods
49
+ # for how they handle things when the Cloud DP is the master.
50
+ #
46
51
  # @see JSS::APIObject
47
52
  #
48
53
  class DistributionPoint < JSS::APIObject
@@ -80,32 +85,92 @@ module JSS
80
85
  # Class Methods
81
86
  #####################################
82
87
 
83
- # Get the DistributionPoint instance for the master
84
- # distribution point in the JSS. If there's only one
85
- # in the JSS, return it even if not marked as master.
88
+ # Get the DistributionPoint instance for the master distribution point.
89
+ #
90
+ # If the Cloud Dist Point is master, then the classic API has no way to
91
+ # know that or access it. In that case you can provide the 'default:' parameter.
92
+ # Give it the name or id of any dist. point to be used instead, or give it
93
+ # :random to randomly choose one.
94
+ #
95
+ # If there are no fileshare dist points defined (the cloud is the only one)
96
+ # then this whole class can't really be used.
86
97
  #
87
98
  # @param refresh[Boolean] should the distribution point be re-queried?
88
99
  #
100
+ # @param default[String, Integer, Symbol] Name or ID of a dist point to use
101
+ # if no master is found, or :random to randomly choose one.
102
+ #
89
103
  # @param api[JSS::APIConnection] which API connection should we query?
90
104
  #
91
105
  # @return [JSS::DistributionPoint]
92
106
  #
93
- def self.master_distribution_point(refresh = false, api: JSS.api)
94
- api.master_distribution_point refresh
107
+ def self.master_distribution_point(refresh = false, default: nil, api: JSS.api)
108
+ @master_distribution_point = nil if refresh
109
+ return @master_distribution_point if @master_distribution_point
110
+
111
+ all_ids(refresh, api: api).each do |dp_id|
112
+ dp = fetch id: dp_id, api: api
113
+ if dp.master?
114
+ @master_distribution_point = dp
115
+ break
116
+ end
117
+ end
118
+
119
+ # If we're here, the Cloud DP might be master, but there's no
120
+ # access to it in the API :/
121
+ raise JSS::NoSuchItemError, 'No Master FileShare Distribtion Point. Use the default: parameter if needed.' unless @master_distribution_point || default
122
+
123
+ if @master_distribution_point
124
+ @master_distribution_point
125
+ elsif default == :random
126
+ @master_distribution_point = fetch(id: all_ids.sample, api: api)
127
+ else
128
+ @master_distribution_point = fetch(default, api: api)
129
+ end
95
130
  end
96
131
 
97
132
  # Get the DistributionPoint instance for the machine running
98
133
  # this code, based on its IP address. If none is defined for this IP address,
99
- # use the result of master_distribution_point
134
+ # use the name or id provided as default. If no default: is provided,
135
+ # the master dp is used. If no master dp available (meaning its the
136
+ # cloud dp) then use a randomly chosen dp.
100
137
  #
101
138
  # @param refresh[Boolean] should the distribution point be re-queried?
102
139
  #
140
+ # @param default[String, Integer, Symbol] the name or id of a Dist Point
141
+ # to use if none is specified for this IP addr. Or :master, to use the
142
+ # master DP, or :random to use a randomly chosen one. If :master is
143
+ # specified and there is no master (master is cloud) then a random one is used.
144
+ #
103
145
  # @param api[JSS::APIConnection] which API connection should we query?
104
146
  #
105
147
  # @return [JSS::DistributionPoint]
106
148
  #
107
- def self.my_distribution_point(refresh = false, api: JSS.api)
108
- api.my_distribution_point refresh
149
+ def self.my_distribution_point(refresh = false, default: :master, api: JSS.api)
150
+ @my_distribution_point = nil if refresh
151
+ return @my_distribution_point if @my_distribution_point
152
+
153
+ my_net_seg_id = JSS::NetworkSegment.my_network_segment refresh, api: api
154
+
155
+ if my_net_seg_id
156
+ my_net_seg = JSS::NetworkSegment.fetch id: my_net_seg_id, api: api
157
+ my_dp_name = my_net_seg.distribution_point
158
+ @my_distribution_point = fetch name: my_dp_name, api: api if my_dp_name
159
+ end # if my_net_seg_id
160
+
161
+ return @my_distribution_point if @my_distribution_point
162
+
163
+ @my_distribution_point =
164
+ case default
165
+ when String
166
+ fetch name: default, api: api
167
+ when Integer
168
+ fetch id: default, api: api
169
+ when :master
170
+ master_distribution_point refresh, default: :random, api: api
171
+ when :random
172
+ fetch id: all_ids(refresh).sample, api: api
173
+ end
109
174
  end
110
175
 
111
176
  # Class Attributes
@@ -274,7 +339,7 @@ module JSS
274
339
  # Seemms the read-only pw isn't available in the API
275
340
 
276
341
  # if we mount for fileservice, where's the mountpoint?
277
- @mountpoint = Pathname.new "/#{DEFAULT_MOUNTPOINT_DIR}/#{DEFAULT_MOUNTPOINT_PREFIX}#{@id}"
342
+ @mountpoint = DEFAULT_MOUNTPOINT_DIR + "#{DEFAULT_MOUNTPOINT_PREFIX}#{@id}"
278
343
  end # init
279
344
 
280
345
  # Check the validity of a password.
@@ -315,37 +380,15 @@ module JSS
315
380
  # @return [FalseClass, Symbol] false if not reachable, otherwise :http or :mountable
316
381
  #
317
382
  def reachable_for_download?(pw = '', check_http = true)
318
- pw ||= ''
319
- http_checked = ''
320
- if check_http && http_downloads_enabled
321
- if @username_password_required
322
- # we don't check the pw here, because if the connection fails, we'll
323
- # drop down below to try the password for mounting.
324
- # we'll escape all the chars that aren't unreserved
325
- # reserved_chars = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}]")
326
- user_pass = "#{CGI.escape @http_username.to_s}:#{CGI.escape ro_pw.to_s}@"
327
- url = @http_url.sub "://#{@ip_address}", "://#{user_pass}#{@ip_address}"
328
- else
329
- url = @http_url
330
- end
331
-
332
- begin
333
- open(url).read
334
- return :http
335
- rescue
336
- http_checked = 'http and '
337
- end
338
- end # if check_http && http_downloads_enabled
339
-
383
+ return :http if check_http && http_reachable?(pw)
340
384
  return :mountable if mounted?
341
-
342
385
  return false unless check_pw :ro, pw
343
386
 
344
387
  begin
345
388
  mount pw, :ro
346
- return :mountable
389
+ :mountable
347
390
  rescue
348
- return false
391
+ false
349
392
  ensure
350
393
  unmount
351
394
  end
@@ -469,6 +512,23 @@ module JSS
469
512
  ######################################
470
513
  private
471
514
 
515
+ # can the dp be reached for http downloads?
516
+ def http_reachable?(pw)
517
+ return false unless http_downloads_enabled
518
+
519
+ url =
520
+ if @username_password_required
521
+ user_pass = "#{CGI.escape @http_username.to_s}:#{CGI.escape pw.to_s}@"
522
+ @http_url.sub "://#{@ip_address}", "://#{user_pass}#{@ip_address}"
523
+ else
524
+ @http_url
525
+ end
526
+ URI.parse(url).read
527
+ true
528
+ rescue
529
+ false
530
+ end
531
+
472
532
  # Unused - until I get around to making DP's updatable
473
533
  #
474
534
  # the XML representation of the current state of this object,
@@ -0,0 +1,137 @@
1
+ ### Copyright 2019 Rixar
2
+
3
+ ###
4
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ ### with the following modification; you may not use this file except in
6
+ ### compliance with the Apache License and the following modification to it:
7
+ ### Section 6. Trademarks. is deleted and replaced with:
8
+ ###
9
+ ### 6. Trademarks. This License does not grant permission to use the trade
10
+ ### names, trademarks, service marks, or product names of the Licensor
11
+ ### and its affiliates, except as required to comply with Section 4(c) of
12
+ ### the License and to reproduce the content of the NOTICE file.
13
+ ###
14
+ ### You may obtain a copy of the Apache License at
15
+ ###
16
+ ### http://www.apache.org/licenses/LICENSE-2.0
17
+ ###
18
+ ### Unless required by applicable law or agreed to in writing, software
19
+ ### distributed under the Apache License with the above modification is
20
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ ### KIND, either express or implied. See the Apache License for the specific
22
+ ### language governing permissions and limitations under the Apache License.
23
+ ###
24
+ ###
25
+
26
+ module JSS
27
+
28
+ # Module Variables
29
+ #####################################
30
+
31
+ # Module Methods
32
+ #####################################
33
+
34
+ # Classes
35
+ #####################################
36
+
37
+ # A Dock Item in the JSS.
38
+ # These are rather simple. They have an ID, name, path, type, and contents which is read-only
39
+ #
40
+ # @see JSS::APIObject
41
+ #
42
+ class DockItem < JSS::APIObject
43
+
44
+ # Mix-Ins
45
+ #####################################
46
+ include JSS::Creatable
47
+ include JSS::Updatable
48
+
49
+ # Class Methods
50
+ #####################################
51
+
52
+ # Class Constants
53
+ #####################################
54
+
55
+ # The Dock Item type
56
+ DOCK_ITEM_TYPE = [
57
+ "App",
58
+ "File",
59
+ "Folder"
60
+ ].freeze
61
+
62
+ # The base for REST resources of this class
63
+ RSRC_BASE = 'dockitems'.freeze
64
+
65
+ # the hash key used for the JSON list output of all objects in the JSS
66
+ RSRC_LIST_KEY = :dock_items
67
+
68
+ # The hash key used for the JSON object output.
69
+ # It's also used in various error messages
70
+ RSRC_OBJECT_KEY = :dock_item
71
+
72
+ # the object type for this object in
73
+ # the object history table.
74
+ # See {APIObject#add_object_history_entry}
75
+ #OBJECT_HISTORY_OBJECT_TYPE = 41
76
+
77
+ # Attributes
78
+ #####################################
79
+ attr_reader :id
80
+ attr_reader :name
81
+ attr_reader :type
82
+ attr_reader :path
83
+
84
+ # Constructor
85
+ # @see JSS::APIObject.initialize
86
+ #####################################
87
+ def initialize(args = {})
88
+ super args
89
+
90
+ @type = "App" unless !@init_data[:type].nil?
91
+ @type = @init_data[:type]
92
+ @path = @init_data[:path]
93
+ end
94
+
95
+ # Public Instance Methods
96
+ #####################################
97
+
98
+ # set the type
99
+ #
100
+ # @param newval[String] the new app type
101
+ #
102
+ # @return [void]
103
+ #
104
+ def type=(newval)
105
+ raise JSS::InvalidDataError, 'Type must be a string' unless message.is_a? String
106
+ raise JSS::InvalidDataError, "Type must be one of the following: #{DOCK_ITEM_TYPE.to_s}; not #{newval.to_s}" unless DOCK_ITEM_TYPE.include? newval.to_s
107
+ @type = newval
108
+ @need_to_update = true
109
+ end
110
+
111
+ # set the path
112
+ #
113
+ # @param newval[String] the new app path
114
+ def path=(newval)
115
+ raise JSS::InvalidDataError, 'Path must be a String' unless newval.is_a? String
116
+ @path = newval
117
+ @need_to_update = true
118
+ end
119
+
120
+ # private instance methods
121
+ ######################
122
+ private
123
+
124
+ # the xml formated data for adding or updating this in the JSS
125
+ #
126
+ def rest_xml
127
+ doc = REXML::Document.new APIConnection::XML_HEADER
128
+ ns = doc.add_element RSRC_OBJECT_KEY.to_s
129
+ ns.add_element('name').text = @name
130
+ ns.add_element('type').text = @type.to_s
131
+ ns.add_element('path').text = @path.to_s
132
+ doc.to_s
133
+ end # rest_xml
134
+ end
135
+
136
+
137
+ end