ruby-jss 1.2.9 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +196 -1
  3. data/lib/jamf.rb +10 -3
  4. data/lib/jamf/api/abstract_classes/collection_resource.rb +329 -150
  5. data/lib/jamf/api/abstract_classes/generic_reference.rb +9 -1
  6. data/lib/jamf/api/abstract_classes/json_object.rb +107 -83
  7. data/lib/jamf/api/abstract_classes/prestage.rb +55 -30
  8. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +21 -0
  9. data/lib/jamf/api/abstract_classes/resource.rb +4 -4
  10. data/lib/jamf/api/abstract_classes/singleton_resource.rb +1 -1
  11. data/lib/jamf/api/connection.rb +20 -12
  12. data/lib/jamf/api/connection/api_error.rb +8 -8
  13. data/lib/jamf/api/connection/token.rb +36 -15
  14. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +14 -1
  15. data/lib/jamf/api/json_objects/device_enrollment_device.rb +14 -7
  16. data/lib/jamf/api/json_objects/device_enrollment_device_sync_state.rb +81 -0
  17. data/lib/jamf/api/json_objects/locale.rb +59 -0
  18. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +50 -1
  19. data/lib/jamf/api/json_objects/prestage_location.rb +3 -3
  20. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +7 -7
  21. data/lib/jamf/api/json_objects/prestage_scope.rb +1 -1
  22. data/lib/jamf/api/{resources/collection_resources → json_objects}/time_zone.rb +9 -23
  23. data/lib/jamf/api/mixins/bulk_deletable.rb +27 -6
  24. data/lib/jamf/api/mixins/change_log.rb +201 -51
  25. data/lib/jamf/api/mixins/filterable.rb +51 -0
  26. data/lib/jamf/api/mixins/pageable.rb +208 -0
  27. data/lib/jamf/api/mixins/sortable.rb +59 -0
  28. data/lib/jamf/api/resources/collection_resources/building.rb +19 -8
  29. data/lib/jamf/api/resources/collection_resources/category.rb +5 -3
  30. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +11 -4
  31. data/lib/jamf/api/resources/collection_resources/department.rb +1 -1
  32. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +13 -13
  33. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +11 -3
  34. data/lib/jamf/api/resources/collection_resources/mobile_device_prestage.rb +24 -22
  35. data/lib/jamf/api/resources/collection_resources/script.rb +61 -25
  36. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +15 -5
  37. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +14 -14
  38. data/lib/jamf/api/resources/singleton_resources/locales.rb +155 -0
  39. data/lib/jamf/api/resources/singleton_resources/time_zones.rb +213 -0
  40. data/lib/jamf/configuration.rb +7 -9
  41. data/lib/jamf/ruby_extensions.rb +1 -0
  42. data/lib/jamf/ruby_extensions/array.rb +1 -1
  43. data/lib/jamf/ruby_extensions/array/utils.rb +3 -3
  44. data/lib/jamf/ruby_extensions/dig.rb +52 -0
  45. data/lib/jamf/validate.rb +63 -24
  46. data/lib/jamf/version.rb +1 -1
  47. data/lib/jss.rb +4 -1
  48. data/lib/jss/api_connection.rb +110 -397
  49. data/lib/jss/api_object.rb +16 -13
  50. data/lib/jss/api_object/advanced_search.rb +27 -26
  51. data/lib/jss/api_object/app_store_country_codes.rb +298 -0
  52. data/lib/jss/api_object/categorizable.rb +1 -1
  53. data/lib/jss/api_object/computer.rb +5 -1
  54. data/lib/jss/api_object/configuration_profile.rb +34 -3
  55. data/lib/jss/api_object/directory_binding.rb +273 -0
  56. data/lib/jss/api_object/directory_binding_type.rb +96 -0
  57. data/lib/jss/api_object/directory_binding_type/active_directory.rb +539 -0
  58. data/lib/jss/api_object/directory_binding_type/admitmac.rb +594 -0
  59. data/lib/jss/api_object/directory_binding_type/centrify.rb +226 -0
  60. data/lib/jss/api_object/directory_binding_type/open_directory.rb +178 -0
  61. data/lib/jss/api_object/directory_binding_type/powerbroker_identity_services.rb +73 -0
  62. data/lib/jss/api_object/disk_encryption_configurations.rb +114 -0
  63. data/lib/jss/api_object/distribution_point.rb +97 -37
  64. data/lib/jss/api_object/dock_item.rb +143 -0
  65. data/lib/jss/api_object/ebook.rb +1 -2
  66. data/lib/jss/api_object/extendable.rb +68 -32
  67. data/lib/jss/api_object/extension_attribute.rb +4 -3
  68. data/lib/jss/api_object/group.rb +33 -2
  69. data/lib/jss/api_object/mac_application.rb +107 -8
  70. data/lib/jss/api_object/mobile_device.rb +3 -0
  71. data/lib/jss/api_object/mobile_device_application.rb +12 -0
  72. data/lib/jss/api_object/network_segment.rb +195 -70
  73. data/lib/jss/api_object/package.rb +105 -40
  74. data/lib/jss/api_object/patch_source.rb +10 -9
  75. data/lib/jss/api_object/policy.rb +491 -7
  76. data/lib/jss/api_object/printer.rb +446 -0
  77. data/lib/jss/api_object/scopable.rb +10 -15
  78. data/lib/jss/api_object/scopable/scope.rb +386 -71
  79. data/lib/jss/api_object/self_servable.rb +17 -9
  80. data/lib/jss/api_object/uploadable.rb +1 -1
  81. data/lib/jss/api_object/user.rb +42 -1
  82. data/lib/jss/api_object/vpp_account.rb +209 -0
  83. data/lib/jss/api_object/vppable.rb +169 -13
  84. data/lib/jss/composer.rb +1 -1
  85. data/lib/jss/exceptions.rb +3 -0
  86. data/lib/jss/server.rb +15 -0
  87. data/lib/jss/utility.rb +8 -22
  88. data/lib/jss/validate.rb +53 -10
  89. data/lib/jss/version.rb +1 -1
  90. metadata +50 -22
