ruby-jss 2.1.1 → 3.0.0b1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efe85ea732df2a1ce119273c532084459fdb9ebe6316d62ab7afa533d9c4adc8
4
- data.tar.gz: e42de1baecb51f2886d704e63818d24063d4332a0b17170c2977aa3e336656a5
3
+ metadata.gz: a7af617b6ac8bb27cbc7d5c790a2de9fa788fb3d426ae062581654fbc9f77c5f
4
+ data.tar.gz: f5dfabfdde6c466951862fdc458321ad4f9384293e1fe773fb78a0ca80e51283
5
5
  SHA512:
6
- metadata.gz: 6a0874d08b6c7fc3aa93c207c81ab3a09c0b822e5f035ddb5192144d04fbe3a846db6c6528a8150cd81a2ee9f994155d4b7ba396d11ef7ecf565c9330b99aae6
7
- data.tar.gz: fb3bdf758de69f290974def92a42ff279f1c98611373116304fbe618b0536f59361d892c3444db88c952c2208bb7cfbf0763cba8a959bd84cffb3ca5f8bee8e7
6
+ metadata.gz: 85fd8c1218206a35545cc034058996a5b03183f29ac443cf65735c547975afcedaf406f74099f610380a1b72272db5240c2427ab4e87201ef5d9ec7ceffd2f29
7
+ data.tar.gz: a04b06cbcb9858b06dfe738ced2943e37b6a12088da394599b6ccfae66ac0a9c1bc82a264dac02c0379308141d4cc9795594c19639f473e5684cdd62e48db368
data/CHANGES.md CHANGED
@@ -16,6 +16,21 @@ Many many thanks to actae0n of Blacksun Hackers Club for reporting this issue an
16
16
 
17
17
  --------
18
18
 
19
+ ## \[UNRELEASED]
20
+
21
+ ### Added
22
+ - Jamf::Policy.flush_logs_for_computers: formerly private class method, now public and used for flushing policy logs for specific computers.
23
+
24
+ ### Fixed
25
+ - Fix bug in MDM enable_lost_mode instance method, and make the default behavior match the API
26
+ - Specify the connection instance when validating ids in MacOSManagedUpdates
27
+ - Send mandatory field 'name' with a MobileDeviceApplication request (Thanks @yanniks!)
28
+ - Policy Log Flushing now reflects API limitation: You can flush logs for a policy for all computers, or for a computer for all policies, but not specific policies for specific computers. See Jamf::Policy.flush_logs and Jamf::Policy.flush_logs_for_computers
29
+ - A validation method wasn't passing cnx param correctly.
30
+
31
+ ### Changed
32
+ - MacOSManagedUpdates.send_managed_os_update takes symbols as the updateAction
33
+
19
34
  ## \[2.1.1] - 2022-11-07
20
35
 
21
36
  ### Fixed & Deprecated
@@ -1158,15 +1158,29 @@ module Jamf
1158
1158
  @need_to_update = true
1159
1159
  end
1160
1160
 
1161
- # flush the logs for this computer in a given policy
1162
- # @see Jamf::Policy.flush_logs
1161
+ # Flush all policy logs for this computer older than a given time period.
1163
1162
  #
