ruby-jss 1.3.3 → 1.6.0b1

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

Potentially problematic release.


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

Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +142 -0
  3. data/THANKS.md +3 -2
  4. data/lib/jamf.rb +18 -17
  5. data/lib/jamf/api/base_classes/collection_resource.rb +613 -0
  6. data/lib/jamf/api/{abstract_classes → base_classes}/json_object.rb +109 -101
  7. data/lib/jamf/api/{abstract_classes → base_classes}/prestage.rb +55 -30
  8. data/lib/jamf/api/{abstract_classes → base_classes}/resource.rb +10 -6
  9. data/lib/jamf/api/{abstract_classes → base_classes}/singleton_resource.rb +4 -3
  10. data/lib/jamf/api/connection.rb +13 -9
  11. data/lib/jamf/api/connection/api_error.rb +8 -8
  12. data/lib/jamf/api/connection/token.rb +36 -15
  13. data/lib/jamf/api/json_objects/device_enrollment_device.rb +14 -7
  14. data/lib/jamf/api/json_objects/{location.rb → device_enrollment_device_sync_state.rb} +27 -41
  15. data/lib/jamf/api/json_objects/device_enrollment_sync_status.rb +1 -1
  16. data/lib/jamf/api/json_objects/{attachment.rb → locale.rb} +14 -23
  17. data/lib/jamf/api/json_objects/md_prestage_name.rb +1 -1
  18. data/lib/jamf/api/json_objects/md_prestage_names.rb +2 -2
  19. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +50 -1
  20. data/lib/jamf/api/json_objects/prestage_assignment.rb +2 -2
  21. data/lib/jamf/api/json_objects/prestage_location.rb +3 -3
  22. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +7 -7
  23. data/lib/jamf/api/json_objects/prestage_scope.rb +1 -1
  24. data/lib/jamf/api/{resources/collection_resources → json_objects}/time_zone.rb +9 -23
  25. data/lib/jamf/api/mixins/{abstract.rb → base_class.rb} +34 -16
  26. data/lib/jamf/api/mixins/bulk_deletable.rb +27 -6
  27. data/lib/jamf/api/mixins/change_log.rb +201 -51
  28. data/lib/jamf/api/{resources/collection_resources/computer.rb → mixins/filterable.rb} +19 -17
  29. data/lib/jamf/api/mixins/pageable.rb +208 -0
  30. data/lib/jamf/api/{json_objects/installed_application.rb → mixins/sortable.rb} +33 -33
  31. data/lib/jamf/api/resources/collection_resources/building.rb +16 -9
  32. data/lib/jamf/api/resources/collection_resources/category.rb +5 -4
  33. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +12 -5
  34. data/lib/jamf/api/resources/collection_resources/department.rb +1 -3
  35. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +13 -13
  36. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +11 -3
  37. data/lib/jamf/api/resources/collection_resources/mobile_device_prestage.rb +25 -23
  38. data/lib/jamf/api/resources/collection_resources/script.rb +61 -25
  39. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +15 -5
  40. data/lib/jamf/api/resources/singleton_resources/locales.rb +155 -0
  41. data/lib/jamf/api/resources/singleton_resources/time_zones.rb +213 -0
  42. data/lib/jamf/client.rb +3 -3
  43. data/lib/jamf/client/management_action.rb +2 -3
  44. data/lib/jamf/composer.rb +2 -2
  45. data/lib/jamf/utility.rb +35 -7
  46. data/lib/jamf/validate.rb +63 -24
  47. data/lib/jamf/version.rb +1 -1
  48. data/lib/jss.rb +2 -2
  49. data/lib/jss/api_connection.rb +114 -406
  50. data/lib/jss/api_object.rb +10 -20
  51. data/lib/jss/api_object/advanced_search.rb +27 -26
  52. data/lib/jss/api_object/app_store_country_codes.rb +298 -0
  53. data/lib/jss/api_object/categorizable.rb +1 -1
  54. data/lib/jss/api_object/computer.rb +13 -0
  55. data/lib/jss/api_object/configuration_profile.rb +61 -5
  56. data/lib/jss/api_object/directory_binding_type.rb +66 -60
  57. data/lib/jss/api_object/directory_binding_type/active_directory.rb +71 -34
  58. data/lib/jss/api_object/directory_binding_type/admitmac.rb +536 -467
  59. data/lib/jss/api_object/directory_binding_type/centrify.rb +21 -7
  60. data/lib/jss/api_object/directory_binding_type/open_directory.rb +4 -4
  61. data/lib/jss/api_object/distribution_point.rb +2 -2
  62. data/lib/jss/api_object/dock_item.rb +102 -96
  63. data/lib/jss/api_object/ebook.rb +1 -2
  64. data/lib/jss/api_object/extendable.rb +1 -1
  65. data/lib/jss/api_object/extension_attribute.rb +4 -3
  66. data/lib/jss/api_object/group.rb +33 -2
  67. data/lib/jss/api_object/mac_application.rb +107 -8
  68. data/lib/jss/api_object/network_segment.rb +45 -13
  69. data/lib/jss/api_object/patch_source.rb +10 -9
  70. data/lib/jss/api_object/policy.rb +267 -28
  71. data/lib/jss/api_object/printer.rb +10 -4
  72. data/lib/jss/api_object/scopable.rb +10 -15
  73. data/lib/jss/api_object/scopable/scope.rb +389 -73
  74. data/lib/jss/api_object/script.rb +242 -352
  75. data/lib/jss/api_object/self_servable.rb +17 -9
  76. data/lib/jss/api_object/uploadable.rb +1 -1
  77. data/lib/jss/api_object/user.rb +43 -2
  78. data/lib/jss/api_object/vpp_account.rb +209 -0
  79. data/lib/jss/api_object/vppable.rb +169 -13
  80. data/lib/jss/client/management_action.rb +1 -2
  81. data/lib/jss/composer.rb +2 -2
  82. data/lib/jss/exceptions.rb +3 -0
  83. data/lib/jss/server.rb +15 -0
  84. data/lib/jss/utility.rb +213 -45
  85. data/lib/jss/validate.rb +53 -10
  86. data/lib/jss/version.rb +1 -1
  87. metadata +50 -66
  88. data/lib/jamf/api/abstract_classes/advanced_search.rb +0 -86
  89. data/lib/jamf/api/abstract_classes/collection_resource.rb +0 -433
  90. data/lib/jamf/api/abstract_classes/generic_reference.rb +0 -145
  91. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +0 -126
  92. data/lib/jamf/api/json_objects/account_prefs.rb +0 -79
  93. data/lib/jamf/api/json_objects/android_details.rb +0 -139
  94. data/lib/jamf/api/json_objects/appletv_details.rb +0 -110
  95. data/lib/jamf/api/json_objects/cellular_network.rb +0 -151
  96. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +0 -67
  97. data/lib/jamf/api/json_objects/criterion.rb +0 -152
  98. data/lib/jamf/api/json_objects/extension_attribute_value.rb +0 -128
  99. data/lib/jamf/api/json_objects/installed_certificate.rb +0 -53
  100. data/lib/jamf/api/json_objects/installed_configuration_profile.rb +0 -67
  101. data/lib/jamf/api/json_objects/installed_ebook.rb +0 -58
  102. data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +0 -59
  103. data/lib/jamf/api/json_objects/ios_details.rb +0 -244
  104. data/lib/jamf/api/json_objects/mobile_device_details.rb +0 -219
  105. data/lib/jamf/api/json_objects/mobile_device_security.rb +0 -101
  106. data/lib/jamf/api/json_objects/purchasing_data.rb +0 -125
  107. data/lib/jamf/api/mixins/locatable.rb +0 -124
  108. data/lib/jamf/api/mixins/referable.rb +0 -92
  109. data/lib/jamf/api/resources/collection_resources/account.rb +0 -163
  110. data/lib/jamf/api/resources/collection_resources/advanced_mobile_device_search.rb +0 -52
  111. data/lib/jamf/api/resources/collection_resources/advanced_user_search.rb +0 -52
  112. data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +0 -45
  113. data/lib/jamf/api/resources/collection_resources/mobile_device.rb +0 -315
  114. data/lib/jamf/api/resources/collection_resources/site.rb +0 -77
  115. data/lib/jamf/api/resources/singleton_resources/authorization.rb +0 -88
  116. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +0 -139
  117. data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +0 -95
