Class: Jamf::PatchSource
- Includes:
- Updatable
- Defined in:
- lib/jamf/api/classic/base_classes/patch_source.rb
Overview
A patch source. The abstract parent class of PatchInternalSource and PatchExternalSource
Direct Known Subclasses
Constant Summary collapse
- HTTP =
'http'.freeze
- HTTPS =
'https'.freeze
- DFT_ENABLED =
false
- DFT_SSL =
true
- DFT_SSL_PORT =
443
- DFT_NO_SSL_PORT =
80
- AVAILABLE_TITLES_RSRC =
'patchavailabletitles/sourceid/'.freeze
- 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
{ patch_available_titles: { available_titles: [ { name_id: Jamf::BLANK, current_version: Jamf::BLANK, publisher: Jamf::BLANK, last_modified: Jamf::BLANK, app_name: Jamf::BLANK } ] } }.freeze
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
(also: #enabled?)
readonly
Is this source enabled?.
-
#endpoint ⇒ String
(also: #url)
readonly
The URL from which patch info is retrieved.
-
#host_name ⇒ String
(also: #hostname, #host)
readonly
The host name of the patch source.
-
#need_to_update ⇒ Boolean
included
from Updatable
readonly
Do we have unsaved changes?.
-
#port ⇒ Integer
readonly
The TCP port of the patch source.
-
#ssl_enabled ⇒ Boolean
(also: #ssl_enabled?)
readonly
Is SSL enabled for the patch source?.
Class Method Summary collapse
-
.all(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Array<Hash{:name=>String, :id=> Integer, :type => Symbol}>
Get names, ids and types for all patch sources.
-
.all_external(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Object
Get names, ids for all patch internal sources.
-
.all_internal(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Object
Get names, ids for all patch internal sources.
- .all_objects(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Object
-
.available_name_ids(source, api: nil, cnx: Jamf.cnx) ⇒ Array<String>
FOr a given patch source, an array of available 'name_id's which are uniq identifiers for titles available on that source.
-
.available_titles(source, api: nil, cnx: Jamf.cnx) ⇒ Array<Hash{Symbol:String}>
Get a list of patch titles available from a Patch Source (either internal or external, since they have unique ids ).
-
.create(**args) ⇒ Object
Only Jamf::PatchExternalSources can be created.
-
.delete(victims, api: nil, cnx: Jamf.cnx) ⇒ Object
Only Jamf::PatchExternalSources can be deleted.
-
.fetch(searchterm = nil, **args) ⇒ Object
Fetch either an internal or external patch source.
-
.make(**args) ⇒ Object
bacward compatibility.
-
.valid_patch_source_id(ident, refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Integer?
Given a name or id for a Patch Source (internal or external) return the id if it exists, or nil if it doesn't.
-
.valid_patch_source_type(ident, refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Symbol?
Given a name or id for a Patch Source return :internal or :external if it exists, or nil if it doesnt.
Instance Method Summary collapse
-
#available_name_ids ⇒ Object
Get a list of available name_id's for this patch source.
-
#available_titles ⇒ Object
Get a list of patch titles available from this Patch Source.
-
#delete ⇒ Object
Delete this instance This method is needed to override APIObject#delete.
-
#initialize(**args) ⇒ PatchSource
constructor
Init.
-
#name=(newname) ⇒ void
included
from Updatable
Change the name of this item Remember to #update to push changes to the server.
Constructor Details
#initialize(**args) ⇒ PatchSource
Init
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 326 def initialize(**args) raise Jamf::UnsupportedError, 'PatchSource is an abstract metaclass. Please use PatchInternalSource or PatchExternalSource' if self.class == Jamf::PatchSource super @enabled = @init_data[:enabled].to_s.jss_to_bool @enabled ||= false # derive the data not provided for this source type if @init_data[:endpoint] @endpoint = @init_data[:endpoint] url = URI.parse endpoint @host_name = url.host @port = url.port @ssl_enabled = url.scheme == HTTPS else @host_name = @init_data[:host_name] @port = @init_data[:port].to_i @port ||= ssl_enabled? ? DFT_SSL_PORT : DFT_NO_SSL_PORT @ssl_enabled = @init_data[:ssl_enabled].to_s.jss_to_bool @ssl_enabled ||= false @endpoint = "#{ssl_enabled ? HTTPS : HTTP}://#{host_name}:#{port}/" end end |
Instance Attribute Details
#enabled ⇒ Boolean (readonly) Also known as: enabled?
Returns Is this source enabled?.
302 303 304 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 302 def enabled @enabled end |
#endpoint ⇒ String (readonly) Also known as: url
Returns The URL from which patch info is retrieved.
306 307 308 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 306 def endpoint @endpoint end |
#host_name ⇒ String (readonly) Also known as: hostname, host
Returns The host name of the patch source.
312 313 314 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 312 def host_name @host_name end |
#need_to_update ⇒ Boolean (readonly) Originally defined in module Updatable
Returns do we have unsaved changes?.
#port ⇒ Integer (readonly)
Returns the TCP port of the patch source.
319 320 321 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 319 def port @port end |
#ssl_enabled ⇒ Boolean (readonly) Also known as: ssl_enabled?
Returns Is SSL enabled for the patch source?.
322 323 324 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 322 def ssl_enabled @ssl_enabled end |
Class Method Details
.all(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Array<Hash{:name=>String, :id=> Integer, :type => Symbol}>
Get names, ids and types for all patch sources
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 81 def self.all(refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api if self == Jamf::PatchSource int = Jamf::PatchInternalSource.all(refresh, cnx: cnx).each { |s| s[:type] = :internal } ext = Jamf::PatchExternalSource.all(refresh, cnx: cnx).each { |s| s[:type] = :external } return (int + ext).sort! { |s1, s2| s1[:id] <=> s2[:id] } end super end |
.all_external(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Object
Get names, ids for all patch internal sources
the same as Jamf::PatchExternalSource.all refresh, cnx: cnx
@see Jamf::PatchExternalSource.all
110 111 112 113 114 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 110 def self.all_external(refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api Jamf::PatchExternalSource.all refresh, cnx: cnx end |
.all_internal(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Object
Get names, ids for all patch internal sources
the same as Jamf::PatchInternalSource.all refresh, cnx: cnx
98 99 100 101 102 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 98 def self.all_internal(refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api Jamf::PatchInternalSource.all refresh, cnx: cnx end |
.all_objects(refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 118 def self.all_objects(refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api if self == Jamf::PatchSource int = Jamf::PatchInternalSource.all_objects refresh, cnx: cnx ext = Jamf::PatchExternalSource.all_objects refresh, cnx: cnx return (int + ext).sort! { |s1, s2| s1.id <=> s2.id } end super end |
.available_name_ids(source, api: nil, cnx: Jamf.cnx) ⇒ Array<String>
FOr a given patch source, an array of available 'name_id's which are uniq identifiers for titles available on that source.
248 249 250 251 252 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 248 def self.available_name_ids(source, api: nil, cnx: Jamf.cnx) cnx = api if api available_titles(source, cnx: cnx).map { |t| t[:name_id] } end |
.available_titles(source, api: nil, cnx: Jamf.cnx) ⇒ Array<Hash{Symbol:String}>
Get a list of patch titles available from a Patch Source (either internal or external, since they have unique ids )
get the available titles
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 214 def self.available_titles(source, api: nil, cnx: Jamf.cnx) cnx = api if api src_id = valid_patch_source_id source, cnx: cnx raise Jamf::NoSuchItemError, "No Patch Source found matching: #{source}" unless src_id rsrc_base = if valid_patch_source_type(src_id, cnx: cnx) == :internal Jamf::PatchInternalSource::AVAILABLE_TITLES_RSRC else Jamf::PatchExternalSource::AVAILABLE_TITLES_RSRC end rsrc = "#{rsrc_base}#{src_id}" begin # TODO: remove this and adjust parsing when jamf fixes the JSON raw = Jamf::XMLWorkaround.data_via_xml(rsrc, AVAILABLE_TITLES_DATA_MAP, cnx) rescue Jamf::NoSuchItemError return [] end titles = raw[:patch_available_titles][:available_titles] titles.each { |t| t[:last_modified] = Jamf.parse_time t[:last_modified] } titles end |
.create(**args) ⇒ Object
Only Jamf::PatchExternalSources can be created
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 164 def self.create(**args) case self.name when 'Jamf::PatchSource' Jamf::PatchExternalSource.make args when 'Jamf::PatchExternalSource' super when 'Jamf::PatchInternalSource' raise Jamf::UnsupportedError, 'PatchInteralSources cannot be created.' end end |
.delete(victims, api: nil, cnx: Jamf.cnx) ⇒ Object
Only Jamf::PatchExternalSources can be deleted
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 184 def self.delete(victims, api: nil, cnx: Jamf.cnx) cnx = api if api case self.name when 'Jamf::PatchSource' Jamf::PatchExternalSource victims, cnx: cnx when 'Jamf::PatchExternalSource' super when 'Jamf::PatchInternalSource' raise Jamf::UnsupportedError, 'PatchInteralSources cannot be deleted.' end end |
.fetch(searchterm = nil, **args) ⇒ Object
Fetch either an internal or external patch source
BUG: there's an API bug: fetching a non-existent which is why we rescue internal server errors.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 136 def self.fetch(searchterm = nil, **args) if self == Jamf::PatchSource begin fetched = Jamf::PatchInternalSource.fetch searchterm, **args rescue fetched = nil end unless fetched begin fetched = Jamf::PatchExternalSource.fetch searchterm, **args rescue raise Jamf::NoSuchItemError, 'No matching PatchSource found' end end return fetched end # if self == Jamf::PatchSource begin super searchterm, **args rescue Jamf::NoSuchItemError raise Jamf::NoSuchItemError, "No matching #{self::RSRC_OBJECT_KEY} found" end end |
.make(**args) ⇒ Object
bacward compatibility
176 177 178 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 176 def self.make(**args) create(**args) end |
.valid_patch_source_id(ident, refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Integer?
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.
270 271 272 273 274 275 276 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 270 def self.valid_patch_source_id(ident, refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api id = Jamf::PatchInternalSource.valid_id ident, refresh, cnx: cnx id ||= Jamf::PatchExternalSource.valid_id ident, refresh, cnx: cnx id end |
.valid_patch_source_type(ident, refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Symbol?
Given a name or id for a Patch Source return :internal or :external if it exists, or nil if it doesnt.
290 291 292 293 294 295 296 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 290 def self.valid_patch_source_type(ident, refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api return :internel if Jamf::PatchInternalSource.valid_id ident, refresh, cnx: cnx return :external if Jamf::PatchExternalSource.valid_id ident, refresh, cnx: cnx nil end |
Instance Method Details
#available_name_ids ⇒ Object
Get a list of available name_id's for this patch source
361 362 363 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 361 def available_name_ids self.class.available_name_ids id, cnx: cnx end |
#available_titles ⇒ Object
Get a list of patch titles available from this Patch Source
354 355 356 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 354 def available_titles self.class.available_titles id, cnx: cnx end |
#delete ⇒ Object
Delete this instance This method is needed to override APIObject#delete
367 368 369 370 371 372 373 374 |
# File 'lib/jamf/api/classic/base_classes/patch_source.rb', line 367 def delete case self.class.name when 'Jamf::PatchExternalSource' super when 'Jamf::PatchInternalSource' raise Jamf::UnsupportedError, 'PatchInteralSources cannot be deleted.' end end |
#name=(newname) ⇒ void Originally defined in module Updatable
This method returns an undefined value.
Change the name of this item Remember to #update to push changes to the server.