1164
- def flush_policy_logs(policy, older_than: 0, period: :days)
1165
- Jamf::Policy.flush_logs(
1166
- policy,
1163
+ # IMPORTANT: from the Jamf Developer Site:
1164
+ # The ability to flush logs is currently only supported for flushing all logs
1165
+ # for a given policy or all logs for a given computer. There is no support for
1166
+ # flushing logs for a given policy and computer combination.
1167
+ #
1168
+ # With no parameters, will flush all logs for the computer
1169
+ #
1170
+ # NOTE: Currently the API doesn't have a way to flush only failed policies.
1171
+ #
1172
+ # @param older_than[Integer] 0, 1, 2, 3, or 6
1173
+ #
1174
+ # @param period[Symbol] :days, :weeks, :months, or :years
1175
+ #
1176
+ # @see Jamf::Policy.flush_logs_for_computers
1177
+ #
1178
+ def flush_policy_logs(older_than: 0, period: :days)
1179
+ Jamf::Policy.flush_logs_for_computers(
1180
+ [@id],
1167
1181
  older_than: older_than,
1168
1182
  period: period,
1169
- computers: [@id], cnx: @cnx
1183
+ cnx: @cnx
1170
1184
  )
1171
1185
  end
1172
1186
 
@@ -476,7 +476,7 @@ module Jamf
476
476
  raise Jamf::UnmanagedError, "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd.include? target_id
477
477
  end
478
478
  end # unles
479
-
479
+
480
480
  targets
481
481
  end
482
482
 
@@ -860,7 +860,7 @@ module Jamf
860
860
  cnx = api if api
861
861
 
862
862
  unless WALLPAPER_LOCATIONS.keys.include? wallpaper_setting
863
- raise ArgumentError,
863
+ raise ArgumentError,
864
864
  "wallpaper_setting must be one of: :#{WALLPAPER_LOCATIONS.keys.join ', :'}"
865
865
  end
866
866
 
@@ -999,7 +999,7 @@ module Jamf
999
999
  #
1000
1000
  # @param play_sound[Boolean] Play a sound when entering lost mode
1001
1001
  #
1002
- # @param enforce_lost_mode[Boolean] Re-enabled lost mode when re-enrolled after wipe.
1002
+ # @param enforce_lost_mode[Boolean] Re-enable lost mode when re-enrolled after wipe. Default is false
1003
1003
  #
1004
1004
  # @param cnx [Jamf::Connection] the API thru which to send the command
1005
1005
  #
@@ -1011,7 +1011,7 @@ module Jamf
1011
1011
  phone: nil,
1012
1012
  footnote: nil,
1013
1013
  play_sound: false,
1014
- enforce_lost_mode: true,
1014
+ enforce_lost_mode: false,
1015
1015
  api: nil,
1016
1016
  cnx: Jamf.cnx
1017
1017
  )
@@ -1081,7 +1081,7 @@ module Jamf
1081
1081
 
1082
1082
  status = FLUSHABLE_STATUSES[status]
1083
1083
 
1084
- # TODO: add 'unmanaged_ok:' param to raw_targets_to_ids method, so that we can
1084
+ # TODO: add 'unmanaged_ok:' param to raw_targets_to_ids method, so that we can
1085
1085
  # use this to flush commands for unmanaged machines.
1086
1086
  target_ids = raw_targets_to_ids targets, cnx: cnx, expand_groups: false, unmanaged_ok: true
1087
1087
 
@@ -1378,21 +1378,21 @@ module Jamf
1378
1378
  #
1379
1379
  # @param play_sound[Boolean] Play a sound when entering lost mode
1380
1380
  #
1381
- # @param enforce_lost_mode[Boolean] Re-enabled lost mode when re-enrolled after wipe.
1381
+ # @param enforce_lost_mode[Boolean] Re-enable lost mode when re-enrolled after wipe. Default is false
1382
1382
  #
1383
1383
  # @return (see .send_mdm_command)
1384
1384
  #
1385
1385
  def enable_lost_mode(
1386
1386
  message: nil,
1387
- phone_number: nil,
1387
+ phone: nil,
1388
1388
  footnote: nil,
1389
- enforce_lost_mode: true,
1389
+ enforce_lost_mode: false,
1390
1390
  play_sound: false
1391
1391
  )
