class InsightsCloud::Async::InsightsResolutionsSync

Constants

RULE_ID_REGEX

Public Instance Methods

logger() click to toggle source
# File lib/insights_cloud/async/insights_resolutions_sync.rb, line 18
def logger
  action_logger
end
run() click to toggle source
# File lib/insights_cloud/async/insights_resolutions_sync.rb, line 10
def run
  InsightsResolution.transaction do
    InsightsResolution.delete_all
    api_response = query_insights_resolutions(relevant_rules)
    write_resolutions(api_response)
  end
end

Private Instance Methods

query_insights_resolutions(rule_ids) click to toggle source
# File lib/insights_cloud/async/insights_resolutions_sync.rb, line 24
def query_insights_resolutions(rule_ids)
  resolutions_response = RestClient::Request.execute(
    method: :post,
    url: InsightsCloud.resolutions_url,
    verify_ssl: ForemanRhCloud.verify_ssl_method,
    proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
    headers: {
      content_type: :json,
      Authorization: "Bearer #{rh_credentials}",
    },
    payload: {
      issues: rule_ids,
    }.to_json
  )

  JSON.parse(resolutions_response)
end
relevant_rules() click to toggle source
# File lib/insights_cloud/async/insights_resolutions_sync.rb, line 42
def relevant_rules
  InsightsRule.all.pluck(:rule_id).map { |id| InsightsCloud.remediation_rule_id(id) }
end
to_resolution_hash(rule_id, resolution_hash) click to toggle source
# File lib/insights_cloud/async/insights_resolutions_sync.rb, line 46
def to_resolution_hash(rule_id, resolution_hash)
  {
    rule_id: rule_id,
    description: resolution_hash['description'],
    resolution_type: resolution_hash['id'],
    needs_reboot: resolution_hash['needs_reboot'],
    resolution_risk: resolution_hash['resolution_risk'],
  }
end
to_rule_id(resolution_rule_id) click to toggle source
# File lib/insights_cloud/async/insights_resolutions_sync.rb, line 64
def to_rule_id(resolution_rule_id)
  RULE_ID_REGEX.match(resolution_rule_id).named_captures.fetch('id', resolution_rule_id)
end
write_resolutions(response) click to toggle source
# File lib/insights_cloud/async/insights_resolutions_sync.rb, line 56
def write_resolutions(response)
  all_resolutions = response.map do |rule_id, rule_details|
    rule_details['resolutions'].map { |resolution| to_resolution_hash(to_rule_id(rule_id), resolution) }
  end.flatten

  InsightsResolution.create(all_resolutions)
end