data/lib/jss/validate.rb CHANGED
@@ -111,8 +111,8 @@ module JSS
111
111
 
112
112
  # Confirm that the given value is a boolean value, accepting
113
113
  # strings and symbols and returning real booleans as needed
114
- # Accepts: true, false, 'true', 'false', :true, :false, 'yes', 'no', :yes,
115
- # or :no (all Strings and Symbols are case insensitive)
114
+ # Accepts: true, false, 'true', 'false', 'yes', 'no', 't','f', 'y', or 'n'
115
+ # as strings or symbols, case insensitive
116
116
  #
117
117
  # TODO: use this throughout ruby-jss
118
118
  #
@@ -123,11 +123,11 @@ module JSS
123
123
  # @return [Boolean] the valid boolean
124
124
  #
125
125
  def self.boolean(bool, msg = nil)
126
- msg ||= 'Value must be boolean true or false'
127
126
  return bool if JSS::TRUE_FALSE.include? bool
128
- return true if bool.to_s =~ /^(true|yes)$/i
129
- return false if bool.to_s =~ /^(false|no)$/i
127
+ return true if bool.to_s =~ /^(t(rue)?|y(es)?)$/i
128
+ return false if bool.to_s =~ /^(f(alse)?|no?)$/i
130
129
 
130
+ msg ||= 'Value must be boolean true or false, or an equivalent string or symbol'
131
131
  raise JSS::InvalidDataError, msg
132
132
  end
133
133
 
@@ -176,10 +176,10 @@ module JSS
176
176
  # @return [String] the valid uuid string
177
177
  #
178
178
  def self.uuid(val, msg = nil)
179
- msg ||= 'value must be valid uuid'
180
- raise JSS::InvalidDataError, msg unless val.is_a?(String) && val =~ UUID_RE
179
+ return val if val.is_a?(String) && val =~ UUID_RE
181
180
 