1392
1392
  self.class.enable_lost_mode(
1393
1393
  @id,
1394
1394
  message: message,
1395
- phone_number: phone_number,
1395
+ phone: phone,
1396
1396
  footnote: footnote,
1397
1397
  play_sound: play_sound,
1398
1398
  enforce_lost_mode: enforce_lost_mode, cnx: @cnx
@@ -544,6 +544,7 @@ module Jamf
544
544
  doc = REXML::Document.new Jamf::Connection::XML_HEADER
545
545
  obj = doc.add_element self.class::RSRC_OBJECT_KEY.to_s
546
546
  gen = obj.add_element 'general'
547
+ gen.add_element('name').text = @display_name
547
548
  gen.add_element('display_name').text = @display_name
548
549
  gen.add_element('description').text = @description
549
550
  gen.add_element('os_type').text = @os_type
@@ -293,10 +293,19 @@ module Jamf
293
293
  # Class Methods
294
294
  ######################
295
295
 
296
- # Flush logs for a given policy older than some number of days, weeks,
297
- # months or years, possibly limited to one or more computers.
296
+ # Flush logs for a given policy older than a given time period.
297
+ # This flushes the logs of the given policy for all computers.
298
298
  #
299
- # With no parameters, flushes all logs for the policy for all computers.
299
+ # IMPORTANT: from the Jamf Developer Site:
300
+ # The ability to flush logs is currently only supported for flushing all logs
301
+ # for a given policy or all logs for a given computer. There is no support for
302
+ # flushing logs for a given policy and computer combination.
303
+ #
304
+ # (See .flush_logs_for_computers to to flush all logs for given computers)
305
+ #
306
+ # With no parameters, flushes all logs for the policy.
307
+ #
308
+ # Without older_than: and period:, will flush all logs for the policy
300
309
  #
301
310
  # NOTE: Currently the API doesn't have a way to flush only failed policies.
302
311
  #
@@ -306,52 +315,74 @@ module Jamf
306
315
  #
307
316
  # @param policy[Integer,String] The id or name of the policy to flush
308
317
  #
309
- # @param older_than[Integer] 0, 1, 2, 3, or 6
310
- #
311
- # @param period[Symbol] :days, :weeks, :months, or :years
318
+ # @param older_than[Integer] 0, 1, 2, 3, or 6, defaults to 0
312
319
  #
313
- # @param computers[Array<Integer,String>] Identifiers of the target computers
314
- # either ids, names, SNs, macaddrs, or UDIDs. If omitted, flushes logs for
315
- # all computers
320
+ # @param period[Symbol] :days, :weeks, :months, or :years, defaults to :days
316
321
  #
317
322
  # @param cnx [Jamf::Connection] the API connection to use.
318
323
  #
319
324
  # @return [void]
320
325
  #
321
- def self.flush_logs(policy, older_than: 0, period: :days, computers: [], api: nil, cnx: Jamf.cnx)
326
+ def self.flush_logs(policy, older_than: 0, period: :days, api: nil, cnx: Jamf.cnx)
322
327
  cnx = api if api
323
328
 
324
- orig_timeout = cnx.timeout
325
329
  pol_id = valid_id policy, cnx: cnx
326
330
  raise Jamf::NoSuchItemError, "No Policy identified by '#{policy}'." unless pol_id
327
331
 
328
- older_than = LOG_FLUSH_INTERVAL_INTEGERS[older_than]
329
- raise Jamf::InvalidDataError, "older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}" unless older_than
330
-
331
- period = LOG_FLUSH_INTERVAL_PERIODS[period]
332
- raise Jamf::InvalidDataError, "period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}" unless period
333
-
334
- computers = [computers] unless computers.is_a? Array
332
+ older_than, period = validate_log_flush_params(older_than, period)
335
333
 
336
334
  # log flushes can be really slow
335
+ orig_timeout = cnx.timeout
337
336
  cnx.timeout = 1800 unless orig_timeout && orig_timeout > 1800
338
337
 
339
- return cnx.c_delete "#{LOG_FLUSH_RSRC}/policy/id/#{pol_id}/interval/#{older_than}+#{period}" if computers.empty?
340
-
341
- flush_logs_for_specific_computers pol_id, older_than, period, computers, cnx
338
+ cnx.c_delete "#{LOG_FLUSH_RSRC}/policy/id/#{pol_id}/interval/#{older_than}+#{period}"
342
339
  ensure
343
340
  cnx.timeout = orig_timeout
344
341
  end
345
342
 
346
- # use an XML body in a DELETE request to flush logs for
347
- # a list of computers - used by the flush_logs class method
348
- def self.flush_logs_for_specific_computers(pol_id, older_than, period, computers, cnx)
343
+ # Flush policy logs for specific computers older than a given time period.
344
+ # This flushes the logs for all policies for these computers.
345
+ #
346
+ # IMPORTANT: from the Jamf Developer Site:
347
+ # The ability to flush logs is currently only supported for flushing all logs
348
+ # for a given policy or all logs for a given computer. There is no support for
349
+ # flushing logs for a given policy and computer combination.
350
+ #
351
+ # (See .flush_logs to to flush all logs for a given policy)
352
+ #
353
+ # Without older_than: and period:, will flush all logs for the computers
354
+ #
355
+ # NOTE: Currently the API doesn't have a way to flush only failed policies.
356
+ #
357
+ # WARNING: Log flushing can take a long time, and the API call doesnt return
358
+ # until its finished. The connection timeout will be temporarily raised to
359
+ # 30 minutes, unless it's already higher.
360
+ #
361
+ # @param computers[Array<Integer,String>] Identifiers of the target computers
362
+ # either ids, names, SNs, macaddrs, or UDIDs.
363
+ #
364
+ # @param older_than[Integer] 0, 1, 2, 3, or 6, defaults to 0
365
+ #
366
+ # @param period[Symbol] :days, :weeks, :months, or :years, defaults to :days
367
+ #
368
+ # @param cnx [Jamf::Connection] the API connection to use.
369
+ #
370
+ # @return [void]
371
+ #
372
+ def self.flush_logs_for_computers(computers = [], older_than: 0, period: :days, api: nil, cnx: Jamf.cnx)
373
+ cnx = api if api
374
+
375
+ computers = [computers] unless computers.is_a? Array
376
+ raise JSS::InvalidDataError, 'One or more computers must be specified' if computers.empty?
377
+
378
+ older_than, period = validate_log_flush_params(older_than, period)
379
+
349
380
  # build the xml body for a DELETE request
350
381
  xml_doc = REXML::Document.new Jamf::Connection::XML_HEADER
351
382
  lf = xml_doc.add_element 'logflush'
352
383
  lf.add_element('log').text = 'policy'
353
- lf.add_element('log_id').text = pol_id.to_s
354
384
  lf.add_element('interval').text = "#{older_than} #{period}"
385
+
355
386
  comps_elem = lf.add_element 'computers'
356
387
  computers.each do |c|
357
388
  id = Jamf::Computer.valid_id c, cnx: cnx
@@ -361,13 +392,41 @@ module Jamf
361
392
  ce.add_element('id').text = id.to_s
362
393
  end
363
394
 
395
+ # for debugging the xml...
396
+ #
397
+ # formatter = REXML::Formatters::Pretty.new(2)
398
+ # formatter.compact = true
399
+ # formatter.write(xml_doc, $stdout)
400
+ # puts
401
+ # return
402
+
403
+ # log flushes can be really slow
404
+ orig_timeout = cnx.timeout
405
+ cnx.timeout = 1800 unless orig_timeout && orig_timeout > 1800
406
+
364
407
  # Do a DELETE request with a body.
365
- cnx.delete(LOG_FLUSH_RSRC) do |req|
408
+ resp = cnx.c_cnx.delete(LOG_FLUSH_RSRC) do |req|
366
409
  req.headers[Jamf::Connection::HTTP_CONTENT_TYPE_HEADER] = Jamf::Connection::MIME_XML
367
410
  req.body = xml_doc.to_s
368
411
  end
412
+
413
+ resp.body
414
+ ensure
415
+ cnx.timeout = orig_timeout
369
416
  end
370
- private_class_method :flush_logs_for_specific_computers
417
+
418
+ # validate the logflush params
419
+ # @return [Array<String>]
420
+ def self.validate_log_flush_params(older_than, period)
421
+ older_than = LOG_FLUSH_INTERVAL_INTEGERS[older_than]
422
+ raise Jamf::InvalidDataError, "older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}" unless older_than
423
+
424
+ period = LOG_FLUSH_INTERVAL_PERIODS[period]
425
+ raise Jamf::InvalidDataError, "period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}" unless period
426
+
427
+ [older_than, period]
428
+ end
429
+ private_class_method :validate_log_flush_params
371
430
 
372
431
  # Attributes
373
432
  ######################
@@ -1852,11 +1911,14 @@ module Jamf
1852
1911
  end
1853
1912
  alias execute run
1854
1913
 
1855
- # Flush logs for this policy older than
1856
- # some number of days, weeks, months or years, possibly limited to
1857
- # one or more computers
1914
+ # Flush logs for this policy older than a given time period.
1858
1915
  #
1859
- # With no parameters, flushes all logs for all computers
1916
+ # IMPORTANT: from the Jamf Developer Site:
1917
+ # The ability to flush logs is currently only supported for flushing all logs
1918
+ # for a given policy or all logs for a given computer. There is no support for
1919
+ # flushing logs for a given policy and computer combination.
1920
+ #
1921
+ # With no parameters, will flush all logs for the policy
1860
1922
  #
1861
1923
  # NOTE: Currently the API doesn't have a way to flush only failed policies.
1862
1924
  #
@@ -1868,19 +1930,16 @@ module Jamf
1868
1930
  #
1869
1931
  # @param period[Symbol] :days, :weeks, :months, or :years
1870
1932
  #
1871
- # @param computers[Array<Integer,String>] Identifiers of the target computers
1872
- # either ids, names, SNs, macaddrs, or UDIDs
1873
- #
1874
1933
  # @return [void]
1875
1934
  #
1876
- def flush_logs(older_than: 0, period: :days, computers: [])
1877
- raise Jamf::NoSuchItemError, "Policy doesn't exist in the JSS. Use #create first." unless @in_jss
1935
+ def flush_logs(older_than: 0, period: :days)
1936
+ raise Jamf::NoSuchItemError, "Policy doesn't exist in the JSS. Use #save first." unless @in_jss
1878
1937
 
1879
1938
  Jamf::Policy.flush_logs(
1880
1939
  @id,
1881
1940
  older_than: older_than,
1882
1941
  period: period,
1883
- computers: computers, cnx: @cnx
1942
+ cnx: @cnx
1884
1943
  )
1885
1944
  end
1886
1945
 
@@ -476,7 +476,10 @@ module Jamf
476
476
  item_id = validate_item(:target, key, item)
477
477
  return if @targets[key]&.include?(item_id)
478
478
 
479
- raise Jamf::AlreadyExistsError, "Can't set #{key} target to '#{item}' because it's already an explicit exclusion." if @exclusions[key]&.include?(item_id)
479
+ if @exclusions[key]&.include?(item_id)
480
+ raise Jamf::AlreadyExistsError,
481
+ "Can't set #{key} target to '#{item}' because it's already an explicit exclusion."
482
+ end
480
483
 
481
484
  @targets[key] << item_id
482
485
  @all_targets = false
@@ -775,7 +778,7 @@ module Jamf
775
778
  ################
776
779
  def scoped_machines
777
780
  scoped_machines = {}
778
- @target_class.all_objects(cnx: container.cnx).each do |machine|
781
+ @target_class.all_objects(:refresh, cnx: container.cnx).each do |machine|
779
782
  scoped_machines[machine.id] = machine.name if in_scope? machine
780
783
  end
781
784
  scoped_machines
@@ -19,14 +19,14 @@
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
- #
23
- #
22
+
23
+ # frozen_string_literal: true
24
24
 
25
25
  module Jamf
26
26
 
27
27
  # This module should be mixed in to Jamf::Computer and Jamf::ComputerGroup
28
28
  #
29
- # It provides access to the macos-managed-software-updates JPAPI resource for
29
+ # It provides access to the macos-managed-software-updates JPAPI resource for
30
30
  # managed OS update commands to managed macs running Big Sur or higher.
31
31
  #
32
32
  module MacOSManagedUpdates
@@ -37,7 +37,7 @@ module Jamf
37
37
  includer.extend(ClassMethods)
38
38
  end
39
39
 
40
- # These resources in the Jamf Pro API can be used to send Managed macOS
40
+ # These resources in the Jamf Pro API can be used to send Managed macOS
41
41
  # updates to clients running Big Sur or higher
42
42
  MANAGED_SW_UPDATES_RSRC = 'v1/macos-managed-software-updates'
43
43
 
@@ -45,7 +45,7 @@ module Jamf
45
45
  MANAGED_SW_UPDATES_AVAILABLE_VERSIONS_RSRC = "#{MANAGED_SW_UPDATES_RSRC}/available-updates"
46
46
 
47
47
  # POSTing JSON data to this resource will send the MDM commands to install os updates
48
- # For details about the data to send, see
48
+ # For details about the data to send, see
49
49
  # https://developer.jamf.com/jamf-pro/reference/post_v1-macos-managed-software-updates-send-updates
50
50
  MANAGED_SW_UPDATES_SEND_UPDATES_RSRC = "#{MANAGED_SW_UPDATES_RSRC}/send-updates"
51
51
 
@@ -53,6 +53,12 @@ module Jamf
53
53
  DOWNLOAD_AND_INSTALL = 'DOWNLOAD_AND_INSTALL'
54
54
  DOWNLOAD_ONLY = 'DOWNLOAD_ONLY'
55
55
 
56
+ # for easier use of these values as the updateAction
57
+ UPDATE_ACTIONS = {
58
+ install: DOWNLOAD_AND_INSTALL,
59
+ download: DOWNLOAD_ONLY
60
+ }
61
+
56
62
  # Class Methods
57
63
  #####################################
58
64
  module ClassMethods
@@ -73,48 +79,52 @@ module Jamf
73
79
 
74
80
  # Send the os update command to target Computers or a ComputerGroup
75
81
  #
76
- # @param updateAction [String] Required. 'DOWNLOAD_AND_INSTALL' or 'DOWNLOAD_ONLY'
82
+ # @param updateAction [Symbol] Required. Use :install to send the
83
+ # DOWNLOAD_AND_INSTALL action, or :download to send DOWNLOAD_ONLY
77
84
  #
78
- # @param deviceIds [String, Integer, Array<String, Integer>] Identifiers for the
85
+ # @param deviceIds [String, Integer, Array<String, Integer>] Identifiers for the
79
86
  # computer targets. Required if no groupId is given.
80
87
  #
81
88
  # @param groupId [String, Integer] Identifier for the computer group target.
82
- # Requied if no deviceIDs are given.
89
+ # Requied if no deviceIds are given.
83
90
  #
84
- # @param maxDeferrals [Integer] Allow users to defer the update the provided number
85
- # of times before macOS forces the update. If a value is provided, the Software
86
- # Update will use the InstallLater install action. MaxDeferral is ignored if using the
87
- # DOWNLOAD_ONLY updateAction.
91
+ # @param maxDeferrals [Integer] Allow users to defer the update the provided number
92
+ # of times before macOS forces the update. If a value is provided, the Software
93
+ # Update will use the InstallLater install action. MaxDeferral is ignored if using the
94
+ # :download updateAction.
88
95
  #
89
- # @param version [String] The OS version to install. If no value is provided, the
96
+ # @param version [String] The OS version to install. If no value is provided, the
90
97
  # version will default to latest version based on device eligibility.
91
98
  #
92
99
  # @param skipVersionVerification [Boolean] Should the specified version be installed
93
100
  # even it it isn't applicable to this machine? If no value is provided, will default to false.
94
- # If true, the specified version will be forced to complete DownloadAndInstall
95
- # install action.
101
+ # If true, the specified version will be forced to complete the :install updateAction.
96
102
  #
97
103
  # @param applyMajorUpdate [Boolean] Available only when updating to the latest version
98
104
  # based on device eligibility. Defaults to false. If false the calculated latest version
99
105
  # will only include minor version updates. If a value is provided, the calculated latest
100
106
  # version will include minor and major version updates.
101
107
  #
102
- # @param forceRestart [Boolean] Will default to false. Can only be true if updateAction
103
- # is DOWNLOAD_AND_INSTALLn and the devices the command is sent to are on macOs 11 or higher.
104
- # If true, the DownloadAndInstall action is performed, a restart will be forced.
105
- # MaxDeferral will be ignored if true.
108
+ # @param forceRestart [Boolean] Will default to false. Can only be true if updateAction
109
+ # is :install and the target devices are on macOs 11 or higher.
110
+ # If true, the DownloadAndInstall action is performed, a restart will be forced.
111
+ # MaxDeferral will be ignored if true.
106
112
  #
107
- # @param cnx [Jamf::Connection] The API connection to use. Defaults to Jamf.cnx
113
+ # @param cnx [Jamf::Connection] The API connection to use. Defaults to Jamf.cnx
108
114
  #
109
- # @return [Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse]
115
+ # @return [Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse]
110
116
  ########################
111
117
  def send_managed_os_update(updateAction:, deviceIds: nil, groupId: nil, maxDeferrals: nil, version: nil, skipVersionVerification: false, applyMajorUpdate: false, forceRestart: false, cnx: Jamf.cnx)
112
- if self == Jamf::Computer
118
+ action_to_send = UPDATE_ACTIONS.value?(updateAction) ? updateAction : UPDATE_ACTIONS[updateAction]
119
+
120
+ raise ArgumentError, "Unknown updateAction, must be one of: #{UPDATE_ACTIONS.keys.join ', '}" unless action_to_send
121
+
122
+ if self == Jamf::Computer
113
123
  raise ArgumentError, 'Must provide one or more deviceIds' unless deviceIds
114
124
  elsif self == Jamf::ComputerGroup
115
125
  raise ArgumentError, 'Must provide a groupId' unless groupId
116
126
  else
117
- raise Jamf::UnsupportedError, 'This method is only available for Jamf::Computer and Jamf::ComputerGroup'
127
+ raise Jamf::UnsupportedError, 'This method is only available for Jamf::Computer and Jamf::ComputerGroup'
118
128
  end
119
129
 
120
130
  if version
@@ -124,9 +134,9 @@ module Jamf
124
134
 
125
135
  if deviceIds
126
136
  deviceIds = [deviceIds] unless deviceIds.is_a?(Array)
127
- deviceIds.map! { |id| valid_id id }
137
+ deviceIds.map! { |id| valid_id id, cnx: cnx }
128
138
  end
129
- groupId = valid_id groupId if groupId
139
+ groupId = valid_id(groupId, cnx: cnx) if groupId
130
140
 
131
141
  data = {}
132
142
  # ids in the JPAPI are string containing integers
@@ -137,11 +147,11 @@ module Jamf
137
147
  data[:version] = version if version
138
148
  data[:skipVersionVerification] = skipVersionVerification if skipVersionVerification
139
149
  data[:applyMajorUpdate] = applyMajorUpdate if applyMajorUpdate
140
- data[:updateAction] = updateAction if updateAction
141
- data[:forceRestart] = forceRestart if forceRestart
142
-
150
+ data[:updateAction] = action_to_send
151
+ data[:forceRestart] = forceRestart if forceRestart
152
+
143
153
  payload = Jamf::OAPISchemas::MacOsManagedSoftwareUpdate.new(data).to_json
144
-
154
+
145
155
  result = cnx.jp_post MANAGED_SW_UPDATES_SEND_UPDATES_RSRC, payload
146
156
  Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse.new result
147
157
  end
@@ -161,14 +171,14 @@ module Jamf
161
171
  groupId = is_a?(Jamf::Computer) ? nil : @id
162
172
 
163
173
  self.class.send_managed_os_update(
164
- deviceIds: deviceIds,
165
- groupId: groupId,
166
- maxDeferrals: maxDeferrals,
167
- version: version,
168
- skipVersionVerification: skipVersionVerification,
169
- applyMajorUpdate: applyMajorUpdate,
170
- forceRestart: forceRestart,
171
- updateAction: updateAction,
174
+ deviceIds: deviceIds,
175
+ groupId: groupId,
176
+ maxDeferrals: maxDeferrals,
177
+ version: version,
178
+ skipVersionVerification: skipVersionVerification,
179
+ applyMajorUpdate: applyMajorUpdate,
180
+ forceRestart: forceRestart,
181
+ updateAction: updateAction,
172
182
  cnx: @cnx
173
183
  )
174
184
  end
data/lib/jamf/validate.rb CHANGED
@@ -98,7 +98,9 @@ module Jamf
98
98
  #
99
99
  # @return [Object] the validated unique value
100
100
  #
101
- def self.doesnt_already_exist(klass, identifier, val, msg: nil, api: Jamf.cnx)
101
+ def self.doesnt_already_exist(klass, identifier, val, msg: nil, api: nil, cnx: Jamf.cnx)
102
+ cnx = api if api
103
+
102
104
  return val unless klass.all(:refresh, cnx: cnx).map { |i| i[identifier] }.include? val
103
105
 
104
106
  key = klass.real_lookup_key identifier
data/lib/jamf/version.rb CHANGED
@@ -27,6 +27,6 @@
27
27
  module Jamf
28
28
 
29
29
  ### The version of ruby-jss
30
- VERSION = '2.1.1'.freeze
30
+ VERSION = '3.0.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: 2.1.1
4
+ version: 3.0.0b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Lasell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-11-09 00:00:00.000000000 Z
13
+ date: 2023-04-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: CFPropertyList
@@ -824,9 +824,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
824
824
  version: 2.6.3
825
825
  required_rubygems_version: !ruby/object:Gem::Requirement
826
826
  requirements:
827
- - - ">="
827
+ - - ">"
828
828
  - !ruby/object:Gem::Version
829
- version: '0'
829
+ version: 1.3.1
830
830
  requirements: []
831
831
  rubygems_version: 3.0.3.1
832
832
  signing_key: