ruby-jss 1.2.4a3 → 1.3.2

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 (248) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +180 -1
  3. data/README.md +4 -2
  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 +2 -1
  9. data/lib/jamf/api/abstract_classes/advanced_search.rb +1 -1
  10. data/lib/jamf/api/abstract_classes/collection_resource.rb +54 -38
  11. data/lib/jamf/api/abstract_classes/generic_reference.rb +1 -1
  12. data/lib/jamf/api/abstract_classes/json_object.rb +16 -10
  13. data/lib/jamf/api/abstract_classes/prestage.rb +111 -35
  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 +166 -69
  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 +87 -16
  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 +6 -4
  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 +5 -3
  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 +3 -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 +3 -3
  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 -1
  73. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +110 -18
  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 +9 -2
  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 +119 -0
  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 +59 -4
  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 +6 -8
  92. data/lib/jamf/exceptions.rb +6 -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 -3
  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 +5 -2
  119. data/lib/jss/api_connection.rb +3 -30
  120. data/lib/jss/api_object.rb +16 -3
  121. data/lib/jss/api_object/account.rb +1 -1
  122. data/lib/jss/api_object/advanced_search.rb +1 -1
  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/building.rb +1 -1
  127. data/lib/jss/api_object/categorizable.rb +1 -1
  128. data/lib/jss/api_object/category.rb +1 -1
  129. data/lib/jss/api_object/computer.rb +12 -6
  130. data/lib/jss/api_object/computer/application_installs.rb +1 -1
  131. data/lib/jss/api_object/computer_invitation.rb +1 -1
  132. data/lib/jss/api_object/configuration_profile.rb +4 -2
  133. data/lib/jss/api_object/configuration_profile/mobile_device_configuration_profile.rb +1 -1
  134. data/lib/jss/api_object/configuration_profile/osx_configuration_profile.rb +1 -1
  135. data/lib/jss/api_object/creatable.rb +1 -1
  136. data/lib/jss/api_object/criteriable.rb +10 -5
  137. data/lib/jss/api_object/criteriable/criteria.rb +26 -10
  138. data/lib/jss/api_object/criteriable/criterion.rb +1 -1
  139. data/lib/jss/api_object/department.rb +1 -1
  140. data/lib/jss/api_object/directory_binding.rb +273 -0
  141. data/lib/jss/api_object/directory_binding_type.rb +90 -0
  142. data/lib/jss/api_object/directory_binding_type/active_directory.rb +502 -0
  143. data/lib/jss/api_object/directory_binding_type/admitmac.rb +525 -0
  144. data/lib/jss/api_object/directory_binding_type/centrify.rb +212 -0
  145. data/lib/jss/api_object/directory_binding_type/open_directory.rb +178 -0
  146. data/lib/jss/api_object/directory_binding_type/powerbroker_identity_services.rb +73 -0
  147. data/lib/jss/api_object/disk_encryption_configurations.rb +114 -0
  148. data/lib/jss/api_object/distribution_point.rb +96 -36
  149. data/lib/jss/api_object/dock_item.rb +137 -0
  150. data/lib/jss/api_object/ebook.rb +1 -1
  151. data/lib/jss/api_object/extendable.rb +67 -28
  152. data/lib/jss/api_object/extension_attribute.rb +1 -1
  153. data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +1 -1
  154. data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +1 -1
  155. data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +1 -1
  156. data/lib/jss/api_object/group.rb +1 -1
  157. data/lib/jss/api_object/group/computer_group.rb +1 -1
  158. data/lib/jss/api_object/group/mobile_device_group.rb +1 -1
  159. data/lib/jss/api_object/group/user_group.rb +1 -1
  160. data/lib/jss/api_object/ibeacon.rb +1 -1
  161. data/lib/jss/api_object/ldap_server.rb +1 -1
  162. data/lib/jss/api_object/locatable.rb +1 -1
  163. data/lib/jss/api_object/mac_application.rb +1 -1
  164. data/lib/jss/api_object/management_history.rb +23 -22
  165. data/lib/jss/api_object/management_history/audit_event.rb +1 -1
  166. data/lib/jss/api_object/management_history/casper_imaging_log.rb +1 -1
  167. data/lib/jss/api_object/management_history/casper_remote_log.rb +1 -1
  168. data/lib/jss/api_object/management_history/computer_usage_log.rb +1 -1
  169. data/lib/jss/api_object/management_history/ebook.rb +1 -1
  170. data/lib/jss/api_object/management_history/hashlike.rb +1 -1
  171. data/lib/jss/api_object/management_history/mac_app_store_app.rb +1 -1
  172. data/lib/jss/api_object/management_history/mdm_command.rb +1 -1
  173. data/lib/jss/api_object/management_history/mobile_device_app.rb +1 -1
  174. data/lib/jss/api_object/management_history/policy_log.rb +1 -1
  175. data/lib/jss/api_object/management_history/screen_sharing_log.rb +1 -1
  176. data/lib/jss/api_object/management_history/user_location_change.rb +1 -1
  177. data/lib/jss/api_object/matchable.rb +1 -1
  178. data/lib/jss/api_object/mdm.rb +1 -1
  179. data/lib/jss/api_object/mobile_device.rb +29 -6
  180. data/lib/jss/api_object/mobile_device_application.rb +13 -1
  181. data/lib/jss/api_object/netboot_server.rb +1 -1
  182. data/lib/jss/api_object/network_segment.rb +153 -59
  183. data/lib/jss/api_object/package.rb +107 -42
  184. data/lib/jss/api_object/patch_policy.rb +1 -1
  185. data/lib/jss/api_object/patch_source.rb +1 -1
  186. data/lib/jss/api_object/patch_source/patch_external_source.rb +1 -1
  187. data/lib/jss/api_object/patch_source/patch_internal_source.rb +1 -1
  188. data/lib/jss/api_object/patch_title.rb +1 -1
  189. data/lib/jss/api_object/patch_title/version.rb +1 -1
  190. data/lib/jss/api_object/peripheral.rb +1 -1
  191. data/lib/jss/api_object/peripheral_type.rb +1 -1
  192. data/lib/jss/api_object/policy.rb +380 -5
  193. data/lib/jss/api_object/printer.rb +440 -0
  194. data/lib/jss/api_object/purchasable.rb +1 -1
  195. data/lib/jss/api_object/removable_macaddr.rb +1 -1
  196. data/lib/jss/api_object/restricted_software.rb +1 -1
  197. data/lib/jss/api_object/scopable.rb +1 -1
  198. data/lib/jss/api_object/scopable/scope.rb +257 -37
  199. data/lib/jss/api_object/script.rb +1 -1
  200. data/lib/jss/api_object/self_servable.rb +7 -7
  201. data/lib/jss/api_object/self_servable/icon.rb +1 -1
  202. data/lib/jss/api_object/sitable.rb +6 -2
  203. data/lib/jss/api_object/site.rb +1 -1
  204. data/lib/jss/api_object/software_update_server.rb +1 -1
  205. data/lib/jss/api_object/updatable.rb +1 -1
  206. data/lib/jss/api_object/uploadable.rb +1 -1
  207. data/lib/jss/api_object/user.rb +5 -3
  208. data/lib/jss/api_object/vppable.rb +1 -1
  209. data/lib/jss/api_object/webhook.rb +1 -1
  210. data/lib/jss/client.rb +1 -1
  211. data/lib/jss/client/jamf_binary.rb +1 -1
  212. data/lib/jss/client/jamf_helper.rb +1 -1
  213. data/lib/jss/client/management_action.rb +1 -1
  214. data/lib/jss/compatibility.rb +1 -1
  215. data/lib/jss/composer.rb +2 -2
  216. data/lib/jss/configuration.rb +1 -1
  217. data/lib/jss/db_connection.rb +1 -1
  218. data/lib/jss/exceptions.rb +1 -1
  219. data/lib/jss/ruby_extensions.rb +1 -1
  220. data/lib/jss/ruby_extensions/array.rb +1 -1
  221. data/lib/jss/ruby_extensions/filetest.rb +1 -1
  222. data/lib/jss/ruby_extensions/hash.rb +1 -1
  223. data/lib/jss/ruby_extensions/ipaddr.rb +1 -1
  224. data/lib/jss/ruby_extensions/pathname.rb +1 -1
  225. data/lib/jss/ruby_extensions/string.rb +1 -1
  226. data/lib/jss/ruby_extensions/string/backports.rb +1 -1
  227. data/lib/jss/ruby_extensions/string/conversions.rb +1 -1
  228. data/lib/jss/ruby_extensions/string/predicates.rb +14 -4
  229. data/lib/jss/ruby_extensions/time.rb +1 -1
  230. data/lib/jss/server.rb +1 -1
  231. data/lib/jss/utility.rb +9 -23
  232. data/lib/jss/validate.rb +1 -1
  233. data/lib/jss/version.rb +2 -2
  234. data/lib/jss/xml_workaround.rb +1 -1
  235. data/lib/ruby-jss.rb +1 -1
  236. data/test/bin/runtests +1 -1
  237. data/test/lib/testhelper.rb +1 -1
  238. data/test/lib/testhelper/auth.rb +1 -1
  239. data/test/lib/testhelper/patch_mgmt.rb +1 -1
  240. data/test/specs/api_connection_spec.rb +1 -1
  241. data/test/specs/patch01_source_spec.rb +1 -1
  242. data/test/specs/patch02_internal_source_spec.rb +1 -1
  243. data/test/specs/patch03_external_source_spec.rb +1 -1
  244. data/test/specs/patch04_titles_spec.rb +1 -1
  245. data/test/specs/patch05_policies_spec.rb +1 -1
  246. data/test/specs/patch06_cleanup_spec.rb +1 -1
  247. data/test/specs/policy_spec.rb +1 -1
  248. metadata +16 -4