182
- val
181
+ msg ||= 'value must be valid uuid'
182
+ raise JSS::InvalidDataError, msg
183
183
  end
184
184
 
185
185
  # validate that the given value is an integer in the JSS::IBeacon::MAJOR_MINOR_RANGE
@@ -191,13 +191,56 @@ module JSS
191
191
  # @return [String] the valid integer
192
192
  #
193
193
  def self.ibeacon_major_minor(val, msg = nil)
194
- msg ||= "value must be an integer in the range #{JSS::IBeacon::MAJOR_MINOR_RANGE}"
195
194
  val = val.to_i if val.is_a?(String) && val.jss_integer?
196
195
  ok = val.is_a? Integer
197
196
  ok = JSS::IBeacon::MAJOR_MINOR_RANGE.include? val if ok
197
+ return val if ok
198
+
199
+ msg ||= "value must be an integer in the range #{JSS::IBeacon::MAJOR_MINOR_RANGE}"
198
200
  raise JSS::InvalidDataError, msg unless ok
201
+ end
199
202
 
200
- val
203
+ # validate a country name or code from JSS::APP_STORE_COUNTRY_CODES
204
+ # returning the validated code, or raising an error
205
+ #
206
+ # @param country[String] The country name or code
207
+ #
208
+ # @param msg[String] A custom error message when the value is invalid
209
+ #
210
+ # @return [String] the valid two-letter country code
211
+ #
212
+ def self.app_store_country_code(country, msg = nil)
213
+ country = country.to_s.upcase
214
+ return country if JSS::APP_STORE_COUNTRY_CODES.value? country
215
+
216
+ JSS::APP_STORE_COUNTRY_CODES.each do |name, code|
217
+ return code if name.upcase == country
218
+ end
219
+
220
+ msg ||= 'Unknown country name or code. See JSS::APP_STORE_COUNTRY_CODES or JSS.country_code_match(str)'
221
+ raise JSS::InvalidDataError, msg
222
+ end
223
+
224
+ # validate an email address - must match the RegEx /^\S+@\S+\.\S+$/
225
+ # i.e.:
226
+ # 1 or more non-whitespace chars, followed by
227
+ # an @ character, followed by
228
+ # 1 or more non-whitespace chars, followed by
229
+ # a dot, followed by
230
+ # 1 or more non-whitespace chars
231
+ #
232
+ # @param email[String] The email address
233
+ #
234
+ # @param msg[String] A custom error message when the value is invalid
235
+ #
236
+ # @return [String] the validly formatted email address
237
+ #
238
+ def self.email_address(email, msg = nil)
239
+ msg ||= "'#{email}' is not formatted as a valid email address"
240
+ email = email.to_s
241
+ return email if email =~ /^\S+@\S+\.\S+$/
242
+
243
+ raise JSS::InvalidDataError, msg
201
244
  end
202
245
 
203
246
  end # module validate
data/lib/jss/version.rb CHANGED
@@ -27,6 +27,6 @@
27
27
  module JSS
28
28
 
29
29
  ### The version of ruby-jss
30
- VERSION = '1.3.3'.freeze
30
+ VERSION = '1.6.0b1'.freeze
31
31
 
32
32
  end # module
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-jss
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.6.0b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Lasell
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-08-07 00:00:00.000000000 Z
12
+ date: 2021-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: plist
15
+ name: CFPropertyList
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '3.1'
20
+ version: '3.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '3.1'
27
+ version: '3.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: ruby-mysql
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -46,39 +46,45 @@ dependencies:
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.9.12
48
48
  - !ruby/object:Gem::Dependency
49
- name: rest-client
49
+ name: faraday
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.0
55
- - - "<"
54
+ version: 1.0.0
55
+ - - "<="
56
56
  - !ruby/object:Gem::Version
57
- version: '2.1'
57
+ version: 1.0.1
58
58
  type: :runtime
59
59
  prerelease: false
60
60
  version_requirements: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 2.0.0
65
- - - "<"
64
+ version: 1.0.0
65
+ - - "<="
66
66
  - !ruby/object:Gem::Version
67
- version: '2.1'
67
+ version: 1.0.1
68
68
  - !ruby/object:Gem::Dependency
69
- name: net-ldap
69
+ name: faraday_middleware
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '0.16'
74
+ version: 1.0.0
75
+ - - "<="
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.1
75
78
  type: :runtime
76
79
  prerelease: false
77
80
  version_requirements: !ruby/object:Gem::Requirement
78
81
  requirements:
79
- - - "~>"
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.0.0
85
+ - - "<="
80
86
  - !ruby/object:Gem::Version
81
- version: '0.16'
87
+ version: 1.0.1
82
88
  - !ruby/object:Gem::Dependency
83
89
  name: immutable-struct
84
90
  requirement: !ruby/object:Gem::Requirement
@@ -120,11 +126,13 @@ dependencies:
120
126
  - !ruby/object:Gem::Version
121
127
  version: '1.1'
122
128
  description: |2
