5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/models/concerns/foreman_openscap/host_extensions.rb', line 5
def self.prepended(base)
base.has_one :asset, :as => :assetable, :class_name => "::ForemanOpenscap::Asset", :dependent => :destroy
base.has_many :asset_policies, :through => :asset, :class_name => "::ForemanOpenscap::AssetPolicy"
base.has_many :policies, :through => :asset_policies, :class_name => "::ForemanOpenscap::Policy"
base.has_many :arf_reports, :class_name => '::ForemanOpenscap::ArfReport', :foreign_key => :host_id
base.has_one :compliance_status_object, :class_name => '::ForemanOpenscap::ComplianceStatus', :foreign_key => 'host_id'
base.validate :openscap_proxy_in_taxonomy, :if => Proc.new { |host| host.openscap_proxy_id.present? }
base.scoped_search :relation => :policies, :on => :name, :complete_value => true, :rename => :compliance_policy,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_policy_name
base.scoped_search :relation => :policies, :on => :id, :complete_value => false, :rename => :compliance_policy_id,
:only_explicit => true, :operators => ['= ', '!= '], :ext_method => :search_by_policy_id
base.scoped_search :relation => :policies, :on => :name, :complete_value => true, :rename => :compliance_report_missing_for,
:only_explicit => true, :operators => ['= ', '!= '], :ext_method => :search_by_missing_arf
base.scoped_search :relation => :compliance_status_object, :on => :status, :rename => :compliance_status,
:complete_value => { :compliant => ::ForemanOpenscap::ComplianceStatus::COMPLIANT,
:incompliant => ::ForemanOpenscap::ComplianceStatus::INCOMPLIANT,
:inconclusive => ::ForemanOpenscap::ComplianceStatus::INCONCLUSIVE }
base.scoped_search :relation => :policies, :on => :name, :complete_value => { :true => true, :false => false },
:only_explicit => true, :rename => :is_compliance_host, :operators => ['= '], :ext_method => :search_for_any_with_policy,
:validator => ->(value) { ['true', 'false'].include? value }
base.scoped_search :on => :id, :rename => :passes_xccdf_rule,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_rule_passed
base.scoped_search :on => :id, :rename => :fails_xccdf_rule,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_rule_failed
base.scoped_search :on => :id, :rename => :others_xccdf_rule,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_rule_othered
base.scoped_search :on => :id, :rename => :comply_with,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_comply_with
base.scoped_search :on => :id, :rename => :not_comply_with,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_not_comply_with
base.scoped_search :on => :id, :rename => :inconclusive_with,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_inconclusive_with
base.scoped_search :on => :id, :rename => :removed_from_policy,
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_removed_from_policy
base.scope :comply_with, lambda { |policy|
joins(:arf_reports).merge(ArfReport.latest_of_policy(policy)).merge(ArfReport.passed)
}
base.scope :not_comply_with, lambda { |policy|
joins(:arf_reports).merge(ArfReport.latest_of_policy(policy)).merge(ArfReport.failed)
}
base.scope :inconclusive_with, lambda { |policy|
joins(:arf_reports).merge(ArfReport.latest_of_policy(policy)).merge(ArfReport.othered)
}
base.scope :policy_reports_missing, lambda { |policy|
search_for("compliance_report_missing_for = \"#{policy.name}\"")
}
base.scope :assigned_to_policy, lambda { |policy|
search_for("compliance_policy = \"#{policy.name}\"")
}
base.scope :removed_from_policy, lambda { |policy|
joins(:arf_reports).merge(ArfReport.latest_of_policy(policy)).where.not(:id => assigned_to_policy(policy).pluck(:id))
}
base.send :extend, ClassMethods
base.apipie :class do
property :policies_enc, String, desc: 'Returns JSON string containing policies for the host'
property :policies_enc_raw, array_of: Hash, desc: 'Returns a list with key:value objects containing policies for the host'
end
base.smart_proxy_reference :self => [:openscap_proxy_id]
end
|