@@ -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")
@@ -0,0 +1,119 @@
1
+ # Copyright 2020 Pixar
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
+ # The Module
27
+ module Jamf
28
+
29
+ # Classes
30
+ #####################################
31
+
32
+ # A building defined in the JSS
33
+ class TimeZone < Jamf::CollectionResource
34
+
35
+ # Mix-Ins
36
+ #####################################
37
+
38
+ extend Jamf::Immutable
39
+ extend Jamf::UnCreatable
40
+ extend Jamf::UnDeletable
41
+
42
+ # Constants
43
+ #####################################
44
+
45
+ RSRC_VERSION = 'v1'.freeze
46
+
47
+ RSRC_PATH = 'time-zones'.freeze
48
+
49
+ # Object Model / Attributes
50
+ # See APIObject class documentation for details
51
+ # of how the OBJECT_MODEL hash works.
52
+ #####################################
53
+ OBJECT_MODEL = {
54
+
55
+ # @!attribute [r] zoneId
56
+ # @return [String]
57
+ zoneId: {
58
+ class: :string,
59
+ identifier: :primary,
60
+ aliases: [:id]
61
+ },
62
+
63
+ # @!attribute displayName
64
+ # @return [String]
65
+ displayName: {
66
+ class: :string,
67
+ identifier: true,
68
+ aliases: [:name]
69
+ },
70
+
71
+ # @!attribute [r] region
72
+ # @return [String]
73
+ region: {
74
+ class: :string
75
+ }
76
+ }.freeze
77
+ parse_object_model
78
+
79
+ # The offset from UTC, as a string.
80
+ #
81
+ # This is as it would appear at the end of an ISO8601 formatted time,
82
+ # e.g. -0945 or +1200
83
+ #
84
+ # Note that ISO8601 accepts the formats: +/-hh:mm, +/-hhmm, or +/-hh
85
+ #
86
+ # @return [Integer] The offset from UTC, as a string
87
+ #
88
+ def utc_offset_str
89
+ return @utc_offset_str if @utc_offset_str
90
+
91
+ displayName =~ /\(([+-]\d{4})\)/
92
+ @utc_offset_str = Regexp.last_match[1]
93
+ end
94
+
95
+ # @return [Integer] The offset from UTC, in seconds
96
+ #
97
+ def utc_offset
98
+ return @utc_offset if @utc_offset
99
+
100
+ sign = utc_offset_str[0]
101
+ secs = utc_offset_str[1..2].to_i * 3600
102
+ secs += utc_offset_str[3..4].to_i * 60
103
+ # negate if needed
104
+ @utc_offset = sign == '+' ? secs : -secs
105
+ end
106
+
107
+ # Give a Time object, whats the matching local time in this TimeZone?
108
+ #
109
+ # @param othertime[Time] a Time or Jamf::Timestamp object
110
+ #
111
+ # @return [Time] othertime, in the local time in this time zone
112
+ #
113
+ def localtime(othertime)
114
+ othertime.getlocal utc_offset
115
+ end
116
+
117
+ end # class
118
+
119
+ end # module
@@ -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")
@@ -24,7 +24,7 @@
24
24
  ###