@@ -0,0 +1,446 @@
1
+ module JSS
2
+ ### Module Constants
3
+ #####################################
4
+
5
+ ### Module Variables
6
+ #####################################
7
+
8
+ ### Module Methods
9
+ #####################################
10
+
11
+ ### Classes
12
+ #####################################
13
+
14
+ ### Printer object inside JSS
15
+ ###
16
+ ### @see JSS::APIObject
17
+ class Printer < JSS::APIObject
18
+ ## Mix-Ins
19
+ #####################################
20
+ include JSS::Creatable
21
+ include JSS::Updatable
22
+ include JSS::Categorizable
23
+
24
+ ## Class Constants
25
+ #####################################
26
+
27
+ ### The base for REST resources of this class
28
+ RSRC_BASE = 'printers'.freeze
29
+
30
+ ### the hash key used for the JSON list output of all objects in the JSS
31
+ RSRC_LIST_KEY = :printers
32
+
33
+ ### The hash key used for the JSON object output
34
+ ### It's also used in various error messages
35
+ RSRC_OBJECT_KEY = :printer
36
+
37
+ # Where is the Category in the API JSON?
38
+ CATEGORY_SUBSET = :top
39
+
40
+ # How is the category stored in the API data?
41
+ CATEGORY_DATA_TYPE = String
42
+
43
+ ## Attributes
44
+ #####################################
45
+
46
+ ### @return [String] The URI path for the specific printer.
47
+ attr_reader :uri
48
+
49
+ ### @return [String] The CUPs name to be used
50
+ attr_reader :CUPS_name
51
+
52
+ ### @return [String] The physical location of the printer.
53
+ attr_reader :location
54
+
55
+ ### @return [String] The specific model of printer.
56
+ attr_reader :model
57
+
58
+ ### @return [Boolean] Is this printer to be shared?
59
+ attr_reader :shared
60
+
61
+ ### @return [String] Information for this specific printer.
62
+ attr_reader :info
63
+
64
+ ### @return [String] Notes for this specific printer.
65
+ attr_reader :notes
66
+
67
+ ### @return [Boolean] Make this printer as the default printer upon installation.
68
+ attr_reader :make_default
69
+
70
+ ### @return [Boolean] Use a generic PPD.
71
+ attr_reader :use_generic
72
+
73
+ ### @return [String] The PPD file name.
74
+ attr_reader :ppd
75
+
76
+ ### @return [String] The contents of the PPD file.
77
+ attr_reader :ppd_contents
78
+
79
+ ### @return [String] The path the PPD file will be installed.
80
+ attr_reader :ppd_path
81
+
82
+ ### @return [String] The OS version requirements seperated by commas
83
+ attr_reader :os_requirements
84
+
85
+ ## Constructor
86
+ #####################################
87
+
88
+ ###
89
+ def initialize(args = {})
90
+ super args
91
+
92
+ if self.in_jss?
93
+
94
+ @uri = @init_data[:uri]
95
+ @CUPS_name = @init_data[:CUPS_name]
96
+ @location = @init_data[:location]
97
+ @model = @init_data[:model]
98
+ @shared = @init_data[:shared]
99
+ @info = @init_data[:info]
100
+ @notes = @init_data[:notes]
101
+ @make_default = @init_data[:make_default]
102
+ @use_generic = @init_data[:use_generic]
103
+ @ppd = @init_data[:ppd]
104
+ @ppd_contents = @init_data[:ppd_contents]
105
+ @ppd_path = @init_data[:ppd_path]
106
+ @os_requirements = @init_data[:os_requirements]
107
+ else
108
+
109
+ raise JSS::MissingDataError, "CUPS_name must be provided." unless !@init_data[:CUPS_name].nil?
110
+ raise JSS::MissingDataError, "uri must be provided." unless !@init_data[:uri].nil?
111
+
112
+ raise JSS::InvalidDataError, "uri must be a String." unless @init_data[:uri].is_a?(String) || @init_data[:uri].nil?
113
+ raise JSS::InvalidDataError, "CUPS_name must be a String." unless @init_data[:CUPS_name].is_a?(String)
114
+ raise JSS::InvalidDataError, "location must be a String." unless @init_data[:location].is_a?(String) || @init_data[:location].nil?
115
+ raise JSS::InvalidDataError, "model must be a String." unless @init_data[:model].is_a?(String) || @init_data[:model].nil?
116
+ raise JSS::InvalidDataError, "info must be a String." unless @init_data[:info].is_a?(String) || @init_data[:info].nil?
117
+ raise JSS::InvalidDataError, "notes must be a String." unless @init_data[:notes].is_a?(String) || @init_data[:notes].nil?
118
+ raise JSS::InvalidDataError, "ppd must be a String." unless @init_data[:ppd].is_a?(String) || @init_data[:ppd].nil?
119
+ raise JSS::InvalidDataError, "ppd_contents must be a String." unless @init_data[:ppd_contents].is_a?(String) || @init_data[:ppd_contents].nil?
120
+ raise JSS::InvalidDataError, "ppd_path must be a String." unless @init_data[:ppd_path].is_a?(String) || @init_data[:ppd_path].nil?
121
+ raise JSS::InvalidDataError, "os_requirements must be a String." unless @init_data[:os_requirements].is_a?(String) || @init_data[:os_requirements].nil?
122
+ raise JSS::InvalidDataError, "shared must be a String." unless (@init_data[:shared].is_a?(TrueClass) || @init_data[:shared].is_a?(FalseClass)) || @init_data[:shared].nil?
123
+ raise JSS::InvalidDataError, "make_default must be a String." unless (@init_data[:make_default].is_a?(TrueClass) || @init_data[:make_default].is_a?(FalseClass)) || @init_data[:make_default].nil?
124
+ raise JSS::InvalidDataError, "use_generic must be a String." unless (@init_data[:use_generic].is_a?(TrueClass) || @init_data[:use_generic].is_a?(FalseClass)) || @init_data[:use_generic].nil?
125
+
126
+ @uri = @init_data[:uri]
127
+ @CUPS_name = @init_data[:CUPS_name]
128
+ @location = @init_data[:location]
129
+ @model = @init_data[:model]
130
+ @shared = @init_data[:shared]
131
+ @info = @init_data[:info]
132
+ @notes = @init_data[:notes]
133
+ @make_default = @init_data[:make_default]
134
+ @use_generic = @init_data[:use_generic]
135
+ @ppd = @init_data[:ppd]
136
+ @ppd_contents = @init_data[:ppd_contents]
137
+ @ppd_path = @init_data[:ppd_path]
138
+ @os_requirements = @init_data[:os_requirements]
139
+ end
140
+ end
141
+
142
+
143
+ ## Class Methods
144
+ #####################################
145
+
146
+
147
+ # The URI path for the specific printer.
148
+ #
149
+ # @author Tyler Morgan
150
+ #
151
+ # @param newvalue [String]
152
+ #
153
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
154
+ #
155
+ # @return [void]
156
+ def uri=(newvalue)
157
+
158
+ raise JSS::InvalidDataError, "URI must be a string." unless newvalue.is_a? String
159
+
160
+ @uri = newvalue
161
+
162
+ @need_to_update = true
163
+ end
164
+
165
+
166
+ # The CUPs name to be used
167
+ #
168
+ # @author Tyler Morgan
169
+ #
170
+ # @param newvalue [String]
171
+ #
172
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
173
+ #
174
+ # @return [void]
175
+ def CUPS_name=(newvalue)
176
+
177
+ raise JSS::InvalidDataError, "CUPS_name must be a string." unless newvalue.is_a? String
178
+
179
+ @CUPS_name = newvalue
180
+
181
+ @need_to_update = true
182
+ end
183
+
184
+
185
+ # The physical location of the printer.
186
+ #
187
+ # @author Tyler Morgan
188
+ #
189
+ # @param newvalue [String]
190
+ #
191
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
192
+ #
193
+ # @return [void]
194
+ def location=(newvalue)
195
+
196
+ raise JSS::InvalidDataError, "location must be a string." unless newvalue.is_a? String
197
+
198
+ @location = newvalue
199
+
200
+ @need_to_update = true
201
+ end
202
+
203
+
204
+ # The specific model of printer.
205
+ #
206
+ # @author Tyler Morgan
207
+ #
208
+ # @param newvalue [String]
209
+ #
210
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
211
+ #
212
+ # @return [void]
213
+ def model=(newvalue)
214
+
215
+ raise JSS::InvalidDataError, "model must be a string." unless newvalue.is_a? String
216
+
217
+ @model = newvalue
218
+
219
+ @need_to_update = true
220
+ end
221
+
222
+
223
+ # Is this printer to be shared?
224
+ #
225
+ # @author Tyler Morgan
226
+ #
227
+ # @param newvalue [Boolean]
228
+ #
229
+ # @raise [JSS::InvalidDataError] If newvalue is not a Boolean
230
+ #
231
+ # @return [void]
232
+ def shared=(newvalue)
233
+
234
+ raise JSS::InvalidDataError, "shared must be a string." unless newvalue.is_a?(TrueClass) || newvalue.is_a?(FalseClass)
235
+
236
+ @shared = newvalue
237
+
238
+ @need_to_update = true
239
+ end
240
+
241
+
242
+ # Information for this specific printer.
243
+ #
244
+ # @author Tyler Morgan
245
+ #
246
+ # @param newvalue [String]
247
+ #
248
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
249
+ #
250
+ # @return [void]
251
+ def info=(newvalue)
252
+
253
+ raise JSS::InvalidDataError, "info must be a string." unless newvalue.is_a? String
254
+
255
+ @info = newvalue
256
+
257
+ @need_to_update = true
258
+ end
259
+
260
+
261
+ # Notes for this specific printer.
262
+ #
263
+ # @author Tyler Morgan
264
+ #
265
+ # @param newvalue [String]
266
+ #
267
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
268
+ #
269
+ # @return [void]
270
+ def notes=(newvalue)
271
+
272
+ raise JSS::InvalidDataError, "notes must be a string." unless newvalue.is_a? String
273
+
274
+ @notes = newvalue
275
+
276
+ @need_to_update = true
277
+ end
278
+
279
+
280
+ # Make this printer as the default printer upon installation.
281
+ #
282
+ # @author Tyler Morgan
283
+ #
284
+ # @param newvalue [Boolean]
285
+ #
286
+ # @raise [JSS::InvalidDataError] If newvalue is not a Boolean
287
+ #
288
+ # @return [void]
289
+ def make_default=(newvalue)
290
+
291
+ raise JSS::InvalidDataError, "make_default must be a string." unless newvalue.is_a?(TrueClass) || newvalue.is_a?(FalseClass)
292
+
293
+ @make_default = newvalue
294
+
295
+ @need_to_update = true
296
+ end
297
+
298
+
299
+ # Use a generic PPD.
300
+ #
301
+ # @author Tyler Morgan
302
+ #
303
+ # @param newvalue [Boolean]
304
+ #
305
+ # @raise [JSS::InvalidDataError] If newvalue is not a Boolean
306
+ #
307
+ # @return [void]
308
+ def use_generic=(newvalue)
309
+
310
+ raise JSS::InvalidDataError, "use_generic must be a string." unless newvalue.is_a?(TrueClass) || newvalue.is_a?(FalseClass)
311
+
312
+ @use_generic = newvalue
313
+
314
+ @need_to_update = true
315
+ end
316
+
317
+
318
+ # The PPD file name.
319
+ #
320
+ # @author Tyler Morgan
321
+ #
322
+ # @param newvalue [String]
323
+ #
324
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
325
+ #
326
+ # @return [void]
327
+ def ppd=(newvalue)
328
+
329
+ raise JSS::InvalidDataError, "ppd must be a string." unless newvalue.is_a? String
330
+
331
+ @ppd = newvalue
332
+
333
+ @need_to_update = true
334
+ end
335
+
336
+
337
+ # The contents of the PPD file.
338
+ #
339
+ # @author Tyler Morgan
340
+ #
341
+ # @param newvalue [String]
342
+ #
343
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
344
+ #
345
+ # @return [void]
346
+ def ppd_contents=(newvalue)
347
+
348
+ raise JSS::InvalidDataError, "ppd_contents must be a string." unless newvalue.is_a? String
349
+
350
+ @ppd_contents = newvalue
351
+
352
+ @need_to_update = true
353
+ end
354
+
355
+
356
+ # The path the PPD file will be installed.
357
+ #
358
+ # @author Tyler Morgan
359
+ #
360
+ # @param newvalue [String]
361
+ #
362
+ # @raise [JSS::InvalidDataError] If newvalue is not a String
363
+ #
364
+ # @return [void]
365
+ def ppd_path=(newvalue)
366
+
367
+ raise JSS::InvalidDataError, "ppd_path must be a string." unless newvalue.is_a? String
368
+
369
+ @ppd_path = newvalue
370
+
371
+ @need_to_update = true
372
+ end
373
+
374
+
375
+ # The OS version requirements seperated by commas
376
+ #
377
+ # @author Tyler Morgan
378
+ #
379
+ # @param newvalue [String, Float, Array[String], Array[Float]]
380
+ #
381
+ # @raise [JSS::InvalidDataError] If newvalue is not a String, Float, Array containing Strings, or Array containing Floats.
382
+ #
383
+ # @example Limit Printer object to only High Sierra devices and Mojave 10.14.5 OS versions
384
+ # printer.os_requirements = "10.13.x, 10.14.5"
385
+ #
386
+ # @return [void]
387
+ def os_requirements=(newvalue)
388
+
389
+ if newvalue.is_a? Array
390
+ # Parse Array
391
+ raise JSS::InvalidDataError, "If setting os_requirements with an array, it must contain strings or floats." unless newvalue[0].is_a?(String) || newvalue[0].is_a?(Float)
392
+ newvalue = newvalue.map { |x| x.to_s }.join(',')
393
+ else
394
+ raise JSS::InvalidDataError, "os_requirements must either be a string, float, or an array containing strings or floats." unless (newvalue.is_a?(String) || newvalue.is_a?(Float)) && !newvalue.nil?
395
+ end
396
+
397
+ @os_requirements = newvalue
398
+
399
+ @need_to_update = true
400
+ end
401
+
402
+ # Remove the various large data
403
+ # from the instance_variables used to create
404
+ # pretty-print (pp) output.
405
+ #
406
+ # @return [Array] the desired instance_variables
407
+ #
408
+ def pretty_print_instance_variables
409
+ vars = super
410
+ vars.delete :@ppd_contents
411
+ vars
412
+ end
413
+
414
+
415
+ ## Private Instance Methods
416
+ #####################################
417
+ private
418
+
419
+ ### Return the xml for creating or updating this script in the JSS
420
+ ###
421
+ def rest_xml
422
+ doc = REXML::Document.new
423
+ printer = doc.add_element 'printer'
424
+
425
+ printer.add_element('id').text = @id
426
+ printer.add_element('name').text = @name
427
+ printer.add_element('uri').text = @uri
428
+ printer.add_element('CUPS_name').text = @CUPS_name
429
+ printer.add_element('location').text = @location
430
+ printer.add_element('model').text = @model
431
+ printer.add_element('shared').text = @shared
432
+ printer.add_element('info').text = @info
433
+ printer.add_element('notes').text = @notes
434
+ printer.add_element('make_default').text = @make_default
435
+ printer.add_element('use_generic').text = @use_generic
436
+ printer.add_element('ppd').text = @ppd
437
+ printer.add_element('ppd_contents').text = @ppd_contents
438
+ printer.add_element('ppd_path').text = @ppd_path
439
+ printer.add_element('os_requirements').text = @os_requirements
440
+ add_category_to_xml(doc)
441
+
442
+ doc.to_s
443
+
444
+ end
445
+ end
446
+ end
@@ -100,22 +100,17 @@ module JSS
100
100
  @need_to_update = true if @in_jss
101
101
  end
102
102
 
103
-
104
- ### A wrapper around the update method, to try catching RestClient::Conflict
105
- ### 409 errors when we couldn't verify all ldap users/groups due to lack of ldap connections
106
- ###
103
+ # A wrapper around the update method, to try catching 409 conflict errors
104
+ # when we couldn't verify all ldap users/groups due to lack of ldap connections
105
+ #
107
106
  def update
108
- begin
109
- super
110
-
111
- rescue RestClient::Conflict => conflict
112
- if self.scope.unable_to_verify_ldap_entries == true
113
- raise JSS::InvalidDataError, "Potentially non-existant LDAP user or group in new scope values."
114
- else
115
- raise conflict
116
- end
117
-
118
- end # begin
107
+ super
108
+ rescue JSS::ConflictError => conflict
109
+ if scope.unable_to_verify_ldap_entries == true
110
+ raise JSS::InvalidDataError, "Potentially non-existant LDAP user or group in new scope values."
111
+ else
112
+ raise conflict
113
+ end
119
114
  end # update
120
115
 
121
116
  end # module Scopable