class Jamf::PatchSource

A patch source. The abstract parent class of {Jamf::PatchInternalSource} and {Jamf::PatchExternalSource}

@see Jamf::APIObject

Constants

AVAILABLE_TITLES_DATA_MAP

TODO: remove this and adjust parsing when jamf fixes the JSON Data map for PatchReport XML data parsing cuz Borked JSON @see {Jamf::XMLWorkaround} for details

AVAILABLE_TITLES_RSRC
DFT_ENABLED
DFT_NO_SSL_PORT
DFT_SSL
DFT_SSL_PORT
HTTP
HTTPS

Attributes

enabled[R]

@return [Boolean] Is this source enabled?

enabled?[R]

@return [Boolean] Is this source enabled?

endpoint[R]

@return [String] The URL from which patch info is retrieved

host[R]

@param newname [String] The new host name (external sources only)

@return [String] The host name of the patch source

host_name[R]

@param newname [String] The new host name (external sources only)

@return [String] The host name of the patch source

hostname[R]

@param newname [String] The new host name (external sources only)

@return [String] The host name of the patch source

port[R]

@param new_port [Integer] The new port (external sources only)

@return [Integer] the TCP port of the patch source

ssl_enabled[R]

@return [Boolean] Is SSL enabled for the patch source?

ssl_enabled?[R]

@return [Boolean] Is SSL enabled for the patch source?

url[R]

@return [String] The URL from which patch info is retrieved

Public Class Methods

