ruby-jss 0.6.5 → 0.6.6

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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +57 -5
  3. data/lib/jss.rb +78 -94
  4. data/lib/jss/api_connection.rb +8 -0
  5. data/lib/jss/api_object.rb +126 -102
  6. data/lib/jss/api_object/creatable.rb +33 -15
  7. data/lib/jss/api_object/distribution_point.rb +4 -1
  8. data/lib/jss/api_object/extension_attribute.rb +1 -1
  9. data/lib/jss/api_object/package.rb +121 -187
  10. data/lib/jss/api_object/policy.rb +590 -251
  11. data/lib/jss/api_object/script.rb +92 -128
  12. data/lib/jss/api_object/self_servable.rb +93 -117
  13. data/lib/jss/api_object/updatable.rb +12 -27
  14. data/lib/jss/api_object/uploadable.rb +12 -15
  15. data/lib/jss/client.rb +178 -156
  16. data/lib/jss/db_connection.rb +34 -49
  17. data/lib/jss/ruby_extensions/string.rb +25 -21
  18. data/lib/jss/version.rb +1 -1
  19. data/lib/jss/webhooks.rb +52 -0
  20. data/lib/jss/webhooks/README.md +269 -0
  21. data/lib/jss/webhooks/configuration.rb +212 -0
  22. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation-executable +90 -0
  23. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation.rb +44 -0
  24. data/lib/jss/webhooks/data/sample_jsons/ComputerAdded.json +27 -0
  25. data/lib/jss/webhooks/data/sample_jsons/ComputerCheckIn.json +27 -0
  26. data/lib/jss/webhooks/data/sample_jsons/ComputerInventoryCompleted.json +27 -0
  27. data/lib/jss/webhooks/data/sample_jsons/ComputerPolicyFinished.json +27 -0
  28. data/lib/jss/webhooks/data/sample_jsons/ComputerPushCapabilityChanged.json +27 -0
  29. data/lib/jss/webhooks/data/sample_jsons/JSSShutdown.json +14 -0
  30. data/lib/jss/webhooks/data/sample_jsons/JSSStartup.json +14 -0
  31. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCheckIn.json +26 -0
  32. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCommandCompleted.json +26 -0
  33. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceEnrolled.json +26 -0
  34. data/lib/jss/webhooks/data/sample_jsons/MobileDevicePushSent.json +26 -0
  35. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceUnEnrolled.json +26 -0
  36. data/lib/jss/webhooks/data/sample_jsons/PatchSoftwareTitleUpdated.json +14 -0
  37. data/lib/jss/webhooks/data/sample_jsons/PushSent.json +11 -0
  38. data/lib/jss/webhooks/data/sample_jsons/RestAPIOperation.json +15 -0
  39. data/lib/jss/webhooks/data/sample_jsons/SCEPChallenge.json +10 -0
  40. data/lib/jss/webhooks/data/sample_jsons/SmartGroupComputerMembershipChange.json +13 -0
  41. data/lib/jss/webhooks/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +13 -0
  42. data/lib/jss/webhooks/event.rb +138 -0
  43. data/lib/jss/webhooks/event/computer_added.rb +37 -0
  44. data/lib/jss/webhooks/event/computer_check_in.rb +37 -0
  45. data/lib/jss/webhooks/event/computer_inventory_completed.rb +37 -0
  46. data/lib/jss/webhooks/event/computer_policy_finished.rb +37 -0
  47. data/lib/jss/webhooks/event/computer_push_capability_changed.rb +37 -0
  48. data/lib/jss/webhooks/event/handlers.rb +191 -0
  49. data/lib/jss/webhooks/event/jss_shutdown.rb +37 -0
  50. data/lib/jss/webhooks/event/jss_startup.rb +37 -0
  51. data/lib/jss/webhooks/event/mobile_device_check_in.rb +37 -0
  52. data/lib/jss/webhooks/event/mobile_device_command_completed.rb +37 -0
  53. data/lib/jss/webhooks/event/mobile_device_enrolled.rb +37 -0
  54. data/lib/jss/webhooks/event/mobile_device_push_sent.rb +37 -0
  55. data/lib/jss/webhooks/event/mobile_device_unenrolled.rb +37 -0
  56. data/lib/jss/webhooks/event/patch_software_title_updated.rb +37 -0
  57. data/lib/jss/webhooks/event/push_sent.rb +37 -0
  58. data/lib/jss/webhooks/event/rest_api_operation.rb +37 -0
  59. data/lib/jss/webhooks/event/scep_challenge.rb +37 -0
  60. data/lib/jss/webhooks/event/smart_group_computer_membership_change.rb +37 -0
  61. data/lib/jss/webhooks/event/smart_group_mobile_device_membership_change.rb +37 -0
  62. data/lib/jss/webhooks/event/webhook.rb +39 -0
  63. data/lib/jss/webhooks/event_objects.rb +111 -0
  64. data/lib/jss/webhooks/event_objects/computer.rb +48 -0
  65. data/lib/jss/webhooks/event_objects/jss.rb +35 -0
  66. data/lib/jss/webhooks/event_objects/mobile_device.rb +47 -0
  67. data/lib/jss/webhooks/event_objects/patch_software_title_update.rb +37 -0
  68. data/lib/jss/webhooks/event_objects/push.rb +32 -0
  69. data/lib/jss/webhooks/event_objects/rest_api_operation.rb +36 -0
  70. data/lib/jss/webhooks/event_objects/scep_challenge.rb +31 -0
  71. data/lib/jss/webhooks/event_objects/smart_group.rb +34 -0
  72. data/lib/jss/webhooks/server_app.rb +36 -0
  73. data/lib/jss/webhooks/server_app/routes.rb +26 -0
  74. data/lib/jss/webhooks/server_app/routes/handle_webhook_event.rb +38 -0
  75. data/lib/jss/webhooks/server_app/routes/home.rb +36 -0
  76. data/lib/jss/webhooks/server_app/self_signed_cert.rb +64 -0
  77. data/lib/jss/webhooks/server_app/server.rb +59 -0
  78. data/lib/jss/webhooks/version.rb +31 -0
  79. metadata +63 -4