123
- The ruby-jss gem provides the JSS module, a framework for interacting with the REST API
124
- of the Jamf Software Server (JSS), the core of Jamf Pro, an enterprise/education
125
- tool for managing Apple devices, from Jamf Software LLC.
126
- JSS API objects are implemented as Ruby classes, and interact with each oher to
127
- allow simpler automation of Jamf-related tasks. For details see the README file."
129
+ The ruby-jss gem provides native ruby access to the REST APIs of Jamf Pro,
130
+ an enterprise/education tool for managing Apple devices, from jamf.com.
131
+ The JSS module provides access to the 'Classic' API, while the Jamf module
132
+ provides access to the more modern 'Jamf Pro' API. Jamf Pro objects are
133
+ implemented as classes and, within each module, can interact with each other.
134
+ The underlying data transfer using JSON or XML is handled automatically
135
+ under the hood to allow simpler, intuitive automation of Jamf-related Tasks.
128
136
  email: ruby-jss@pixar.com
129
137
  executables:
130
138
  - cgrouper
@@ -147,82 +155,56 @@ files:
147
155
  - bin/netseg-update
148
156
  - data/ruby-jss.conf.example
149
157
  - lib/jamf.rb
150
- - lib/jamf/api/abstract_classes/advanced_search.rb
151
- - lib/jamf/api/abstract_classes/collection_resource.rb
152
- - lib/jamf/api/abstract_classes/generic_reference.rb
153
- - lib/jamf/api/abstract_classes/json_object.rb
154
- - lib/jamf/api/abstract_classes/prestage.rb
155
- - lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb
156
- - lib/jamf/api/abstract_classes/resource.rb
157
- - lib/jamf/api/abstract_classes/singleton_resource.rb
158
158
  - lib/jamf/api/attribute_classes/ip_address.rb
159
159
  - lib/jamf/api/attribute_classes/timestamp.rb
160
+ - lib/jamf/api/base_classes/collection_resource.rb
161
+ - lib/jamf/api/base_classes/json_object.rb
162
+ - lib/jamf/api/base_classes/prestage.rb
163
+ - lib/jamf/api/base_classes/resource.rb
164
+ - lib/jamf/api/base_classes/singleton_resource.rb
160
165
  - lib/jamf/api/connection.rb
161
166
  - lib/jamf/api/connection/api_error.rb
162
167
  - lib/jamf/api/connection/api_error_styleguide.rb
163
168
  - lib/jamf/api/connection/token.rb
164
- - lib/jamf/api/json_objects/account_prefs.rb
165
- - lib/jamf/api/json_objects/android_details.rb
166
- - lib/jamf/api/json_objects/appletv_details.rb
167
- - lib/jamf/api/json_objects/attachment.rb
168
- - lib/jamf/api/json_objects/cellular_network.rb
169
169
  - lib/jamf/api/json_objects/change_log_entry.rb
170
- - lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb
171
170
  - lib/jamf/api/json_objects/country.rb
172
- - lib/jamf/api/json_objects/criterion.rb
173
171
  - lib/jamf/api/json_objects/device_enrollment_device.rb
172
+ - lib/jamf/api/json_objects/device_enrollment_device_sync_state.rb
174
173
  - lib/jamf/api/json_objects/device_enrollment_sync_status.rb
175
- - lib/jamf/api/json_objects/extension_attribute_value.rb
176
- - lib/jamf/api/json_objects/installed_application.rb
177
- - lib/jamf/api/json_objects/installed_certificate.rb
178
- - lib/jamf/api/json_objects/installed_configuration_profile.rb
179
- - lib/jamf/api/json_objects/installed_ebook.rb
180
- - lib/jamf/api/json_objects/installed_provisioning_profile.rb
181
174
  - lib/jamf/api/json_objects/inventory_preload_extension_attribute.rb
182
- - lib/jamf/api/json_objects/ios_details.rb
183
- - lib/jamf/api/json_objects/location.rb
175
+ - lib/jamf/api/json_objects/locale.rb
184
176
  - lib/jamf/api/json_objects/md_prestage_name.rb
185
177
  - lib/jamf/api/json_objects/md_prestage_names.rb
186
178
  - lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb
187
- - lib/jamf/api/json_objects/mobile_device_details.rb
188
- - lib/jamf/api/json_objects/mobile_device_security.rb
189
179
  - lib/jamf/api/json_objects/prestage_assignment.rb
190
180
  - lib/jamf/api/json_objects/prestage_location.rb
191
181
  - lib/jamf/api/json_objects/prestage_purchasing_data.rb
192
182
  - lib/jamf/api/json_objects/prestage_scope.rb
193
183
  - lib/jamf/api/json_objects/prestage_sync_status.rb
194
- - lib/jamf/api/json_objects/purchasing_data.rb
195
- - lib/jamf/api/mixins/abstract.rb
184
+ - lib/jamf/api/json_objects/time_zone.rb
185
+ - lib/jamf/api/mixins/base_class.rb
196
186
  - lib/jamf/api/mixins/bulk_deletable.rb
197
187
  - lib/jamf/api/mixins/change_log.rb
198
188
  - lib/jamf/api/mixins/extendable.rb
189
+ - lib/jamf/api/mixins/filterable.rb
199
190
  - lib/jamf/api/mixins/immutable.rb
200
- - lib/jamf/api/mixins/locatable.rb
201
191
  - lib/jamf/api/mixins/lockable.rb