all(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

Get names, ids and types for all patch sources

@param refresh should the data be re-queried from the API?

@param cnx [Jamf::Connection] an API connection to use for the query.

Defaults to the corrently active API. See {Jamf::Connection}

@return [Array<Hash{:name=>String, :id=> Integer, :type => Symbol}>]

Calls superclass method Jamf::APIObject::all
   # File lib/jamf/api/classic/base_classes/patch_source.rb
81 def self.all(refresh = false, api: nil, cnx: Jamf.cnx)
82   cnx = api if api
83 
84   if self == Jamf::PatchSource
85     int = Jamf::PatchInternalSource.all(refresh, cnx: cnx).each { |s| s[:type] = :internal }
86     ext = Jamf::PatchExternalSource.all(refresh, cnx: cnx).each { |s| s[:type] = :external }
87     return (int + ext).sort! { |s1, s2| s1[:id] <=> s2[:id] }
88   end
89   super
90 end
all_external(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

Get names, ids for all patch internal sources

the same as Jamf::PatchExternalSource.all refresh, cnx: cnx

@see  Jamf::PatchExternalSource.all
    # File lib/jamf/api/classic/base_classes/patch_source.rb
110 def self.all_external(refresh = false, api: nil, cnx: Jamf.cnx)
111   cnx = api if api
112 
113   Jamf::PatchExternalSource.all refresh, cnx: cnx
114 end
all_internal(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

Get names, ids for all patch internal sources

the same as Jamf::PatchInternalSource.all refresh, cnx: cnx

@see Jamf::PatchInternalSource.all

    # File lib/jamf/api/classic/base_classes/patch_source.rb
 98 def self.all_internal(refresh = false, api: nil, cnx: Jamf.cnx)
 99   cnx = api if api
100 
101   Jamf::PatchInternalSource.all refresh, cnx: cnx
102 end
all_objects(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@see Jamf::APIObject.all_objects

Calls superclass method Jamf::APIObject::all_objects
    # File lib/jamf/api/classic/base_classes/patch_source.rb
118 def self.all_objects(refresh = false, api: nil, cnx: Jamf.cnx)
119   cnx = api if api
120 
121   if self == Jamf::PatchSource
122     int = Jamf::PatchInternalSource.all_objects refresh, cnx: cnx
123     ext = Jamf::PatchExternalSource.all_objects refresh, cnx: cnx
124     return (int + ext).sort! { |s1, s2| s1.id <=> s2.id }
125   end
126   super
127 end
available_name_ids(source, api: nil, cnx: Jamf.cnx) click to toggle source

FOr a given patch source, an array of available ‘name_id’s which are uniq identifiers for titles available on that source.

@see available_titles

@return [Array<String>] the name_ids available on the source

    # File lib/jamf/api/classic/base_classes/patch_source.rb
249 def self.available_name_ids(source, api: nil, cnx: Jamf.cnx)
250   cnx = api if api
251   available_titles(source, cnx: cnx).map { |t| t[:name_id] }
252 end
available_titles(source, api: nil, cnx: Jamf.cnx) click to toggle source

Get a list of patch titles available from a Patch Source (either internal or external, since they have unique ids )

@param source name or id of the Patch Source for which to get the available titles

@param cnx [Jamf::Connection] The api connection to use for the query

Defaults to the currently active connection

@return [Array<Hash{Symbol:String}>] One hash for each available title, with

these keys:
  :name_id String
  :current_version String
  :publisher String
  :last_modified Time
  :app_name  String
    # File lib/jamf/api/classic/base_classes/patch_source.rb
215 def self.available_titles(source, api: nil, cnx: Jamf.cnx)
216   cnx = api if api
217 
218   src_id = valid_patch_source_id source, cnx: cnx
219   raise Jamf::NoSuchItemError, "No Patch Source found matching: #{source}" unless src_id
220 
221   rsrc_base =
222     if valid_patch_source_type(src_id, cnx: cnx) == :internal
223       Jamf::PatchInternalSource::AVAILABLE_TITLES_RSRC
224     else
225       Jamf::PatchExternalSource::AVAILABLE_TITLES_RSRC
226     end
227 
228   rsrc = "#{rsrc_base}#{src_id}"
229 
230   begin
231     # TODO: remove this and adjust parsing when jamf fixes the JSON
232     raw = Jamf::XMLWorkaround.data_via_xml(rsrc, AVAILABLE_TITLES_DATA_MAP, cnx)
233   rescue Jamf::NoSuchItemError
234     return []
235   end
236 
237   titles = raw[:patch_available_titles][:available_titles]
238   titles.each { |t| t[:last_modified] = Jamf.parse_time t[:last_modified] }
239   titles
240 end
create(**args) click to toggle source

Only Jamf::PatchExternalSources can be created

@see APIObject.make

Calls superclass method Jamf::APIObject::create
    # File lib/jamf/api/classic/base_classes/patch_source.rb
165 def self.create(**args)
166   case name
167   when 'Jamf::PatchSource'
168     Jamf::PatchExternalSource.make args
169   when 'Jamf::PatchExternalSource'
170     super
171   when 'Jamf::PatchInternalSource'
172     raise Jamf::UnsupportedError, 'PatchInteralSources cannot be created.'
173   end
174 end
delete(victims, api: nil, cnx: Jamf.cnx) click to toggle source

Only Jamf::PatchExternalSources can be deleted

@see APIObject.delete

Calls superclass method Jamf::APIObject::delete
    # File lib/jamf/api/classic/base_classes/patch_source.rb
185 def self.delete(victims, api: nil, cnx: Jamf.cnx)
186   cnx = api if api
187 
188   case name
189   when 'Jamf::PatchSource'
190     Jamf::PatchExternalSource victims, cnx: cnx
191   when 'Jamf::PatchExternalSource'
192     super
193   when 'Jamf::PatchInternalSource'
194     raise Jamf::UnsupportedError, 'PatchInteralSources cannot be deleted.'
195   end
196 end
fetch(searchterm = nil, **args) click to toggle source

Fetch either an internal or external patch source

BUG: there’s an API bug when fetching a non-existent patch source which is why we rescue 500 internal server errors and report them as ‘no matching patch source’

@see APIObject.fetch

Calls superclass method Jamf::APIObject::fetch
    # File lib/jamf/api/classic/base_classes/patch_source.rb
137 def self.fetch(searchterm = nil, **args)
138   if self == Jamf::PatchSource
139     begin
140       fetched = Jamf::PatchInternalSource.fetch searchterm, **args
141     rescue
142       fetched = nil
143     end
144     unless fetched
145       begin
146         fetched = Jamf::PatchExternalSource.fetch searchterm, **args
147       rescue
148         raise Jamf::NoSuchItemError, 'No matching PatchSource found'
149       end
150     end
151     return fetched
152   end # if self == Jamf::PatchSource
153 
154   begin
155     super searchterm, **args
156   rescue Jamf::NoSuchItemError
157     raise Jamf::NoSuchItemError, "No matching #{self::RSRC_OBJECT_KEY} found"
158   end
159 end
make(**args) click to toggle source

bacward compatibility

    # File lib/jamf/api/classic/base_classes/patch_source.rb
177 def self.make(**args)
178   create(**args)
179 end
new(**args) click to toggle source

Init

Calls superclass method Jamf::APIObject::new
    # File lib/jamf/api/classic/base_classes/patch_source.rb
326 def initialize(**args)
327   if instance_of?(Jamf::PatchSource)
328     raise Jamf::UnsupportedError,
329           'PatchSource is an abstract metaclass. Please use PatchInternalSource or PatchExternalSource'
330   end
331 
332   super
333 
334   @enabled = @init_data[:enabled].to_s.jss_to_bool
335   @enabled ||= false
336 
337   # derive the data not provided for this source type
338   if @init_data[:endpoint]
339     @endpoint = @init_data[:endpoint]
340     url = URI.parse endpoint
341     @host_name = url.host
342     @port = url.port
343     @ssl_enabled = url.scheme == HTTPS
344   else
345     @host_name = @init_data[:host_name]
346     @port = @init_data[:port].to_i
347     @port ||= ssl_enabled? ? DFT_SSL_PORT : DFT_NO_SSL_PORT
348     @ssl_enabled = @init_data[:ssl_enabled].to_s.jss_to_bool
349     @ssl_enabled ||= false
350     @endpoint = "#{ssl_enabled ? HTTPS : HTTP}://#{host_name}:#{port}/"
351   end
352 end
valid_patch_source_id(ident, refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

Given a name or id for a Patch Source (internal or external) return the id if it exists, or nil if it doesn’t.

NOTE: does not indicate which kind of source it is, just that it exists and can be used as a source_id for a patch title. @see .valid_patch_source_type

@param ident the name or id to validate

@param refresh [Boolean] Should the data be re-read from the server

@param cnx [Jamf::Connection] an API connection to use for the query.

Defaults to the corrently active API. See {Jamf::Connection}

@return [Integer, nil] the valid id or nil if it doesn’t exist.

    # File lib/jamf/api/classic/base_classes/patch_source.rb
270 def self.valid_patch_source_id(ident, refresh = false, api: nil, cnx: Jamf.cnx)
271   cnx = api if api
272   id = Jamf::PatchInternalSource.valid_id ident, refresh, cnx: cnx
273   id ||= Jamf::PatchExternalSource.valid_id ident, refresh, cnx: cnx
274   id
275 end
valid_patch_source_type(ident, refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

Given a name or id for a Patch Source return :internal or :external if it exists, or nil if it doesnt.

@param ident the name or id to validate

@param refresh [Boolean] Should the data be re-read from the server

@param cnx [Jamf::Connection] an API connection to use for the query.

Defaults to the corrently active API. See {Jamf::Connection}

@return [Symbol, nil] :internal, :external, or nil if it doesn’t exist.

    # File lib/jamf/api/classic/base_classes/patch_source.rb
289 def self.valid_patch_source_type(ident, refresh = false, api: nil, cnx: Jamf.cnx)
290   cnx = api if api
291 
292   return :internel if Jamf::PatchInternalSource.valid_id ident, refresh, cnx: cnx
293   return :external if Jamf::PatchExternalSource.valid_id ident, refresh, cnx: cnx
294 
295   nil
296 end

Public Instance Methods

available_name_ids() click to toggle source

Get a list of available name_id’s for this patch source @see Jamf::PatchSource.available_name_ids

    # File lib/jamf/api/classic/base_classes/patch_source.rb
364 def available_name_ids
365   self.class.available_name_ids id, cnx: cnx
366 end
available_titles() click to toggle source

Get a list of patch titles available from this Patch Source @see Jamf::PatchSource.available_titles

    # File lib/jamf/api/classic/base_classes/patch_source.rb
357 def available_titles
358   self.class.available_titles id, cnx: cnx
359 end
delete() click to toggle source

Delete this instance This method is needed to override APIObject#delete

Calls superclass method Jamf::APIObject::delete
    # File lib/jamf/api/classic/base_classes/patch_source.rb
370 def delete
371   case self.class.name
372   when 'Jamf::PatchExternalSource'
373     super
374   when 'Jamf::PatchInternalSource'
375     raise Jamf::UnsupportedError, 'PatchInteralSources cannot be deleted.'
376   end
377 end