@@ -1,47 +1,42 @@
1
1
  ### Copyright 2016 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
5
5
  ### compliance with the Apache License and the following modification to it:
6
6
  ### Section 6. Trademarks. is deleted and replaced with:
7
- ###
7
+ ###
8
8
  ### 6. Trademarks. This License does not grant permission to use the trade
9
9
  ### names, trademarks, service marks, or product names of the Licensor
10
10
  ### and its affiliates, except as required to comply with Section 4(c) of
11
11
  ### the License and to reproduce the content of the NOTICE file.
12
- ###
12
+ ###
13
13
  ### You may obtain a copy of the Apache License at
14
- ###
14
+ ###
15
15
  ### http://www.apache.org/licenses/LICENSE-2.0
16
- ###
16
+ ###
17
17
  ### Unless required by applicable law or agreed to in writing, software
18
18
  ### distributed under the Apache License with the above modification is
19
19
  ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
20
  ### KIND, either express or implied. See the Apache License for the specific
21
21
  ### language governing permissions and limitations under the Apache License.
22
- ###
22
+ ###
23
23
  ###
24
24
 
25
25
  ###
26
26
  module JSS
27
27
 
28
- #####################################
29
28
  ### Module Constants
30
29
  #####################################
31
30
 
32
- #####################################
33
31
  ### Module Variables
34
32
  #####################################
35
33
 
36
- #####################################
37
34
  ### Module Methods
38
35
  #####################################
39
36
 
40
- #####################################
41
37
  ### Classes
42
38
  #####################################
43
39
 
44
- ###
45
40
  ### A Script in the JSS.
46
41
  ###
47
42
  ### As of Casper 9.4, the script contents as stored in the database are
@@ -60,23 +55,20 @@ module JSS
60
55
  ###
61
56
  class Script < JSS::APIObject
62
57
 
63
- #####################################
64
58
  ### Mix-Ins
65
59
  #####################################
66
60
 
67
61
  include JSS::Creatable
68
62
  include JSS::Updatable
69
63
 
70
- #####################################
71
64
  ### Class Methods
72
65
  #####################################
73
66
 
74
- #####################################
75
67
  ### Class Constants
76
68
  #####################################
77
69
 
78
70
  ### The base for REST resources of this class
79
- RSRC_BASE = "scripts"
71
+ RSRC_BASE = 'scripts'.freeze
80
72
 
81
73
  ### the hash key used for the JSON list output of all objects in the JSS
