Module: Xolo::Server::Helpers::Subscriptions
- Defined in:
- lib/xolo/server/helpers/subscriptions.rb
Overview
This is mixed in to Xolo::Server::App (as a helper, available in route processing)
This holds methods and constants for working with subscribed titles - those that are managed by other Non-Xolo Patch Sources.
Class Method Summary collapse
-
.included(includer) ⇒ Object
when this module is included.
Instance Method Summary collapse
-
#available_titles_for_subscription ⇒ Array<Hash>
All available (i.e. not yet subscribed) titles on all patch sources defined in Jamf.
-
#process_patch_title_updated_webhook(req_body) ⇒ Object
Process an incoming webhook event, possibly for a subscribed title Do this in a thread so that we can return a 200 response to the webhook immediately, and do the processing asynchronously (which may involve time-consuming tasks like autopkg runs).
Class Method Details
.included(includer) ⇒ Object
when this module is included
33 34 35 |
# File 'lib/xolo/server/helpers/subscriptions.rb', line 33 def self.included(includer) Xolo.verbose_include includer, self end |
Instance Method Details
#available_titles_for_subscription ⇒ Array<Hash>
All available (i.e. not yet subscribed) titles on all patch sources defined in Jamf.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/xolo/server/helpers/subscriptions.rb', line 44 def available_titles_for_subscription available = [] Jamf::PatchSource.all(cnx: jamf_cnx).each do |ps| log_debug "Checking Patch Source #{ps} for available titles" ps = Jamf::PatchSource.fetch id: ps[:id], cnx: jamf_cnx ps.available_titles.each do |t| data = t.merge({ source_id: ps.id, source_name: ps.name }) available << data end end available end |
#process_patch_title_updated_webhook(req_body) ⇒ Object
Process an incoming webhook event, possibly for a subscribed title Do this in a thread so that we can return a 200 response to the webhook immediately, and do the processing asynchronously (which may involve time-consuming tasks like autopkg runs)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/xolo/server/helpers/subscriptions.rb', line 63 def process_patch_title_updated_webhook(req_body) @process_webhook_thread = Thread.new do log_debug "Using a thread for processing PatchSoftwareTitleUpdated webhook event with body: #{req_body}" event_data = parse_json(req_body)[:event] title_name = event_data[:name] title_id = event_data[:jssID] new_version = event_data[:latestVersion] log_debug "Received PatchSoftwareTitleUpdate webhook event for patch title '#{title_name}' (jamf id #{title_id}), new version '#{new_version}'" subscribed_title = subscribed_title_objects.select { |tobj| tobj.jamf_patch_title_id.to_i == title_id.to_i }.first if subscribed_title msg = +"New version '#{new_version}' is available for subscribed title '#{subscribed_title.title}' (#{subscribed_title.display_name})." msg << " Running autopkg recipe '#{subscribed_title.autopkg_recipe}'." if subscribed_title.autopkg_enabled? log_info msg Xolo::Server::Version.add_version_via_subscription( title_object: subscribed_title, new_version: new_version ) else log_debug "Title '#{title_name}' ID #{title_id} is not a subscribed title in Xolo. Ignoring webhook." end rescue => e msg = "Error processing PatchSoftwareTitleUpdated webhook event: #{e.class}: #{e}" log_error msg raise e, msg end # thread end |