Class: JSS::PatchSource
- Includes:
- Updatable
- Defined in:
- lib/jss/api_object/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: JSS::BLANK, current_version: JSS::BLANK, publisher: JSS::BLANK, last_modified: JSS::BLANK, app_name: JSS::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: JSS.api) ⇒ Array<Hash{:name=>String, :id=> Integer, :type => Symbol}>
Get names, ids and types for all patch sources.
-
.all_external(refresh = false, api: JSS.api) ⇒ Object
Get names, ids for all patch internal sources.
-
.all_internal(refresh = false, api: JSS.api) ⇒ Object
Get names, ids for all patch internal sources.
- .all_objects(refresh = false, api: JSS.api) ⇒ Object
-
.available_name_ids(source, api: JSS.api) ⇒ 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: JSS.api) ⇒ Array<Hash{Symbol:String}>
Get a list of patch titles available from a Patch Source (either internal or external, since they have unique ids ).
-
.delete(victims, api: JSS.api) ⇒ Object
Only JSS::PatchExternalSources can be deleted.
-
.fetch(searchterm = nil, **args) ⇒ Object
Fetch either an internal or external patch source.
-
.make(**args) ⇒ Object
Only JSS::PatchExternalSources can be created.
-
.valid_patch_source_id(ident, refresh = false, api: JSS.api) ⇒ 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: JSS.api) ⇒ 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.
-
#update ⇒ Boolean
included
from Updatable
Save changes to the JSS.
Constructor Details
#initialize(**args) ⇒ PatchSource
Init
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/jss/api_object/patch_source.rb', line 303 def initialize(**args) raise JSS::UnsupportedError, 'PatchSource is an abstract metaclass. Please use PatchInternalSource or PatchExternalSource' if self.class == JSS::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?.
279 280 281 |
# File 'lib/jss/api_object/patch_source.rb', line 279 def enabled @enabled end |
#endpoint ⇒ String (readonly) Also known as: url
Returns The URL from which patch info is retrieved.
283 284 285 |
# File 'lib/jss/api_object/patch_source.rb', line 283 def endpoint @endpoint end |
#host_name ⇒ String (readonly) Also known as: hostname, host
Returns The host name of the patch source.
289 290 291 |
# File 'lib/jss/api_object/patch_source.rb', line 289 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.
296 297 298 |
# File 'lib/jss/api_object/patch_source.rb', line 296 def port @port end |
#ssl_enabled ⇒ Boolean (readonly) Also known as: ssl_enabled?
Returns Is SSL enabled for the patch source?.
299 300 301 |
# File 'lib/jss/api_object/patch_source.rb', line 299 def ssl_enabled @ssl_enabled end |
Class Method Details
.all(refresh = false, api: JSS.api) ⇒ 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 |
# File 'lib/jss/api_object/patch_source.rb', line 81 def self.all(refresh = false, api: JSS.api) if self == JSS::PatchSource int = JSS::PatchInternalSource.all(refresh, api: api).each { |s| s[:type] = :internal } ext = JSS::PatchExternalSource.all(refresh, api: api).each { |s| s[:type] = :external } return (int + ext).sort! { |s1, s2| s1[:id] <=> s2[:id] } end super end |
.all_external(refresh = false, api: JSS.api) ⇒ Object
Get names, ids for all patch internal sources
the same as JSS::PatchExternalSource.all refresh, api: api
@see JSS::PatchExternalSource.all
106 107 108 |
# File 'lib/jss/api_object/patch_source.rb', line 106 def self.all_external(refresh = false, api: JSS.api) JSS::PatchExternalSource.all refresh, api: api end |
.all_internal(refresh = false, api: JSS.api) ⇒ Object
Get names, ids for all patch internal sources
the same as JSS::PatchInternalSource.all refresh, api: api
96 97 98 |
# File 'lib/jss/api_object/patch_source.rb', line 96 def self.all_internal(refresh = false, api: JSS.api) JSS::PatchInternalSource.all refresh, api: api end |
.all_objects(refresh = false, api: JSS.api) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/jss/api_object/patch_source.rb', line 112 def self.all_objects(refresh = false, api: JSS.api) if self == JSS::PatchSource int = JSS::PatchInternalSource.all_objects refresh, api: api ext = JSS::PatchExternalSource.all_objects refresh, api: api return (int + ext).sort! { |s1, s2| s1.id <=> s2.id } end super end |
.available_name_ids(source, api: JSS.api) ⇒ Array<String>
FOr a given patch source, an array of available 'name_id's which are uniq identifiers for titles available on that source.
231 232 233 |
# File 'lib/jss/api_object/patch_source.rb', line 231 def self.available_name_ids(source, api: JSS.api) available_titles(source, api: api).map { |t| t[:name_id] } end |
.available_titles(source, api: JSS.api) ⇒ 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
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/jss/api_object/patch_source.rb', line 199 def self.available_titles(source, api: JSS.api) src_id = valid_patch_source_id source, api: api raise JSS::NoSuchItemError, "No Patch Source found matching: #{source}" unless src_id rsrc_base = if valid_patch_source_type(src_id, api: api) == :internal JSS::PatchInternalSource::AVAILABLE_TITLES_RSRC else JSS::PatchExternalSource::AVAILABLE_TITLES_RSRC end rsrc = "#{rsrc_base}#{src_id}" begin # TODO: remove this and adjust parsing when jamf fixes the JSON raw = JSS::XMLWorkaround.data_via_xml(rsrc, AVAILABLE_TITLES_DATA_MAP, api) rescue JSS::NoSuchItemError return [] end titles = raw[:patch_available_titles][:available_titles] titles.each { |t| t[:last_modified] = Time.parse t[:last_modified] } titles end |
.delete(victims, api: JSS.api) ⇒ Object
Only JSS::PatchExternalSources can be deleted
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/jss/api_object/patch_source.rb', line 171 def self.delete(victims, api: JSS.api) case self.name when 'JSS::PatchSource' JSS::PatchExternalSource victims, api: api when 'JSS::PatchExternalSource' super when 'JSS::PatchInternalSource' raise JSS::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.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/jss/api_object/patch_source.rb', line 128 def self.fetch(searchterm = nil, **args) if self == JSS::PatchSource begin fetched = JSS::PatchInternalSource.fetch searchterm, **args rescue fetched = nil end unless fetched begin fetched = JSS::PatchExternalSource.fetch searchterm, **args rescue raise JSS::NoSuchItemError, 'No matching PatchSource found' end end return fetched end # if self == JSS::PatchSource begin super searchterm, **args rescue JSS::NoSuchItemError raise JSS::NoSuchItemError, "No matching #{self::RSRC_OBJECT_KEY} found" end end |
.make(**args) ⇒ Object
Only JSS::PatchExternalSources can be created
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/jss/api_object/patch_source.rb', line 156 def self.make(**args) case self.name when 'JSS::PatchSource' JSS::PatchExternalSource.make args when 'JSS::PatchExternalSource' super when 'JSS::PatchInternalSource' raise JSS::UnsupportedError, 'PatchInteralSources cannot be created.' end end |
.valid_patch_source_id(ident, refresh = false, api: JSS.api) ⇒ 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.
251 252 253 254 255 |
# File 'lib/jss/api_object/patch_source.rb', line 251 def self.valid_patch_source_id(ident, refresh = false, api: JSS.api) id = JSS::PatchInternalSource.valid_id ident, refresh, api: api id ||= JSS::PatchExternalSource.valid_id ident, refresh, api: api id end |
.valid_patch_source_type(ident, refresh = false, api: JSS.api) ⇒ Symbol?
Given a name or id for a Patch Source return :internal or :external if it exists, or nil if it doesnt.
269 270 271 272 273 |
# File 'lib/jss/api_object/patch_source.rb', line 269 def self.valid_patch_source_type(ident, refresh = false, api: JSS.api) return :internel if JSS::PatchInternalSource.valid_id ident, refresh, api: api return :external if JSS::PatchExternalSource.valid_id ident, refresh, api: api nil end |
Instance Method Details
#available_name_ids ⇒ Object
Get a list of available name_id's for this patch source
338 339 340 |
# File 'lib/jss/api_object/patch_source.rb', line 338 def available_name_ids self.class.available_name_ids id, api: api end |
#available_titles ⇒ Object
Get a list of patch titles available from this Patch Source
331 332 333 |
# File 'lib/jss/api_object/patch_source.rb', line 331 def available_titles self.class.available_titles id, api: api end |
#delete ⇒ Object
Delete this instance This method is needed to override APIObject#delete
344 345 346 347 348 349 350 351 |
# File 'lib/jss/api_object/patch_source.rb', line 344 def delete case self.class.name when 'JSS::PatchExternalSource' super when 'JSS::PatchInternalSource' raise JSS::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.
#update ⇒ Boolean Originally defined in module Updatable
Save changes to the JSS