82
74
  RSRC_LIST_KEY = :scripts
@@ -86,21 +78,20 @@ module JSS
86
78
  RSRC_OBJECT_KEY = :script
87
79
 
88
80
  ### these keys, as well as :id and :name, are present in valid API JSON data for this class
89
- VALID_DATA_KEYS = [:parameters, :filename, :os_requirements ]
81
+ VALID_DATA_KEYS = [:parameters, :filename, :os_requirements].freeze
90
82
 
91
83
  ### The script storage folder on the distribution point, if used
92
- DIST_POINT_SCRIPTS_FOLDER = "Scripts"
84
+ DIST_POINT_SCRIPTS_FOLDER = 'Scripts'.freeze
93
85
 
94
86
  ### Priority to use for running the script in relation to other actions during imaging
95
- PRIORITIES = [ 'Before', 'After','At Reboot']
87
+ PRIORITIES = ['Before', 'After', 'At Reboot'].freeze
96
88
 
97
89
  ### which is default?
98
- DEFAULT_PRIORITY = "After"
90
+ DEFAULT_PRIORITY = 'After'.freeze
99
91
 
100
92
  ### The keys used in the @parameters Hash
101
- PARAMETER_KEYS = [:parameter4, :parameter5, :parameter6,:parameter7, :parameter8, :parameter9, :parameter10, :parameter11]
93
+ PARAMETER_KEYS = [:parameter4, :parameter5, :parameter6, :parameter7, :parameter8, :parameter9, :parameter10, :parameter11].freeze
102
94
 
103
- #####################################
104
95
  ### Attributes
105
96
  #####################################
106
97
 
@@ -128,29 +119,23 @@ module JSS
128
119
  ### @return {String] the actual code for this script, if it's stored in the database.
129
120
  attr_reader :script_contents
130
121
 
131
-
132
- #####################################
133
122
  ### Constructor
134
123
  #####################################
135
124
 
136
125
  ###
137
- ###
138
- ###
139
- def initialize (args = {})
126
+ def initialize(args = {})
140
127
  super
141
128
 
142
129
  @category = JSS::APIObject.get_name(@init_data[:category])
143
130
  @filename = @init_data[:filename] || @name
144
131
  @info = @init_data[:info]
145
132
  @notes = @init_data[:notes]
146
- @os_requirements = @init_data[:os_requirements] ? JSS.to_s_and_a(@init_data[:os_requirements] )[:arrayform] : []
133
+ @os_requirements = @init_data[:os_requirements] ? JSS.to_s_and_a(@init_data[:os_requirements])[:arrayform] : []
147
134
  @parameters = @init_data[:parameters] ? @init_data[:parameters] : {}
148
135
  @priority = @init_data[:priority] || DEFAULT_PRIORITY
149
- @script_contents = @init_data[:script_contents]
150
-
136
+ @script_contents = @init_data[:script_contents]
151
137
  end # initialize
152
138
 
153
- ###
154
139
  ### Change the script filename
155
140
  ###
156
141
  ### Setting it to nil will make it match the script name
@@ -162,8 +147,7 @@ module JSS
162
147
  ### @note This method does NOT change the filename on the distribution point
163
148
  ### if that's where you store your scripts.
164
149
  ###
165
- def filename= (new_val)
166
-
150
+ def filename=(new_val)
167
151
  new_val = nil if new_val == ''
168
152
  new_val = @name unless new_val
169
153
 
@@ -171,9 +155,8 @@ module JSS
171
155
 
172
156
  @filename = new_val
173
157
  @need_to_update = true
174
- end #filename=
158
+ end # filename=
175
159
 
176
- ###
177
160
  ### Change the script's display name
178
161
  ###
179
162
  ### If the filename is the same as the name, the filename will be changed also
@@ -182,7 +165,7 @@ module JSS
182
165
  ###
183
166
  ### @return [void]
184
167
  ###
185
- def name= (new_val)
168
+ def name=(new_val)
186
169
  return nil if new_val == @name
187
170
  new_val = nil if new_val == ''
188
171
  raise JSS::MissingDataError, "Name can't be empty" unless new_val
@@ -195,9 +178,8 @@ module JSS
195
178
  ### if our REST resource is based on the name, update that too
196
179
  @rest_rsrc = "#{RSRC_BASE}/name/#{CGI.escape @name}" if @rest_rsrc.include? '/name/'
197
180
  @need_to_update = true
198
- end #name=
181
+ end # name=
199
182
 
200
- ###
201
183
  ### Change the os_requirements
202
184
  ###
203
185
  ### Minumum OS's can be specified as a string using the notation ">=10.6.7"
@@ -217,90 +199,84 @@ module JSS
217
199
  ### @example Minimum OS
218
200
  ### myscript.os_requirements ">=10.7.5"
219
201
  ###
220
- def os_requirements= (new_val)
202
+ def os_requirements=(new_val)
221
203
  ### nil should be an empty array
222
204
  new_val = [] if new_val.to_s.empty?
223
205
 
224
206
  ### if any value starts with >=, expand it
225
207
  case new_val
226
- when String
227
- new_val = JSS.expand_min_os(new_val) if new_val =~ /^>=/
228
- when Array
229
- new_val.map!{|a| a =~ /^>=/ ? JSS.expand_min_os(a) : a }
230
- new_val.flatten!
231
- new_val.uniq!
232
- else
233
- raise JSS::InvalidDataError, "os_requirements must be a String or an Array of strings"
208
+ when String
209
+ new_val = JSS.expand_min_os(new_val) if new_val =~ /^>=/
210
+ when Array
211
+ new_val.map! { |a| a =~ /^>=/ ? JSS.expand_min_os(a) : a }
212
+ new_val.flatten!
213
+ new_val.uniq!
214
+ else
215
+ raise JSS::InvalidDataError, 'os_requirements must be a String or an Array of strings'
234
216
  end # case
235
217
 
236
218
  ### get the array version
237
219
  @os_requirements = JSS.to_s_and_a(new_val)[:arrayform]
238
220
  @need_to_update = true
221
+ end # os_requirements=
239
222
 
240
- end #os_requirements=
241
-
242
- ###
243
223
  ### Change the priority of this script
244
224
  ###
245
225
  ### @param new_val[Integer] the new priority, which must be one of {PRIORITIES}
246
226
  ###
247
227
  ### @return [void]
248
228
  ###
249
- def priority= (new_val)
229
+ def priority=(new_val)
250
230
  return nil if new_val == @priority
251
- new_val = DEFAULT_PRIORITY if new_val.nil? or new_val == ""
231
+ new_val = DEFAULT_PRIORITY if new_val.nil? || (new_val == '')
252
232
  raise JSS::InvalidDataError, ":priority must be one of: #{PRIORITIES.join ', '}" unless PRIORITIES.include? new_val
253
233
  @priority = new_val
254
234
  @need_to_update = true
255
- end #priority=
235
+ end # priority=
256
236
 
257
- ###
258
237
  ### Change the info field
259
238
  ###
260
239
  ### @param new_val[String] the new info
261
240
  ###
262
241
  ### @return [void]
263
242
  ###
264
- def info= (new_val)
243
+ def info=(new_val)
265
244
  return nil if new_val == @info
266
245
  ### line breaks should be \r
267
- new_val = new_val.to_s.gsub(/\n/, "\r")
246
+ new_val = new_val.to_s.tr("\n", "\r")
268
247
  @info = new_val
269
248
  @need_to_update = true
270
- end #info=
249
+ end # info=
271
250
 
272
- ###
273
251
  ### Change the notes field
274
252
  ###
275
253
  ### @param new_val[String] the new notes
276
254
  ###
277
255
  ### @return [void]
278
256
  ###
279
- def notes= (new_val)
257
+ def notes=(new_val)
280
258
  return nil if new_val == @notes
281
259
  ### line breaks should be \r
282
- new_val = new_val.to_s.gsub(/\n/, "\r")
260
+ new_val = new_val.to_s.tr("\n", "\r")
283
261
  @notes = new_val
284
262
  @need_to_update = true
285
- end #notes=
263
+ end # notes=
286
264
 
287
- ###
288
265
  ### Change the category
289
266
  ###
290
267
  ### @param new_val[String] the name of the new category, which must be in {JSS::Category.all_names}
291
268
  ###
292
269
  ### @return [void]
293
270
  ###
294
- def category= (new_val)
271
+ def category=(new_val)
295
272
  return nil if new_val == @category
296
273
  new_val = nil if new_val == ''