25
25
 
26
26
  ###
27
- module JSS
27
+ module Jamf
28
28
 
29
29
  # This class represents a Jamf/JSS Client computer, on which
30
30
  # this code is running.
@@ -78,10 +78,17 @@ module JSS
78
78
  # the path to a users byhost folder from home
79
79
  USER_PREFS_BYHOST_FOLDER = 'Library/Preferences/ByHost/'
80
80
 
81
- # Class Methods
82
- #####################################
81
+ # If some processs C has a parent process P whose command (via ps -o comm)
82
+ # matches this, then process C is being run by Jamf
83
+ POLICY_SCRIPT_CMD_RE = %r{sh -c PATH=\$PATH:/usr/local/jamf/bin; '/Library/Application Support/JAMF/tmp/.* >& '/Library/Application Support/JAMF/tmp/\d+.tmp}.freeze
83
84
 
85
+ # If some processs C has a parent process P whose command (via ps -o comm)
86
+ # matching POLICY_SCRIPT_CMD_RE, and process P has a parent process G that
87
+ # matches this (C is grandchild of G), then process C is being run by a Jamf policy
88
+ POLICY_CMD_RE = %r{/bin/jamf policy }.freeze
84
89
 
90
+ # Class Methods
91
+ #####################################
85
92
 
