lib/jamf/api/classic/api_objects/mdm.rb in ruby-jss-2.0.0a11 vs lib/jamf/api/classic/api_objects/mdm.rb in ruby-jss-2.0.0b1
- old
+ new
@@ -440,11 +440,11 @@
#
# @param cnx [Jamf::Connection] an API connection to use.
#
# @return [Array<Integer>] The ids of the target devices for a command
#
- def raw_targets_to_ids(targets, expand_groups: true, api: nil, cnx: Jamf.cnx)
+ def raw_targets_to_ids(targets, expand_groups: true, unmanaged_ok: false, api: nil, cnx: Jamf.cnx)
cnx = api if api
targets = targets.is_a?(Array) ? targets : [targets]
# flush caches before checking ids and managment
@@ -452,10 +452,11 @@
# make sure its an array of ids
targets.map! do |md|
id = valid_id md, cnx: cnx
raise Jamf::NoSuchItemError, "No #{self} matches identifier: #{md}" unless id
+
id
end # map!
# expand group members if needed
if expand_groups && GROUP_TARGETS.include?(self::MDM_COMMAND_TARGET)
@@ -463,17 +464,21 @@
targets.each { |group_id| target_ids += fetch(id: group_id).member_ids }
targets = target_ids
end
# make sure all of them are managed, or else the API will raise a 400
- # 'Bad Request' when sending the command to an unmanaged target
- all_mgd = map_all_ids_to(:managed, cnx: cnx).select { |_id, mgd| mgd }.keys
+ # 'Bad Request' when sending the command to an unmanaged target.
+ # Some actions, like flushing MDM commands (see .flush_mdm_commands)
+ # are OK on unmanaged machines, so they will specify 'unmanaged_ok'
+ unless unmanaged_ok
+ all_mgd = map_all_ids_to(:managed, cnx: cnx).select { |_id, mgd| mgd }.keys
- targets.each do |target_id|
- raise Jamf::UnmanagedError, "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd.include? target_id
- end
-
+ targets.each do |target_id|
+ raise Jamf::UnmanagedError, "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd.include? target_id
+ end
+ end # unles
+
targets
end
# Generate the XML to send to the API, sending the MDM command to the targets
#
@@ -533,13 +538,15 @@
command = COMMANDS[command]
case self::MDM_COMMAND_TARGET
when *COMPUTER_TARGETS
return command if COMPUTER_COMMANDS.include? command
+
raise Jamf::UnsupportedError, "'#{command}' cannot be sent to computers or computer groups"
when *DEVICE_TARGETS
return command if DEVICE_COMMANDS.include? command
+
raise Jamf::UnsupportedError, "'#{command}' cannot be sent to mobile devices or mobile device groups"
end
raise Jamf::NoSuchItemError, "'#{command}' is known, but not available for computers or mobile devices. This is a bug. Please report it."
end
@@ -583,10 +590,11 @@
cnx = api if api
case self::MDM_COMMAND_TARGET
when *COMPUTER_TARGETS
raise Jamf::InvalidDataError, 'Locking computers requires a 6-character String passcode' unless passcode.size == 6
+
opts = { passcode: passcode }
when *DEVICE_TARGETS
opts = {}
opts[:lock_message] = message if message
end # case
@@ -611,10 +619,11 @@
cnx = api if api
case self::MDM_COMMAND_TARGET
when *COMPUTER_TARGETS
raise Jamf::InvalidDataError, 'Erasing computers requires a 6-character String passcode' unless passcode.size == 6
+
opts = { passcode: passcode }
when *DEVICE_TARGETS
opts = {}
opts[:preserve_data_plan] = 'true' if preserve_data_plan
end # case
@@ -848,17 +857,21 @@
# @return (see .send_mdm_command)
#
def wallpaper(targets, wallpaper_setting: nil, wallpaper_content: nil, wallpaper_id: nil, api: nil, cnx: Jamf.cnx)
cnx = api if api
- raise ArgumentError, "wallpaper_setting must be one of: :#{WALLPAPER_LOCATIONS.keys.join ', :'}" unless WALLPAPER_LOCATIONS.keys.include? wallpaper_setting
+ unless WALLPAPER_LOCATIONS.keys.include? wallpaper_setting
+ raise ArgumentError,
+ "wallpaper_setting must be one of: :#{WALLPAPER_LOCATIONS.keys.join ', :'}"
+ end
opts = { wallpaper_setting: WALLPAPER_LOCATIONS[wallpaper_setting] }
if wallpaper_content
file = Pathname.new wallpaper_content
raise Jamf::NoSuchItemError, "Not a file: #{file}" unless file.file?
+
opts[:wallpaper_content] = Base64.encode64 file.read
elsif wallpaper_id
opts[:wallpaper_id] = wallpaper_id
else
raise ArgumentError, 'Either wallpaper_id: or wallpaper_content must be provided'
@@ -991,22 +1004,23 @@
# @param cnx [Jamf::Connection] the API thru which to send the command
#
# @return (see .send_mdm_command)
#
def enable_lost_mode(
- targets,
- message: nil,
- phone: nil,
- footnote: nil,
- play_sound: false,
- enforce_lost_mode: true,
- api: nil,
- cnx: Jamf.cnx
- )
+ targets,
+ message: nil,
+ phone: nil,
+ footnote: nil,
+ play_sound: false,
+ enforce_lost_mode: true,
+ api: nil,
+ cnx: Jamf.cnx
+ )
cnx = api if api
raise ArgumentError, 'Either message: or phone_number: must be provided' unless message || phone
+
opts = { always_enforce_lost_mode: enforce_lost_mode }
opts[:lost_mode_message] = message if message
opts[:lost_mode_phone] = phone if phone
opts[:lost_mode_footnote] = footnote if footnote
opts[:lost_mode_with_sound] = 'true' if play_sound
@@ -1065,11 +1079,13 @@
raise Jamf::InvalidDataError, "Status must be one of :#{FLUSHABLE_STATUSES.keys.join ', :'}" unless FLUSHABLE_STATUSES.keys.include? status
status = FLUSHABLE_STATUSES[status]
- target_ids = raw_targets_to_ids targets, cnx: cnx, expand_groups: false
+ # TODO: add 'unmanaged_ok:' param to raw_targets_to_ids method, so that we can
+ # use this to flush commands for unmanaged machines.
+ target_ids = raw_targets_to_ids targets, cnx: cnx, expand_groups: false, unmanaged_ok: true
command_flush_rsrc = "commandflush/#{self::MDM_COMMAND_TARGET}/id"
flush_rsrc = "#{command_flush_rsrc}/#{target_ids.join ','}/status/#{status}"
@@ -1365,14 +1381,14 @@
# @param enforce_lost_mode[Boolean] Re-enabled lost mode when re-enrolled after wipe.
#
# @return (see .send_mdm_command)
#
def enable_lost_mode(
- message: nil,
- phone_number: nil,
- footnote: nil,
- enforce_lost_mode: true,
- play_sound: false
+ message: nil,
+ phone_number: nil,
+ footnote: nil,
+ enforce_lost_mode: true,
+ play_sound: false
)
self.class.enable_lost_mode(
@id,
message: message,
phone_number: phone_number,