297
274
  new_val ||= JSS::Category::DEFAULT_CATEGORY
298
275
  raise JSS::InvalidDataError, "Category #{new_val} is not known to the JSS" unless JSS::Category.all_names.include? new_val
299
276
  @need_to_update = true
300
277
  @category = new_val
301
- end #category=
278
+ end # category=
302
279
 
303
- ###
304
280
  ### Replace all the script parameters at once.
305
281
  ###
306
282
  ### This will replace the entire set with the hash provided.
@@ -309,21 +285,21 @@ module JSS
309
285
  ###
310
286
  ### @return [void]
311
287
  ###
312
- def parameters= (new_val)
288
+ def parameters=(new_val)
313
289
  return nil if new_val == @parameters
314
- new_val = {} if new_val.nil? or new_val== ''
290
+ new_val = {} if new_val.nil? || (new_val == '')
315
291
 
316
292
  ### check the values
317
- raise JSS::InvalidDataError, ":parameters must be a Hash with keys :parameter4 thru :parameter11" unless new_val.kind_of? Hash and (new_val.keys & PARAMETER_KEYS) == new_val.keys
318
- new_val.each do |k,v|
319
- raise JSS::InvalidDataError, ":parameter values must be strings or nil" unless v.nil? or v.kind_of? String
293
+ raise JSS::InvalidDataError, ':parameters must be a Hash with keys :parameter4 thru :parameter11' unless \
294
+ new_val.is_a?(Hash) && ((new_val.keys & PARAMETER_KEYS) == new_val.keys)
295
+ new_val.each do |_k, v|
296
+ raise JSS::InvalidDataError, ':parameter values must be strings or nil' unless v.nil? || v.is_a?(String)
320
297
  end
321
298
 
322
299
  @parameters = new_val
323
300
  @need_to_update = true
324
301
  end # parameters=
325
302
 
326
- ###
327
303
  ### Change one of the stored parameters
328
304
  ###
329
305
  ### @param param_num[Integer] which param are we setting? must be 4..11
@@ -332,16 +308,15 @@ module JSS
332
308
  ###
333
309
  ### @return [void]
334
310
  ###
335
- def set_parameter (param_num, new_val)
336
- raise JSS::NoSuchItemError, "Parameter numbers must be from 4-11" unless (4..11).include? param_num
311
+ def set_parameter(param_num, new_val)
312
+ raise JSS::NoSuchItemError, 'Parameter numbers must be from 4-11' unless (4..11).cover? param_num
337
313
  pkey = "parameter#{param_num}".to_sym
338
- raise JSS::InvalidDataError, "parameter values must be strings or nil" unless new_val.nil? or new_val.kind_of? String
314
+ raise JSS::InvalidDataError, 'parameter values must be strings or nil' unless new_val.nil? || new_val.is_a?(String)
339
315
  return nil if new_val == @parameters[pkey]
340
316
  @parameters[pkey] = new_val
341
317
  @need_to_update = true
342
318
  end
343
319
 
344
- ###
345
320
  ### Change the executable code of this script.
346
321
  ###
347
322
  ### If the arg is a Pathname instance, or a String starting with "/"
@@ -356,20 +331,19 @@ module JSS
356
331
  ###
357
332
  ### @return [void]
358
333
  ###
359
- def script_contents= (new_val)
360
-
334
+ def script_contents=(new_val)
361
335
  new_code = case new_val
362
- when String
363
- if new_val.start_with? '/'
364
- Pathname.new(new_val).read
365
- else
366
- new_val
367
- end #if
368
- when Pathname
369
- new_val.read
370
- else
371
- raise JSS::InvalidDataError, "New code must be a String (path or code) or Pathname instance"
372
- end # case
336
+ when String
337
+ if new_val.start_with? '/'
338
+ Pathname.new(new_val).read
339
+ else
340
+ new_val
341
+ end # if
342
+ when Pathname
343
+ new_val.read
344
+ else
345
+ raise JSS::InvalidDataError, 'New code must be a String (path or code) or Pathname instance'
346
+ end # case
373
347
 
374
348
  raise JSS::InvalidDataError, "Script contents must start with '#!'" unless new_code.start_with? '#!'
375
349
 
@@ -377,7 +351,6 @@ module JSS
377
351
  @need_to_update = true
378
352
  end
379
353
 
380
- ###
381
354
  ### Save the @script_contents for this script to a file on the Master Distribution point.
382
355
  ###
383
356
  ### If you'll be uploading several files you can specify unmount as false, and do it manually when all
@@ -391,18 +364,17 @@ module JSS
391
364
  ###
392
365
  ### @return [void]
393
366
  ###
394
- def upload_master_file( rw_pw, unmount = true)
395
- raise JSS::MissingDataError, "No code specified. Use #code= first." if @script_contents.nil? or @script_contents.empty?
367
+ def upload_master_file(rw_pw, unmount = true)
368
+ raise JSS::MissingDataError, 'No code specified. Use #code= first.' if @script_contents.nil? || @script_contents.empty?
396
369
 
397
370
  mdp = JSS::DistributionPoint.master_distribution_point
398
- raise JSS::InvaldDatatError, "Incorrect password for read-write access to master distribution point." unless mdp.check_pw :rw, rw_pw
371
+ raise JSS::InvaldDatatError, 'Incorrect password for read-write access to master distribution point.' unless mdp.check_pw :rw, rw_pw
399
372
 
400
373
  destination = mdp.mount(rw_pw, :rw) + "#{DIST_POINT_SCRIPTS_FOLDER}/#{@filename}"
401
374
  destination.save @script_contents
402
375
  mdp.unmount if unmount
403
376
  end # upload
404
377
 
405
- ###
406
378
  ### Delete the filename from the master distribution point, if it exists.
407
379
  ###
408
380
  ### If you'll be uploading several files you can specify unmount as false, and do it manually when all
@@ -423,11 +395,9 @@ module JSS
423
395
  did_it = false
424
396
  end # if exists
425
397
  JSS::DistributionPoint.master_distribution_point.unmount if unmount
426
- return did_it
398
+ did_it
427
399
  end
428
400
 
429
-
430
- ###
431
401
  ### Run this script on the current machine using the "jamf runScript" command.
432
402
  ###
433
403
  ### If the script code is available in the {#script_contents} attribute, then that
@@ -482,9 +452,8 @@ module JSS
482
452
  ### p1-p8, and that's how they are expected as options to #run. So if :p1=> "new param" is given as an
483
453
  ### aption to #run, it will override any value that the API provided in @parameters[:parameter4]
484
454
  ###
485
- def run( opts = {} )
486
-
487
- opts[:target] ||= "/"
455
+ def run(opts = {})
456
+ opts[:target] ||= '/'
488
457
  opts[:p1] ||= @parameters[:parameter4]
489
458
  opts[:p2] ||= @parameters[:parameter5]
490
459
  opts[:p3] ||= @parameters[:parameter6]
@@ -500,14 +469,14 @@ module JSS
500
469
  begin
501
470
 
502
471
  # do we have the code already? if so, save it out and make it executable
503
- if @script_contents and (not @script_contents.empty?)
472
+ if @script_contents && !@script_contents.empty?
504
473
 
505
474
  script_path = JSS::Client::DOWNLOADS_FOLDER
506
475
 
507
476
  executable = script_path + @filename
508
477
 
509
478
  executable.jss_touch
510
- executable.chmod 0700
479
+ executable.chmod 0o700
511
480
  executable.jss_save @script_contents
512
481
  delete_exec = true
513
482
 
@@ -528,63 +497,60 @@ module JSS
528
497
 
529
498
  end # if @script_contents and (not @script_contents.empty?)
530
499
 
531
-
532
500
  # build the command as an array.
533
- command_arry = ["-script", @filename, '-path', script_path.to_s]
501
+ command_arry = ['-script', @filename, '-path', script_path.to_s]
534
502
 
535
- command_arry << "-target"
503
+ command_arry << '-target'
536
504
  command_arry << opts[:target].to_s
537
505
 
538
- command_arry << "-computerName" if opts[:computer_name]
506
+ command_arry << '-computerName' if opts[:computer_name]
539
507
  command_arry << opts[:computer_name] if opts[:computer_name]
540
508
 
541
- command_arry << "-username" if opts[:username]
509
+ command_arry << '-username' if opts[:username]
542
510
  command_arry << opts[:username] if opts[:username]
543
511
 