86
93
  # Get the current IP address as a String.
87
94
  #
@@ -292,6 +299,54 @@ module JSS
292
299
  dir ? Pathname.new(dir) : nil
293
300
  end
294
301
 
302
+ # Search up the process lineage to see if any ancestor processes indicate
303
+ # that the current process is being run by a Jamf Policy.
304
+ #
305
+ # @return [Boolean] Is the current process being run as a script by a Jamf Policy?
306
+ #
307
+ def self.script_running_via_policy?
308
+ root_ps_lines = `ps -u root -x -o pid -o ppid -o user -o command`.lines
309
+
310
+ parent_pid, _parent_user, parent_command = parent_pid_user_and_cmd Process.pid, root_ps_lines
311
+ return false unless parent_pid
312
+
313
+ until parent_command =~ POLICY_SCRIPT_CMD_RE || parent_pid.nil?
314
+ parent_pid, _parent_user, parent_command = parent_pid_user_and_cmd parent_pid, root_ps_lines
315
+ return false if parent_pid.zero?
316
+ end
317
+ return false if parent_pid.nil?
318
+
319
+ # if we're here, our parent is a jamf process, lets confirm that its
320
+ # a jamf policy
321
+ until parent_command =~ POLICY_CMD_RE || parent_pid.nil?
322
+ parent_pid, _parent_user, parent_command = parent_pid_user_and_cmd parent_pid, root_ps_lines
323
+ return false if parent_pid.zero?
324
+ end
325
+ !parent_pid.nil?
326
+ end
327
+
328
+ # given a pid and optionally the output of `ps -o pid -o ppid -o user -o command`
329
+ # return an array with the pid, user, and command of the pid's parent process
330
+ #
331
+ # @param pid [Integer, String] the process id for which we want parent info
332
+ #
333
+ # @param ps_lines [Array<String>] the lines of output from
334
+ # `ps -o pid -o ppid -o user -o command` possibly with other options.
335
+ # If omitted, `ps -a -x -o pid -o ppid -o user -o command` will be used
336
+ #
337
+ # @return [Array<Integer, String, String>] the pid, user, and commandline
338
+ # of the parent process of the given pid. All will be nil if not found
339
+ #
340
+ def self.parent_pid_user_and_cmd(pid, ps_lines = nil)
341
+ ps_lines ||= `ps -a -x -o pid -o ppid -o user -o command`.lines
342
+
343
+ parent_ps_line = ps_lines.select { |l| l =~ /^\s*#{pid}\s/ }.first
344
+ return [nil, nil, nil] unless parent_ps_line
345
+
346
+ parent_ps_line =~ /^\s*\d+\s+(\d+)\s+(\S+)\s+(.*)$/
347
+ [Regexp.last_match(1).to_i, Regexp.last_match(2), Regexp.last_match(3)]
348
+ end
349
+
295
350
  end # class Client
296
351
 
297
352
  end # module
@@ -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")
@@ -103,8 +103,8 @@ module Jamf
103
103
  # The Pathname to the machine-wide preferences
104
104
  GLOBAL_CONF_FILE = Pathname.new "/etc/#{CONF_FILENAME}"
105
105
 
106
- # The Pathname to the user-specific preferences plist
107
- USER_CONF_FILE = ENV['HOME'] ? Pathname.new("~/.#{CONF_FILENAME}").expand_path : nil
106
+ # The Pathname to the user-specific preferences plist if there is one
107
+ USER_CONF_FILE = Pathname.new("#{ENV['HOME']}/.#{CONF_FILENAME}")
108
108
 
109
109
  # The attribute keys we maintain, and the type they should be stored as
110
110
  CONF_KEYS = {
@@ -134,7 +134,6 @@ module Jamf
134
134
  # Constructor
135
135
  #####################################
136
136
 
137
-
138
137
  # Initialize!
139
138
  #
140
139
  def initialize
@@ -145,7 +144,6 @@ module Jamf
145
144
  # Public Instance Methods
146
145
  #####################################
147
146
 
148
-
149
147
  # Clear all values
150
148
  #
151
149
  # @return [void]
@@ -196,9 +194,9 @@ module Jamf
196
194
  def save(file)
197
195
  path =
198
196
  case file
199
- when :global then GLOBAL_CONF_FILE
200
- when :user then USER_CONF_FILE
201
- else Pathname.new(file)
197
+ when :global then GLOBAL_CONF_FILE
198
+ when :user then USER_CONF_FILE
199
+ else Pathname.new(file)
202
200
  end
203
201
 
204
202
  raise Jamf::MissingDataError, "No HOME environment variable, can't write to user conf file." if path.nil?
@@ -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")
@@ -82,6 +82,11 @@ module Jamf
82
82
  #
83
83
  class AuthenticationError < RuntimeError; end
84
84
 
85
+ # InvalidTokenError - raise this when a connection token is
86
+ # expired or otherwise invalid
87
+ #
88
+ class InvalidTokenError < RuntimeError; end
89
+
85
90
  # ConflictError - raise this when
86
91
  # attempts to PUT or PUSH to the API
87
92
  # result in a 409 Conflict http error.
@@ -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")
@@ -34,3 +34,4 @@ require 'jamf/ruby_extensions/object.rb'
34
34
  require 'jamf/ruby_extensions/pathname.rb'
35
35
  require 'jamf/ruby_extensions/string.rb'
36
36
  require 'jamf/ruby_extensions/array.rb'
37
+ require 'jamf/ruby_extensions/dig.rb'
@@ -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")
@@ -26,7 +26,7 @@
26
26
  require 'jamf/ruby_extensions/array/predicates'
27
27
  require 'jamf/ruby_extensions/array/utils'
28
28
 
29
- #
29
+ # an array
30
30
  class Array
31
31
 
32
32
  include JamfRubyExtensions::Array::Predicates
@@ -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")
@@ -25,6 +25,7 @@ module JamfRubyExtensions
25
25
 
26
26
  module Array
27
27
 
28
+ # Useful monkey patches for Array
28
29
  module Utils
29
30
 
30
31
  # Fetch a string from an Array case-insensitively,
@@ -40,7 +41,7 @@ module JamfRubyExtensions
40
41
  # nil if it doesn't exist
41
42
  #
42
43
  def j_ci_fetch(somestring)
43
- each { |s| return s if s.is_a?(String) && s.casecmp?(somestring) }
44
+ each { |s| return s if s.respond_to?(:casecmp?) && s.casecmp?(somestring) }
44
45
  nil
45
46
  end
46
47
 
@@ -51,7 +52,7 @@ module JamfRubyExtensions
51
52
  # @return [Boolean]
52
53
  #
53
54
  def j_ci_include?(somestring)
54
- any? { |s| s.casecmp? somestring if s.is_a? String }
55
+ any? { |s| s.respond_to?(:casecmp?) && s.casecmp?(somestring) }
55
56
  end
56
57
 
57
58
  end # module
@@ -0,0 +1,52 @@
1
+ # Copyright 2020 Pixar
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
+ # Gratefully borrowed from https://github.com/Invoca/ruby_dig
25
+
26
+ # modulize monkey patches
27
+ module RubyDig
28
+
29
+ def dig(key, *rest)
30
+ value = self[key]
31
+ if value.nil? || rest.empty?
32
+ value
33
+ elsif value.respond_to?(:dig)
34
+ value.dig(*rest)
35
+ else
36
+ raise TypeError, "#{value.class} does not have #dig method"
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ if RUBY_VERSION < '2.3'
43
+
44
+ # arrays
45
+ class Array; include RubyDig; end
46
+
47
+ # hashes
48
+ class Hash; include RubyDig; end
49
+
50
+ # ostructs
51
+ class OpenStruct; include RubyDig; end
52
+ end