Module: Jamf::MacOSManagedUpdates::ClassMethods

Defined in:
lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb

Overview

Class Methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object

when this module is included, also extend our Class Methods



67
68
69
# File 'lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb', line 67

def self.extended(extender)
  Jamf.load_msg "--> #{extender} is extending #{self}"
end

Instance Method Details

#available_os_updates(cnx: Jamf.cnx) ⇒ Array<String>

get the list of available OS versions



75
76
77
78
# File 'lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb', line 75

def available_os_updates(cnx: Jamf.cnx)
  data = cnx.jp_get(MANAGED_SW_UPDATES_AVAILABLE_VERSIONS_RSRC)
  Jamf::OAPISchemas::AvailableUpdates.new(data).availableUpdates
end

#send_managed_os_update(updateAction:, deviceIds: nil, groupId: nil, maxDeferrals: nil, version: nil, skipVersionVerification: false, applyMajorUpdate: false, forceRestart: false, cnx: Jamf.cnx) ⇒ Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse

Send the os update command to target Computers or a ComputerGroup

Raises:

  • (ArgumentError)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb', line 116

def send_managed_os_update(updateAction:, deviceIds: nil, groupId: nil, maxDeferrals: nil, version: nil, skipVersionVerification: false,
                           applyMajorUpdate: false, forceRestart: false, cnx: Jamf.cnx)
  action_to_send = UPDATE_ACTIONS.value?(updateAction) ? updateAction : UPDATE_ACTIONS[updateAction]

  raise ArgumentError, "Unknown updateAction, must be one of: #{UPDATE_ACTIONS.keys.join ', '}" unless action_to_send

  if self == Jamf::Computer
    raise ArgumentError, 'Must provide one or more deviceIds' unless deviceIds
  elsif self == Jamf::ComputerGroup
    raise ArgumentError, 'Must provide a groupId' unless groupId
  else
    raise Jamf::UnsupportedError, 'This method is only available for Jamf::Computer and Jamf::ComputerGroup'
  end

  if version
    available_versions = available_os_updates
    raise ArgumentError, "Invalid version, must be one of: #{available_versions.join ', '}" unless available_versions.include? version
  end

  if deviceIds
    deviceIds = [deviceIds] unless deviceIds.is_a?(Array)
    deviceIds.map! { |id| valid_id id, cnx: cnx }
  end
  groupId = valid_id(groupId, cnx: cnx) if groupId

  data = {}
  # ids in the JPAPI are string containing integers
  data[:deviceIds] = deviceIds.map(&:to_s) if deviceIds
  data[:groupId] = groupId.to_s if groupId

  data[:maxDeferrals] = maxDeferrals if maxDeferrals
  data[:version] = version if version
  data[:skipVersionVerification] = skipVersionVerification if skipVersionVerification
  data[:applyMajorUpdate] = applyMajorUpdate if applyMajorUpdate
  data[:updateAction] = action_to_send
  data[:forceRestart] = forceRestart if forceRestart

  payload = Jamf::OAPISchemas::MacOsManagedSoftwareUpdate.new(data).to_json

  result = cnx.jp_post MANAGED_SW_UPDATES_SEND_UPDATES_RSRC, payload
  Jamf::OAPISchemas::MacOsManagedSoftwareUpdateResponse.new result
end