Module: ForemanOpenscap::ComplianceStatusScopedSearch::ClassMethods

Defined in:
app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb

Instance Method Summary collapse

Instance Method Details

#policy_search(search_alias) ⇒ Object



6
7
8
9
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 6

def policy_search(search_alias)
  scoped_search :relation => :policy, :on => :name, :complete_value => true, :rename => search_alias,
        :only_explicit => true
end

#search_by_compliance_status(key, operator, value) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 64

def search_by_compliance_status(key, operator, value)
  scope = case value
          when 'compliant'
            ArfReport.passed
          when 'incompliant'
            ArfReport.failed
          when 'inconclusive'
            ArfReport.othered
          end
  query_conditions_from_scope scope
end

#search_by_comply_with(_key, _operator, policy_name) ⇒ Object



11
12
13
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 11

def search_by_comply_with(_key, _operator, policy_name)
  search_by_policy_results policy_name, &:passed
end

#search_by_host_collection_name(key, operator, value) ⇒ Object



76
77
78
79
80
81
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 76

def search_by_host_collection_name(key, operator, value)
  scope = apply_condition(Host.joins(:host_collections),
                          operator == '<>',
                          :katello_host_collections => { :name => value })
  query_conditions_from_scope ForemanOpenscap::ArfReport.where(:host_id => scope)
end

#search_by_inconclusive_with(_key, _operator, policy_name) ⇒ Object



19
20
21
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 19

def search_by_inconclusive_with(_key, _operator, policy_name)
  search_by_policy_results policy_name, &:othered
end

#search_by_last_for(key, operator, by) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 41

def search_by_last_for(key, operator, by)
  by.gsub!(/[^[:alnum:]]/, '')
  case by.downcase
  when 'host'
    { :conditions => "reports.id IN (
          SELECT MAX(id) FROM reports sub
          WHERE sub.type = 'ForemanOpenscap::ArfReport'
            AND sub.host_id = reports.host_id )" }
  when 'policy'
    { :conditions => 'reports.id IN (
        SELECT latest.id
        FROM foreman_openscap_policies
          INNER JOIN (SELECT policy_id, MAX(reports.id) AS id
                      FROM reports INNER JOIN foreman_openscap_policy_arf_reports
                        ON reports.id = foreman_openscap_policy_arf_reports.arf_report_id
                      GROUP BY policy_id
                     ) latest
          ON foreman_openscap_policies.id = latest.policy_id)' }
  else
    raise "Cannot search last by #{by}"
  end
end

#search_by_not_comply_with(_key, _operator, policy_name) ⇒ Object



15
16
17
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 15

def search_by_not_comply_with(_key, _operator, policy_name)
  search_by_policy_results policy_name, &:failed
end

#search_by_policy_results(policy_name, &selection) ⇒ Object



23
24
25
26
27
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 23

def search_by_policy_results(policy_name, &selection)
  scope = ArfReport.of_policy(Policy.find_by(:name => policy_name).id)
                   .instance_eval(&selection)
  query_conditions_from_scope scope
end

#search_by_rule_failed(key, operator, rule_name) ⇒ Object



29
30
31
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 29

def search_by_rule_failed(key, operator, rule_name)
  search_by_rule rule_name, "fail"
end

#search_by_rule_othered(key, operator, rule_name) ⇒ Object



37
38
39
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 37

def search_by_rule_othered(key, operator, rule_name)
  search_by_rule rule_name, LogExtensions.othered_result_constants
end

#search_by_rule_passed(key, operator, rule_name) ⇒ Object



33
34
35
# File 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb', line 33

def search_by_rule_passed(key, operator, rule_name)
  search_by_rule rule_name, "pass"
end