202
- - lib/jamf/api/mixins/referable.rb
192
+ - lib/jamf/api/mixins/pageable.rb
203
193
  - lib/jamf/api/mixins/searchable.rb
194
+ - lib/jamf/api/mixins/sortable.rb
204
195
  - lib/jamf/api/mixins/uncreatable.rb
205
196
  - lib/jamf/api/mixins/undeletable.rb
206
- - lib/jamf/api/resources/collection_resources/account.rb
207
- - lib/jamf/api/resources/collection_resources/advanced_mobile_device_search.rb
208
- - lib/jamf/api/resources/collection_resources/advanced_user_search.rb
209
197
  - lib/jamf/api/resources/collection_resources/building.rb
210
198
  - lib/jamf/api/resources/collection_resources/category.rb
211
- - lib/jamf/api/resources/collection_resources/computer.rb
212
199
  - lib/jamf/api/resources/collection_resources/computer_prestage.rb
213
200
  - lib/jamf/api/resources/collection_resources/department.rb
214
201
  - lib/jamf/api/resources/collection_resources/device_enrollment.rb
215
- - lib/jamf/api/resources/collection_resources/extension_attribute.rb
216
202
  - lib/jamf/api/resources/collection_resources/inventory_preload_record.rb
217
- - lib/jamf/api/resources/collection_resources/mobile_device.rb
218
203
  - lib/jamf/api/resources/collection_resources/mobile_device_prestage.rb
219
204
  - lib/jamf/api/resources/collection_resources/script.rb
220
- - lib/jamf/api/resources/collection_resources/site.rb
221
- - lib/jamf/api/resources/collection_resources/time_zone.rb
222
205
  - lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb
223
- - lib/jamf/api/resources/singleton_resources/authorization.rb
224
- - lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb
225
- - lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb
206
+ - lib/jamf/api/resources/singleton_resources/locales.rb
207
+ - lib/jamf/api/resources/singleton_resources/time_zones.rb
226
208
  - lib/jamf/client.rb
227
209
  - lib/jamf/client/jamf_binary.rb
228
210
  - lib/jamf/client/jamf_helper.rb
@@ -264,6 +246,7 @@ files:
264
246
  - lib/jss/api_object/advanced_search/advanced_computer_search.rb
265
247
  - lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb
266
248
  - lib/jss/api_object/advanced_search/advanced_user_search.rb
249
+ - lib/jss/api_object/app_store_country_codes.rb
267
250
  - lib/jss/api_object/building.rb
268
251
  - lib/jss/api_object/categorizable.rb
269
252
  - lib/jss/api_object/category.rb
@@ -346,6 +329,7 @@ files:
346
329
  - lib/jss/api_object/updatable.rb
347
330
  - lib/jss/api_object/uploadable.rb
348
331
  - lib/jss/api_object/user.rb
332
+ - lib/jss/api_object/vpp_account.rb
349
333
  - lib/jss/api_object/vppable.rb
350
334
  - lib/jss/api_object/webhook.rb
351
335
  - lib/jss/client.rb
@@ -405,15 +389,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
405
389
  requirements:
406
390
  - - ">="
407
391
  - !ruby/object:Gem::Version
408
- version: 2.0.0
392
+ version: 2.3.0
409
393
  required_rubygems_version: !ruby/object:Gem::Requirement
410
394
  requirements:
411
- - - ">="
395
+ - - ">"
412
396
  - !ruby/object:Gem::Version
413
- version: '0'
397
+ version: 1.3.1
414
398
  requirements: []
415
399
  rubygems_version: 3.0.3
416
400
  signing_key:
417
401
  specification_version: 4
418
- summary: A Ruby interface to the Jamf Pro REST API
402
+ summary: A Ruby interface to the Jamf Pro REST APIs
419
403
  test_files: []
