Module: Jamf::ComputerRecoveryLock::ClassMethods

Defined in:
lib/jamf/api/jamf_pro/mixins/computer_recovery_lock.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



56
57
58
# File 'lib/jamf/api/jamf_pro/mixins/computer_recovery_lock.rb', line 56

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

Instance Method Details

#inventory_data(computer, section: 'GENERAL', cnx: Jamf.cnx) ⇒ Jamf::OAPISchemas::ComputerInventory

Get the JPAPI inventory data for a single computer, either by section or all sections.

Parameters:

  • computer (Symbol, String, Integer, Array<String, Integer>)

    Identifier for the desired Computer

  • section (String) (defaults to: 'GENERAL')

    One of the data sections listed in Jamf::OAPISchemas::ComputerSection::VALUE_OPTIONS or ‘all’. Default is ‘GENERAL’

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    The API connection to use. Defaults to Jamf.cnx

Returns:

Raises:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/jamf/api/jamf_pro/mixins/computer_recovery_lock.rb', line 101

def inventory_data(computer, section: 'GENERAL', cnx: Jamf.cnx)
  # TODO: get this into a constant
  all = 'ALL'

  section = section.to_s.upcase
  id = Jamf::Computer.valid_id computer
  raise Jamf::NoSuchItemError, "No computer matches identifier '#{computer}'" unless id

  data =
    if section == all
      cnx.jp_get "#{Jamf::Computer::JPAPI_INVENTORY_DETAIL_RSRC}/#{id}"
    else
      raise ArgumentError, "Unknown inventory data section '#{section}'" unless Jamf::OAPISchemas::ComputerSection::VALUE_OPTIONS.include?(section)

      cnx.jp_get("#{Jamf::Computer::JPAPI_INVENTORY_RSRC}?section=#{section}&page=0&page-size=1&filter=id%3D%3D#{id}")[:results].first
    end

  Jamf::OAPISchemas::ComputerInventory.new data
end

#management_id(computer, cnx: Jamf.cnx) ⇒ String?

Get the MDM ‘managementID’ of a given computer.

Parameters:

  • computer (Symbol, String, Integer, Array<String, Integer>)

    Identifier for the desired Computer

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    The API connection to use. Defaults to Jamf.cnx

Returns:

  • (String, nil)

    The managementID or nil if not available



130
131
132
# File 'lib/jamf/api/jamf_pro/mixins/computer_recovery_lock.rb', line 130

def management_id(computer, cnx: Jamf.cnx)
  inventory_data(computer, cnx: cnx).general.managementId
end

#recovery_lock_password(computer, cnx: Jamf.cnx) ⇒ String?

Retrieve the recovery lock password for a given computer, if one has been set.

Parameters:

  • computer (Symbol, String, Integer, Array<String, Integer>)

    Identifier for the desired Computer

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    The API connection to use. Defaults to Jamf.cnx

Returns:

  • (String, nil)

    The recovery lock password, or nil if none has been set.



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/jamf/api/jamf_pro/mixins/computer_recovery_lock.rb', line 69

def recovery_lock_password(computer, cnx: Jamf.cnx)
  id = Jamf::Computer.valid_id computer
  raise Jamf::NoSuchItemError, "No computer matches identifier '#{computer}'" unless id

  cnx.jp_get("#{Jamf::Computer::JPAPI_INVENTORY_RSRC}/#{id}/#{RECOVERY_LOCK_PW_RSRC_SUFFIX}").dig :recoveryLockPassword

# if we get a 404 NOT FOUND error, this given computer has no passwd set, so just return nil
rescue Jamf::Connection::JamfProAPIError => e
  raise unless e.http_status == 404

  nil
end