544
- command_arry << "-p1" if opts[:p1]
512
+ command_arry << '-p1' if opts[:p1]
545
513
  command_arry << opts[:p1] if opts[:p1]
546
514
 
547
- command_arry << "-p2" if opts[:p2]
515
+ command_arry << '-p2' if opts[:p2]
548
516
  command_arry << opts[:p2] if opts[:p2]
549
517
 
550
- command_arry << "-p3" if opts[:p3]
518
+ command_arry << '-p3' if opts[:p3]
551
519
  command_arry << opts[:p3] if opts[:p3]
552
520
 
553
- command_arry << "-p4" if opts[:p4]
521
+ command_arry << '-p4' if opts[:p4]
554
522
  command_arry << opts[:p4] if opts[:p4]
555
523
 
556
- command_arry << "-p5" if opts[:p5]
524
+ command_arry << '-p5' if opts[:p5]
557
525
  command_arry << opts[:p5] if opts[:p5]
558
526
 
559
- command_arry << "-p6" if opts[:p6]
527
+ command_arry << '-p6' if opts[:p6]
560
528
  command_arry << opts[:p6] if opts[:p6]
561
529
 
562
- command_arry << "-p7" if opts[:p7]
530
+ command_arry << '-p7' if opts[:p7]
563
531
  command_arry << opts[:p7] if opts[:p7]
564
532
 
565
- command_arry << "-p8" if opts[:p8]
533
+ command_arry << '-p8' if opts[:p8]
566
534
  command_arry << opts[:p8] if opts[:p8]
567
535
 
568
- command_arry << "-verbose" if opts[:verbose]
536
+ command_arry << '-verbose' if opts[:verbose]
569
537
 
570
538
  command = command_arry.shelljoin
571
539
 
572
- jamf_output = JSS::Client.run_jamf "runScript", command, opts[:show_output]
540
+ jamf_output = JSS::Client.run_jamf 'runScript', command, opts[:show_output]
573
541
 
574
542
  jamf_output =~ /^.*Script exit code: (\d+)(\D|$)/
575
543
 
576
- script_exitstatus = $1.to_i
544
+ script_exitstatus = Regexp.last_match(1).to_i
577
545
 
578
546
  ensure
579
- executable.delete if delete_exec and executable.exist?
580
- dist_point.unmount if (dp_mount_pt and dp_mount_pt.mountpoint? and opts[:unmount])
547
+ executable.delete if delete_exec && executable.exist?
548
+ dist_point.unmount if dp_mount_pt && dp_mount_pt.mountpoint? && opts[:unmount]
581
549
  end # begin/ensure
582
550
 
583
- return [script_exitstatus, jamf_output]
584
-
551
+ [script_exitstatus, jamf_output]
585
552
  end # def run
586
553
 
587
-
588
554
  # aliases under their methods seem to confuse the YARD documenter, so I'm putting them all here.
589
555
  alias oses os_requirements
590
556
  alias oses= os_requirements=
@@ -593,19 +559,16 @@ module JSS
593
559
  alias contents script_contents
594
560
  alias contents= script_contents=
595
561
 
596
-
597
- #####################################
598
562
  ### Private Instance Methods
599
563
  #####################################
600
564
 
601
565
  private
602
566
 
603
- ###
604
567
  ### Return the xml for creating or updating this script in the JSS
605
568
  ###
606
569
  def rest_xml
607
570
  doc = REXML::Document.new
608
- scpt = doc.add_element "script"
571
+ scpt = doc.add_element 'script'
609
572
  scpt.add_element('category').text = @category
610
573
  scpt.add_element('filename').text = @filename
611
574
  scpt.add_element('id').text = @id
@@ -619,13 +582,14 @@ module JSS
619
582
  scpt.add_element('parameters').text = nil
620
583
  else
621
584
  pars = scpt.add_element('parameters')
622
- PARAMETER_KEYS.each {|p| pars.add_element(p.to_s).text = @parameters[p]}
585
+ PARAMETER_KEYS.each { |p| pars.add_element(p.to_s).text = @parameters[p] }
623
586
  end
624
587
 
625
588
  scpt.add_element('script_contents_encoded').text = Base64.encode64(@script_contents)
626
589
 
627
- return doc.to_s
590
+ doc.to_s
628
591
  end # rest xml
629
592
 
630
593
  end # class Script
631
- end # midule
594
+
595
+ end # module