@@ -1,86 +0,0 @@
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 AdvancedSearch < Jamf::CollectionResource
34
-
35
- extend Jamf::Abstract
36
-
37
- # Constants
38
- #####################################
39
-
40
- # Object Model / Attributes
41
- # See APIObject class documentation for details
42
- # of how the OBJECT_MODEL hash works.
43
- #####################################
44
- OBJECT_MODEL = {
45
-
46
- # @!attribute [r] id
47
- # @return [Integer]
48
- id: {
49
- class: :integer,
50
- identifier: :primary,
51
- readonly: true
52
- },
53
-
54
- # @!attribute name
55
- # @return [String]
56
- name: {
57
- class: :string,
58
- identifier: true
59
- },
60
-
61
- # @!attribute criteria
62
- # @return [Array<Jamf::Criterion>]
63
- criteria: {
64
- class: Jamf::Criterion,
65
- multi: true,
66
- required: true
67
- },
68
-
69
- # @!attribute displayFields
70
- # @return [Array<String>]
71
- displayFields: {
72
- class: :string,
73
- multi: true
74
- },
75
-
76
- # @!attribute site
77
- # @return [Jamf::Site::Reference]
78
- site: {
79
- class: Jamf::Site::Reference
80
- }
81
-
82
- }.freeze
83
-
84
- end # class
85
-
86
- end # module
@@ -1,433 +0,0 @@
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
- # A Collection Resource in Jamf Pro
30
- #
31
- # See {Jamf::Resource} for general info about API resources.
32
- #
33
- # Collection resources have more than one resource within them, and those
34
- # can (usually) be created and deleted as well as fetched and updated.
35
- # The entire collection (or a part of it) can also be fetched as an Array.
36
- # When the whole collection is fetched, the result is cached for future use.
37
- #
38
- # # Subclassing
39
- #
40
- # ## Creatability, & Deletability
41
- #
42
- # Sometimes the API doesn't support creation of new members of the collection.
43
- # If that's the case, just extend the subclass with Jamf::UnCreatable
44
- # and the '.create' class method will raise an error.
45
- #
46
- # Similarly for deletion of members: if the API doesn't have a way to delete
47
- # them, extend the subclass with Jamf::UnDeletable
48
- #
49
- # See also Jamf::JSONObject, which talks about extending subclasses
50
- # with Jamf::Immutable
51
- #
52
- # ## Bulk Deletion
53
- #
54
- # Some collection resources have a resource for bulk deletion, passing in
55
- # a JSON array of ids to delete.
56
- #
57
- # If so, just define a BULK_DELETE_RSRC, and the .delete class method
58
- # will use it, rather than making multiple calls to delete individual
59
- # items. See Jamf::Category::BULK_DELETE_RSRC for an example
60
- #
61
- # @abstract
62
- #
63
- class CollectionResource < Jamf::Resource
64
-
65
- extend Jamf::Abstract
66
- include Comparable
67
-
68
- # Public Class Methods
69
- #####################################
70
-
71
- # @return [Array<Symbol>] the attribute names that are marked as identifiers
72
- #
73
- def self.identifiers
74
- self::OBJECT_MODEL.select { |_attr, deets| deets[:identifier] }.keys
75
- end
76
-
77
- # The Collection members Array for this class, retrieved from
78
- # the RSRC_PATH as Parsed JSON, but not instantiated into instances
79
- # unless instantiate: is truthy.
80
- #
81
- # E.g. for {Jamf::Settings::Building}, this would be the Array of Hashes
82
- # returned by GETing the resource .../settings/obj/building
83
- #
84
- # This Array is cached in the {Jamf::Connection} instance used to
85
- # retrieve it, and future calls to .all will return the cached Array
86
- # unless refresh is truthy.
87
- #
88
- # TODO: Investigate https://www.rubydoc.info/github/mloughran/api_cache
89
- #
90
- # @param refresh[Boolean] re-read the data from the API?
91
- #
92
- # @param cnx[Jamf::Connection] an API connection to use for the query.
93
- # Defaults to the corrently active connection. See {Jamf::Connection}
94
- #
95
- # @param instantiate[Boolean] The Array contains instances of this class
96
- # rather than the JSON Hashes from the API.
97
- #
98
- # @return [Array<Object>] An Array of all objects of this class in the JSS.
99
- #
100
- def self.all(refresh = false, cnx: Jamf.cnx, instantiate: false)
101
- validate_not_abstract
102
- cnx.collection_cache[self] = nil if refresh
103
- if cnx.collection_cache[self]
104
- return cnx.collection_cache[self] unless instantiate
105
-
106
- return cnx.collection_cache[self].map { |m| new m }
107
- end
108
-
109
- # TODO: make sure all collection resources use this format
110
- # for paging. Also -ask Jamf about a url that returns
111
- # ALL objects in one query, regardless of number.
112
- page = 0
113
- raw = cnx.get "#{rsrc_path}?page=#{page}&size=1000000&sort=id%3Aasc"
114
- results = raw[:results]
115
-
116
- until results.size >= raw[:totalCount]
117
- page += 1
118
- raw = cnx.get "#{rsrc_path}?page=#{page}&size=1000000&sort=id%3Aasc"
119
- results += raw[:results]
120
- end
121
-
122
-
123
- cnx.collection_cache[self] = results
124
-
125
- return cnx.collection_cache[self] unless instantiate
126
-
127
- cnx.collection_cache[self].map { |m| new m }
128
- end
129
-
130
- # An array of the ids for all collection members. According to the
131
- # specs ALL collection resources must have an ID, which is used in the
132
- # resource path.
133
- #
134
- # @param refresh (see .all)
135
- #
136
- # @param cnx (see .all)
137
- #
138
- # @return [Array<Integer>]
139
- #
140
- def self.all_ids(refresh = false, cnx: Jamf.cnx)
141
- all(refresh, cnx: cnx).map { |m| m[:id] }
142
- end
143
-
144
- # rubocop:disable Naming/UncommunicativeMethodParamName
145
-
146
- # A Hash of all members of this collection where the keys are some
147
- # identifier and values are any other attribute.
148
- #
149
- # @param ident [Symbol] An identifier of this Class, used as the key
150
- # for the mapping Hash. Aliases are acceptable, e.g. :sn for :serialNumber
151
- #
152
- # @param to [Symbol] The attribute to which the ident will be mapped.
153
- # Aliases are acceptable, e.g. :name for :displayName
154
- #
155
- # @param refresh (see .all)
156
- #
157
- # @param cnx (see .all)
158
- #
159
- # @return [Hash {Symbol: Object}] A Hash of identifier mapped to attribute
160
- #
161
- def self.map_all(ident, to:, cnx: Jamf.cnx, refresh: false)
162
- real_ident = attr_key_for_alias ident
163
- raise Jamf::InvalidDataError, "No identifier #{ident} for class #{self}" unless
164
- identifiers.include? real_ident
165
-
166
- real_to = attr_key_for_alias to
167
- raise Jamf::NoSuchItemError, "No attribute #{to} for class #{self}" unless self::OBJECT_MODEL.key? real_to
168
-
169
- ident = real_ident
170
- to = real_to
171
- list = all refresh, cnx: cnx
172
- to_class = self::OBJECT_MODEL[to][:class]
173
- mapped = list.map do |i|
174
- [
175
- i[ident],
176
- to_class.is_a?(Symbol) ? i[to] : to_class.new(i[to])
177
- ]
178
- end # do i
179
- mapped.to_h
180
- end
181
- # rubocop:enable Naming/UncommunicativeMethodParamName
182
-
183
- # Given any identfier value for this collection, return the id of the
184
- # object that has such an identifier.
185
- #
186
- # Return nil if there's no match for the given value.
187
- #
188
- # If you know the value is a certain identifier, e.g. a serialNumber,
189
- # then you can specify the identifier for a faster search:
190
- #
191
- # valid_id serialNumber: 'AB12DE34' # => Int or nil
192
- #
193
- # If you don't know wich identifier you have, just pass the value and
194
- # all identifiers are searched
195
- #
196
- # valid_id 'AB12DE34' # => Int or nil
197
- # valid_id 'SomeComputerName' # => Int or nil
198
- #
199
- # When the value is a string, the seach is case-insensitive
200
- #
201
- # TODO: When 'Searchability' is more dialed in via the searchable
202
- # mixin, which implements enpoints like 'POST /v1/search-mobile-devices'
203
- # then use that before using the 'all' list.
204
- #
205
- # @param value [Object] A value to search for as an identifier.
206
- #
207
- # @param refresh[Boolean] Reload the list data from the API
208
- #
209
- # @param ident: [Symbol] Restrict the search to this identifier.
210
- # E.g. if :serialNumber, then the value must be
211
- # a known serial number, it is not checked against other identifiers
212
- #
213
- # @param cnx: (see .all)
214
- #
215
- # @return [Object, nil] the primary identifier of the matching object,
216
- # or nil if it doesn't exist
217
- #
218
- def self.valid_id(value = nil, refresh: true, cnx: Jamf.cnx, **ident_hash)
219
- unless ident_hash.empty?
220
- ident, value = ident_hash.first
221
- return id_from_other_ident ident, value, refresh, cnx: cnx
222
- end
223
-
224
- # check the id itself first
225
- return value if all_ids(refresh, cnx: cnx).include? value
226
-
227
- idents = identifiers - [:id]
228
- val_is_str = value.is_a? String
229
-
230
- idents.each do |ident|
231
- match = all(refresh, cnx: cnx).select do |m|
232
- val_is_str ? m[ident].to_s.casecmp?(value) : m[ident] == value
233
- end.first
234
- return match[:id] if match
235
- end # identifiers.each do |ident|
236
-
237
- nil
238
- end
239
-
240
- # Bu default, subclasses are creatable, i.e. new instances can be created
241
- # with .create, and added to the JSS with .save
242
- # If a subclass is NOT creatble for any reason, just add
243
- # extend Jamf::UnCreatable
244
- # and this method will return false
245
- #
246
- # @return [Boolean]
247
- def self.creatable?
248
- true
249
- end
250
-
251
- # Make a new thing to be added to the API
252
- def self.create(**params)
253
- validate_not_abstract
254
- raise Jamf::UnsupportedError, "#{self}'s are not currently creatable via the API" unless creatable?
255
-
256
- cnx = params.delete :cnx
257
- cnx ||= Jamf.cnx
258
-
259
- params.delete :id # no such animal when .creating
260
-
261
- params.keys.each do |param|
262
- raise ArgumentError, "Unknown parameter: #{param}" unless self::OBJECT_MODEL.key? param
263
-
264
- params[param] = validate_attr param, params[param], cnx: cnx
265
- end
266
-
267
- params[:creating_from_create] = true
268
- new params, cnx: cnx
269
- end
270
-
271
- # Retrieve a member of a CollectionResource from the API
272
- #
273
- # To create new members to be added to the JSS, use
274
- # {Jamf::CollectionResource.create}
275
- #
276
- # If you know the specific identifier attribute you're looking up, e.g.
277
- # :id or :name or :udid, (or an aliase thereof) then you can specify it like
278
- # `.fetch name: 'somename'`, or `.fetch udid: 'someudid'`
279
- #
280
- # If you don't know if (or don't want to type it) you can just use
281
- # `.fetch 'somename'`, or `.fetch 'someudid'` and all identifiers will be
282
- # searched for a match.
283
- #
284
- # @param ident_value[Object] A value for any identifier for this subclass.
285
- # All identifier attributes will be searched for a match.
286
- #
287
- # @param cnx[Jamf::Connection] the connection to use to fetch the object
288
- #
289
- # @param ident_hash[Hash] an identifier attribute key and a search value
290
- #
291
- # @return [CollectionResource] The ruby-instance of a Jamf object
292
- #
293
- def self.fetch(ident_value = nil, cnx: Jamf.cnx, **ident_hash)
294
- validate_not_abstract
295
-
296
- id =
297
- if ident_value == :random
298
- all_ids.sample
299
- elsif ident_value
300
- valid_id ident_value, cnx: cnx
301
- elsif ident_hash.empty?
302
- nil
303
- else
304
- ident, lookup_value = ident_hash.first
305
- valid_id ident => lookup_value, cnx: cnx
306
- end
307
-
308
- raise Jamf::NoSuchItemError, "No matching #{self}" unless id
309
-
310
- data = cnx.get "#{rsrc_path}/#{id}"
311
- new data, cnx: cnx
312
- end # fetch
313
-
314
- # By default, CollectionResource subclass instances are deletable.
315
- # If not, just extend the subclass with Jamf::UnDeletable, and this
316
- # will return false, and .delete & #delete will raise errors
317
- def self.deletable?
318
- true
319
- end
320
-
321
- # Delete one or more objects by identifier
322
- # Any valid identifier for the class can be used (id, name, udid, etc)
323
- # Identifiers can be provided as an array or as separate parameters
324
- #
325
- # e.g. .delete [1,3, 34, 4]
326
- # or .delete 'myComputer', 'that-computer', 'OtherComputer'
327
- #
328
- # @param idents[Array<integer>, Integer]
329
- #
330
- # @param cnx[Jamf::Connection]
331
- #
332
- # @return [Array] the identifiers that were not found, so couldn't be deleted
333
- #
334
- def self.delete(*idents, cnx: Jamf.cnx)
335
- raise Jamf::UnsupportedError, "Deleting #{self} objects is not currently supported" unless deletable?
336
-
337
- idents.flatten!
338
- no_valid_ids = []
339
-
340
- idents.map do |ident|
341
- id = valid_id ident
342
- no_valid_ids << ident unless id
343
- id
344
- end
345
- idents.compact!
346
-
347
- # TODO: some rsrcs have a 'bulk delete' version...
348
- idents.each { |id| cnx.delete "#{rsrc_path}/#{id}" }
349
-
350
- no_valid_ids
351
- end
352
-
353
- # Private Class Methods
354
- #####################################
355
-
356
- # TODO: better pluralizing?
357
- #
358
- def self.create_list_methods(attr_name, attr_def)
359
- list_method_name = "all_#{attr_name}s"
360
-
361
- define_singleton_method(list_method_name) do |refresh = false, cnx: Jamf.cnx|
362
- all_list = all(refresh, cnx: cnx)
363
- if attr_def[:class].is_a? Symbol
364
- all_list.map { |i| i[attr_name] }.uniq
365
- else
366
- all_list.map { |i| attr_def[:class].new i[attr_name] }
367
- end
368
- end # define_singleton_method
369
-
370
- return unless attr_def[:aliases]
371
-
372
- # aliases - TODO: is there a more elegant way?
373
- attr_def[:aliases].each do |a|
374
- define_singleton_method("all_#{a}s") do |refresh = false, cnx: Jamf.cnx|
375
- send list_method_name, refresh, cnx: cnx
376
- end # define_singleton_method
377
- end # each alias
378
- end # create_list_methods
379
- private_class_method :create_list_methods
380
-
381
- # Given an indentier attr. key, and a value,
382
- # return the id where that ident has that value, or nil
383
- #
384
- def self.id_from_other_ident(ident, value, refresh = true, cnx: Jamf.cnx)
385
- raise ArgumentError, "Unknown identifier '#{ident}' for #{self}" unless identifiers.include? ident
386
-
387
- # check the id itself first
388
- return value if ident == :id && all_ids(refresh, cnx: cnx).include?(value)
389
-
390
- # all ident values => ids
391
- ident_map = map_all(ident, to: :id, cnx: cnx, refresh: refresh)
392
-
393
- # case-insensitivity for string values
394
- value = ident_map.keys.j_ci_fetch(value) if value.is_a? String
395
-
396
- ident_map[value]
397
- end
398
- private_class_method :id_from_other_ident
399
-
400
- # Instance Methods
401
- #####################################
402
-
403
- def exist?
404
- !@id.nil?
405
- end
406
-
407
- def rsrc_path
408
- return unless exist?
409
- "#{self.class.rsrc_path}/#{@id}"
410
- end
411
-
412
- def delete
413
- raise Jamf::UnsupportedError, "Deleting #{self} objects is not currently supported" unless self.class.deletable?
414
- @cnx.delete rsrc_path
415
- end
416
-
417
- # Two collection resource objects are the same if their id's are the same
418
- def <=>(other)
419
- id <=> other.id
420
- end
421
-
422
- # Private Instance Methods
423
- ############################################
424
- private
425
-
426
- def create_in_jamf
427
- result = @cnx.post self.class.rsrc_path, to_jamf
428
- @id = result[:id]
429
- end
430
-
431
- end # class CollectionResource
432
-
433
- end # module JAMF